From 705250ad471951bac7e69d7170f3991536ee4aa1 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 17 Nov 2024 21:46:10 -0500 Subject: [PATCH] wip --- .mockery.yaml | 2 +- pkg/alerting/alert/alert.go | 5 +- pkg/calls/call.go | 16 + pkg/database/calls.sql.go | 19 +- pkg/database/database.go | 39 +- pkg/database/extend.go | 8 +- pkg/database/mocks/DB.go | 1631 --------------- pkg/database/mocks/Store.go | 1786 +++++++++++++++++ pkg/database/models.go | 26 +- pkg/database/querier.go | 8 +- pkg/database/talkgroups.go | 28 +- pkg/database/talkgroups.sql.go | 122 +- pkg/nexus/commands.go | 2 +- pkg/server/server.go | 6 +- pkg/sinks/database.go | 38 +- pkg/talkgroups/importer/import.go | 5 +- sql/postgres/migrations/001_initial.up.sql | 20 +- .../migrations/002_tglearned.down.sql | 34 + sql/postgres/migrations/002_tglearned.up.sql | 21 + sql/postgres/migrations/initial.sql | 120 ++ sql/postgres/queries/calls.sql | 3 +- sql/postgres/queries/talkgroups.sql | 40 +- sql/sqlc.yaml | 1 + 23 files changed, 2218 insertions(+), 1762 deletions(-) delete mode 100644 pkg/database/mocks/DB.go create mode 100644 pkg/database/mocks/Store.go create mode 100644 sql/postgres/migrations/002_tglearned.down.sql create mode 100644 sql/postgres/migrations/002_tglearned.up.sql create mode 100644 sql/postgres/migrations/initial.sql diff --git a/.mockery.yaml b/.mockery.yaml index ab4e084..fa78e2c 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -7,4 +7,4 @@ packages: dynatron.me/x/stillbox/pkg/database: config: interfaces: - DB: + Store: diff --git a/pkg/alerting/alert/alert.go b/pkg/alerting/alert/alert.go index de64278..3889a61 100644 --- a/pkg/alerting/alert/alert.go +++ b/pkg/alerting/alert/alert.go @@ -10,12 +10,11 @@ import ( "dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/talkgroups" - "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" ) type Alert struct { - ID uuid.UUID + ID int Timestamp time.Time TGName string Score trending.Score[talkgroups.ID] @@ -34,7 +33,6 @@ func (a *Alert) ToAddAlertParams() database.AddAlertParams { } return database.AddAlertParams{ - ID: a.ID, Time: pgtype.Timestamptz{Time: a.Timestamp, Valid: true}, SystemID: int(a.Score.ID.System), TGID: int(a.Score.ID.Talkgroup), @@ -48,7 +46,6 @@ func (a *Alert) ToAddAlertParams() database.AddAlertParams { // Make creates an alert for later rendering or storage. func Make(ctx context.Context, store talkgroups.Store, score trending.Score[talkgroups.ID], origScore float64) (Alert, error) { d := Alert{ - ID: uuid.New(), Score: score, Timestamp: time.Now(), Weight: 1.0, diff --git a/pkg/calls/call.go b/pkg/calls/call.go index 6359940..d6f1943 100644 --- a/pkg/calls/call.go +++ b/pkg/calls/call.go @@ -1,11 +1,13 @@ package calls import ( + "context" "fmt" "time" "dynatron.me/x/stillbox/internal/audio" "dynatron.me/x/stillbox/pkg/auth" + "dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/pb" "dynatron.me/x/stillbox/pkg/talkgroups" @@ -111,6 +113,20 @@ func (c *Call) ToPB() *pb.Call { } } +func (c *Call) LearnTG(ctx context.Context, db database.Store) (learnedId int, err error) { + err = db.AddTalkgroupWithLearnedFlag(ctx, int32(c.System), int32(c.Talkgroup)) + if err != nil { + return 0, err + } + + return db.AddLearnedTalkgroup(ctx, database.AddLearnedTalkgroupParams{ + SystemID: c.System, + TGID: c.Talkgroup, + Name: c.TalkgroupLabel, + AlphaTag: c.TGAlphaTag, + }) +} + func (c *Call) computeLength() (err error) { var td time.Duration diff --git a/pkg/database/calls.sql.go b/pkg/database/calls.sql.go index ab98ae4..2c82ea8 100644 --- a/pkg/database/calls.sql.go +++ b/pkg/database/calls.sql.go @@ -13,7 +13,7 @@ import ( ) const addAlert = `-- name: AddAlert :exec -INSERT INTO alerts (id, time, tgid, system_id, weight, score, orig_score, notified, metadata) +INSERT INTO alerts (time, tgid, system_id, weight, score, orig_score, notified, metadata) VALUES ( $1, @@ -23,13 +23,11 @@ VALUES $5, $6, $7, - $8, - $9 + $8 ) ` type AddAlertParams struct { - ID uuid.UUID `json:"id"` Time pgtype.Timestamptz `json:"time"` TGID int `json:"tgid"` SystemID int `json:"system_id"` @@ -42,7 +40,6 @@ type AddAlertParams struct { func (q *Queries) AddAlert(ctx context.Context, arg AddAlertParams) error { _, err := q.db.Exec(ctx, addAlert, - arg.ID, arg.Time, arg.TGID, arg.SystemID, @@ -109,9 +106,9 @@ type AddCallParams struct { Frequency int `json:"frequency"` Frequencies []int `json:"frequencies"` Patches []int `json:"patches"` - TgLabel *string `json:"tg_label"` - TgAlphaTag *string `json:"tg_alpha_tag"` - TgGroup *string `json:"tg_group"` + TGLabel *string `json:"tg_label"` + TGAlphaTag *string `json:"tg_alpha_tag"` + TGGroup *string `json:"tg_group"` Source int `json:"source"` } @@ -130,9 +127,9 @@ func (q *Queries) AddCall(ctx context.Context, arg AddCallParams) error { arg.Frequency, arg.Frequencies, arg.Patches, - arg.TgLabel, - arg.TgAlphaTag, - arg.TgGroup, + arg.TGLabel, + arg.TGAlphaTag, + arg.TGGroup, arg.Source, ) return err diff --git a/pkg/database/database.go b/pkg/database/database.go index 9aab59e..35fb95d 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -3,6 +3,7 @@ package database import ( "context" "errors" + "fmt" "strings" "dynatron.me/x/stillbox/pkg/config" @@ -19,11 +20,12 @@ import ( // DB is a database handle. //go:generate mockery -type DB interface { +type Store interface { Querier talkgroupQuerier DB() *Database + InTx(context.Context, func(Store) error, pgx.TxOptions) error } type Database struct { @@ -35,14 +37,41 @@ func (db *Database) DB() *Database { return db } +func (db *Database) InTx(ctx context.Context, f func(Store) error, opts pgx.TxOptions) error { + tx, err := db.DB().Pool.BeginTx(ctx, opts) + if err != nil { + return fmt.Errorf("Tx begin: %w", err) + } + + defer tx.Rollback(ctx) + + dbtx := &Database{Pool: db.Pool, Queries: db.Queries.WithTx(tx)} + + err = f(dbtx) + if err != nil { + return fmt.Errorf("Tx: %w", err) + } + + err = tx.Commit(ctx) + if err != nil { + return fmt.Errorf("Tx commit: %w", err) + } + + return nil +} + type dbLogger struct{} func (m dbLogger) Log(ctx context.Context, level tracelog.LogLevel, msg string, data map[string]any) { log.Debug().Fields(data).Msg(msg) } +func Close(c Store) { + c.(*Database).Pool.Close() +} + // NewClient creates a new DB using the provided config. -func NewClient(ctx context.Context, conf config.DB) (DB, error) { +func NewClient(ctx context.Context, conf config.DB) (Store, error) { dir, err := iofs.New(sqlembed.Migrations, "postgres/migrations") if err != nil { return nil, err @@ -90,8 +119,8 @@ type dBCtxKey string const DBCtxKey dBCtxKey = "dbctx" // FromCtx returns the database handle from the provided Context. -func FromCtx(ctx context.Context) DB { - c, ok := ctx.Value(DBCtxKey).(DB) +func FromCtx(ctx context.Context) Store { + c, ok := ctx.Value(DBCtxKey).(Store) if !ok { panic("no DB in context") } @@ -100,7 +129,7 @@ func FromCtx(ctx context.Context) DB { } // CtxWithDB returns a Context with the provided database handle. -func CtxWithDB(ctx context.Context, conn DB) context.Context { +func CtxWithDB(ctx context.Context, conn Store) context.Context { return context.WithValue(ctx, DBCtxKey, conn) } diff --git a/pkg/database/extend.go b/pkg/database/extend.go index d885991..c9ae0c2 100644 --- a/pkg/database/extend.go +++ b/pkg/database/extend.go @@ -2,16 +2,16 @@ package database func (d GetTalkgroupsRow) GetTalkgroup() Talkgroup { return d.Talkgroup } func (d GetTalkgroupsRow) GetSystem() System { return d.System } -func (d GetTalkgroupsRow) GetLearned() bool { return d.Learned } +func (d GetTalkgroupsRow) GetLearned() bool { return d.Talkgroup.Learned } func (g GetTalkgroupWithLearnedRow) GetTalkgroup() Talkgroup { return g.Talkgroup } func (g GetTalkgroupWithLearnedRow) GetSystem() System { return g.System } -func (g GetTalkgroupWithLearnedRow) GetLearned() bool { return g.Learned } +func (g GetTalkgroupWithLearnedRow) GetLearned() bool { return g.Talkgroup.Learned } func (g GetTalkgroupsWithLearnedRow) GetTalkgroup() Talkgroup { return g.Talkgroup } func (g GetTalkgroupsWithLearnedRow) GetSystem() System { return g.System } -func (g GetTalkgroupsWithLearnedRow) GetLearned() bool { return g.Learned } +func (g GetTalkgroupsWithLearnedRow) GetLearned() bool { return g.Talkgroup.Learned } func (g GetTalkgroupsWithLearnedBySystemRow) GetTalkgroup() Talkgroup { return g.Talkgroup } func (g GetTalkgroupsWithLearnedBySystemRow) GetSystem() System { return g.System } -func (g GetTalkgroupsWithLearnedBySystemRow) GetLearned() bool { return g.Learned } +func (g GetTalkgroupsWithLearnedBySystemRow) GetLearned() bool { return g.Talkgroup.Learned } func (g Talkgroup) GetTalkgroup() Talkgroup { return g } func (g Talkgroup) GetSystem() System { return System{ID: int(g.SystemID)} } func (g Talkgroup) GetLearned() bool { return false } diff --git a/pkg/database/mocks/DB.go b/pkg/database/mocks/DB.go deleted file mode 100644 index f7b451d..0000000 --- a/pkg/database/mocks/DB.go +++ /dev/null @@ -1,1631 +0,0 @@ -// Code generated by mockery v2.47.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - database "dynatron.me/x/stillbox/pkg/database" - mock "github.com/stretchr/testify/mock" - - pgtype "github.com/jackc/pgx/v5/pgtype" - - uuid "github.com/google/uuid" -) - -// DB is an autogenerated mock type for the DB type -type DB struct { - mock.Mock -} - -type DB_Expecter struct { - mock *mock.Mock -} - -func (_m *DB) EXPECT() *DB_Expecter { - return &DB_Expecter{mock: &_m.Mock} -} - -// AddAlert provides a mock function with given fields: ctx, arg -func (_m *DB) AddAlert(ctx context.Context, arg database.AddAlertParams) error { - ret := _m.Called(ctx, arg) - - if len(ret) == 0 { - panic("no return value specified for AddAlert") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, database.AddAlertParams) error); ok { - r0 = rf(ctx, arg) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_AddAlert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddAlert' -type DB_AddAlert_Call struct { - *mock.Call -} - -// AddAlert is a helper method to define mock.On call -// - ctx context.Context -// - arg database.AddAlertParams -func (_e *DB_Expecter) AddAlert(ctx interface{}, arg interface{}) *DB_AddAlert_Call { - return &DB_AddAlert_Call{Call: _e.mock.On("AddAlert", ctx, arg)} -} - -func (_c *DB_AddAlert_Call) Run(run func(ctx context.Context, arg database.AddAlertParams)) *DB_AddAlert_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.AddAlertParams)) - }) - return _c -} - -func (_c *DB_AddAlert_Call) Return(_a0 error) *DB_AddAlert_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_AddAlert_Call) RunAndReturn(run func(context.Context, database.AddAlertParams) error) *DB_AddAlert_Call { - _c.Call.Return(run) - return _c -} - -// AddCall provides a mock function with given fields: ctx, arg -func (_m *DB) AddCall(ctx context.Context, arg database.AddCallParams) error { - ret := _m.Called(ctx, arg) - - if len(ret) == 0 { - panic("no return value specified for AddCall") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, database.AddCallParams) error); ok { - r0 = rf(ctx, arg) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_AddCall_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddCall' -type DB_AddCall_Call struct { - *mock.Call -} - -// AddCall is a helper method to define mock.On call -// - ctx context.Context -// - arg database.AddCallParams -func (_e *DB_Expecter) AddCall(ctx interface{}, arg interface{}) *DB_AddCall_Call { - return &DB_AddCall_Call{Call: _e.mock.On("AddCall", ctx, arg)} -} - -func (_c *DB_AddCall_Call) Run(run func(ctx context.Context, arg database.AddCallParams)) *DB_AddCall_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.AddCallParams)) - }) - return _c -} - -func (_c *DB_AddCall_Call) Return(_a0 error) *DB_AddCall_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_AddCall_Call) RunAndReturn(run func(context.Context, database.AddCallParams) error) *DB_AddCall_Call { - _c.Call.Return(run) - return _c -} - -// BulkSetTalkgroupTags provides a mock function with given fields: ctx, tgs, tags -func (_m *DB) BulkSetTalkgroupTags(ctx context.Context, tgs database.TGTuples, tags []string) error { - ret := _m.Called(ctx, tgs, tags) - - if len(ret) == 0 { - panic("no return value specified for BulkSetTalkgroupTags") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples, []string) error); ok { - r0 = rf(ctx, tgs, tags) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_BulkSetTalkgroupTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BulkSetTalkgroupTags' -type DB_BulkSetTalkgroupTags_Call struct { - *mock.Call -} - -// BulkSetTalkgroupTags is a helper method to define mock.On call -// - ctx context.Context -// - tgs database.TGTuples -// - tags []string -func (_e *DB_Expecter) BulkSetTalkgroupTags(ctx interface{}, tgs interface{}, tags interface{}) *DB_BulkSetTalkgroupTags_Call { - return &DB_BulkSetTalkgroupTags_Call{Call: _e.mock.On("BulkSetTalkgroupTags", ctx, tgs, tags)} -} - -func (_c *DB_BulkSetTalkgroupTags_Call) Run(run func(ctx context.Context, tgs database.TGTuples, tags []string)) *DB_BulkSetTalkgroupTags_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.TGTuples), args[2].([]string)) - }) - return _c -} - -func (_c *DB_BulkSetTalkgroupTags_Call) Return(_a0 error) *DB_BulkSetTalkgroupTags_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_BulkSetTalkgroupTags_Call) RunAndReturn(run func(context.Context, database.TGTuples, []string) error) *DB_BulkSetTalkgroupTags_Call { - _c.Call.Return(run) - return _c -} - -// CreateAPIKey provides a mock function with given fields: ctx, owner, expires, disabled -func (_m *DB) CreateAPIKey(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool) (database.ApiKey, error) { - ret := _m.Called(ctx, owner, expires, disabled) - - if len(ret) == 0 { - panic("no return value specified for CreateAPIKey") - } - - var r0 database.ApiKey - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int, pgtype.Timestamp, *bool) (database.ApiKey, error)); ok { - return rf(ctx, owner, expires, disabled) - } - if rf, ok := ret.Get(0).(func(context.Context, int, pgtype.Timestamp, *bool) database.ApiKey); ok { - r0 = rf(ctx, owner, expires, disabled) - } else { - r0 = ret.Get(0).(database.ApiKey) - } - - if rf, ok := ret.Get(1).(func(context.Context, int, pgtype.Timestamp, *bool) error); ok { - r1 = rf(ctx, owner, expires, disabled) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_CreateAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAPIKey' -type DB_CreateAPIKey_Call struct { - *mock.Call -} - -// CreateAPIKey is a helper method to define mock.On call -// - ctx context.Context -// - owner int -// - expires pgtype.Timestamp -// - disabled *bool -func (_e *DB_Expecter) CreateAPIKey(ctx interface{}, owner interface{}, expires interface{}, disabled interface{}) *DB_CreateAPIKey_Call { - return &DB_CreateAPIKey_Call{Call: _e.mock.On("CreateAPIKey", ctx, owner, expires, disabled)} -} - -func (_c *DB_CreateAPIKey_Call) Run(run func(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool)) *DB_CreateAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int), args[2].(pgtype.Timestamp), args[3].(*bool)) - }) - return _c -} - -func (_c *DB_CreateAPIKey_Call) Return(_a0 database.ApiKey, _a1 error) *DB_CreateAPIKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_CreateAPIKey_Call) RunAndReturn(run func(context.Context, int, pgtype.Timestamp, *bool) (database.ApiKey, error)) *DB_CreateAPIKey_Call { - _c.Call.Return(run) - return _c -} - -// CreateUser provides a mock function with given fields: ctx, arg -func (_m *DB) CreateUser(ctx context.Context, arg database.CreateUserParams) (database.User, error) { - ret := _m.Called(ctx, arg) - - if len(ret) == 0 { - panic("no return value specified for CreateUser") - } - - var r0 database.User - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, database.CreateUserParams) (database.User, error)); ok { - return rf(ctx, arg) - } - if rf, ok := ret.Get(0).(func(context.Context, database.CreateUserParams) database.User); ok { - r0 = rf(ctx, arg) - } else { - r0 = ret.Get(0).(database.User) - } - - if rf, ok := ret.Get(1).(func(context.Context, database.CreateUserParams) error); ok { - r1 = rf(ctx, arg) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_CreateUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateUser' -type DB_CreateUser_Call struct { - *mock.Call -} - -// CreateUser is a helper method to define mock.On call -// - ctx context.Context -// - arg database.CreateUserParams -func (_e *DB_Expecter) CreateUser(ctx interface{}, arg interface{}) *DB_CreateUser_Call { - return &DB_CreateUser_Call{Call: _e.mock.On("CreateUser", ctx, arg)} -} - -func (_c *DB_CreateUser_Call) Run(run func(ctx context.Context, arg database.CreateUserParams)) *DB_CreateUser_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.CreateUserParams)) - }) - return _c -} - -func (_c *DB_CreateUser_Call) Return(_a0 database.User, _a1 error) *DB_CreateUser_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_CreateUser_Call) RunAndReturn(run func(context.Context, database.CreateUserParams) (database.User, error)) *DB_CreateUser_Call { - _c.Call.Return(run) - return _c -} - -// DB provides a mock function with given fields: -func (_m *DB) DB() *database.Database { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for DB") - } - - var r0 *database.Database - if rf, ok := ret.Get(0).(func() *database.Database); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*database.Database) - } - } - - return r0 -} - -// DB_DB_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DB' -type DB_DB_Call struct { - *mock.Call -} - -// DB is a helper method to define mock.On call -func (_e *DB_Expecter) DB() *DB_DB_Call { - return &DB_DB_Call{Call: _e.mock.On("DB")} -} - -func (_c *DB_DB_Call) Run(run func()) *DB_DB_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *DB_DB_Call) Return(_a0 *database.Database) *DB_DB_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_DB_Call) RunAndReturn(run func() *database.Database) *DB_DB_Call { - _c.Call.Return(run) - return _c -} - -// DeleteAPIKey provides a mock function with given fields: ctx, apiKey -func (_m *DB) DeleteAPIKey(ctx context.Context, apiKey string) error { - ret := _m.Called(ctx, apiKey) - - if len(ret) == 0 { - panic("no return value specified for DeleteAPIKey") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, apiKey) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_DeleteAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAPIKey' -type DB_DeleteAPIKey_Call struct { - *mock.Call -} - -// DeleteAPIKey is a helper method to define mock.On call -// - ctx context.Context -// - apiKey string -func (_e *DB_Expecter) DeleteAPIKey(ctx interface{}, apiKey interface{}) *DB_DeleteAPIKey_Call { - return &DB_DeleteAPIKey_Call{Call: _e.mock.On("DeleteAPIKey", ctx, apiKey)} -} - -func (_c *DB_DeleteAPIKey_Call) Run(run func(ctx context.Context, apiKey string)) *DB_DeleteAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string)) - }) - return _c -} - -func (_c *DB_DeleteAPIKey_Call) Return(_a0 error) *DB_DeleteAPIKey_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_DeleteAPIKey_Call) RunAndReturn(run func(context.Context, string) error) *DB_DeleteAPIKey_Call { - _c.Call.Return(run) - return _c -} - -// DeleteUser provides a mock function with given fields: ctx, username -func (_m *DB) DeleteUser(ctx context.Context, username string) error { - ret := _m.Called(ctx, username) - - if len(ret) == 0 { - panic("no return value specified for DeleteUser") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, username) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_DeleteUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteUser' -type DB_DeleteUser_Call struct { - *mock.Call -} - -// DeleteUser is a helper method to define mock.On call -// - ctx context.Context -// - username string -func (_e *DB_Expecter) DeleteUser(ctx interface{}, username interface{}) *DB_DeleteUser_Call { - return &DB_DeleteUser_Call{Call: _e.mock.On("DeleteUser", ctx, username)} -} - -func (_c *DB_DeleteUser_Call) Run(run func(ctx context.Context, username string)) *DB_DeleteUser_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string)) - }) - return _c -} - -func (_c *DB_DeleteUser_Call) Return(_a0 error) *DB_DeleteUser_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_DeleteUser_Call) RunAndReturn(run func(context.Context, string) error) *DB_DeleteUser_Call { - _c.Call.Return(run) - return _c -} - -// GetAPIKey provides a mock function with given fields: ctx, apiKey -func (_m *DB) GetAPIKey(ctx context.Context, apiKey string) (database.ApiKey, error) { - ret := _m.Called(ctx, apiKey) - - if len(ret) == 0 { - panic("no return value specified for GetAPIKey") - } - - var r0 database.ApiKey - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (database.ApiKey, error)); ok { - return rf(ctx, apiKey) - } - if rf, ok := ret.Get(0).(func(context.Context, string) database.ApiKey); ok { - r0 = rf(ctx, apiKey) - } else { - r0 = ret.Get(0).(database.ApiKey) - } - - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, apiKey) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAPIKey' -type DB_GetAPIKey_Call struct { - *mock.Call -} - -// GetAPIKey is a helper method to define mock.On call -// - ctx context.Context -// - apiKey string -func (_e *DB_Expecter) GetAPIKey(ctx interface{}, apiKey interface{}) *DB_GetAPIKey_Call { - return &DB_GetAPIKey_Call{Call: _e.mock.On("GetAPIKey", ctx, apiKey)} -} - -func (_c *DB_GetAPIKey_Call) Run(run func(ctx context.Context, apiKey string)) *DB_GetAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string)) - }) - return _c -} - -func (_c *DB_GetAPIKey_Call) Return(_a0 database.ApiKey, _a1 error) *DB_GetAPIKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetAPIKey_Call) RunAndReturn(run func(context.Context, string) (database.ApiKey, error)) *DB_GetAPIKey_Call { - _c.Call.Return(run) - return _c -} - -// GetDatabaseSize provides a mock function with given fields: ctx -func (_m *DB) GetDatabaseSize(ctx context.Context) (string, error) { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for GetDatabaseSize") - } - - var r0 string - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (string, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) string); ok { - r0 = rf(ctx) - } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetDatabaseSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDatabaseSize' -type DB_GetDatabaseSize_Call struct { - *mock.Call -} - -// GetDatabaseSize is a helper method to define mock.On call -// - ctx context.Context -func (_e *DB_Expecter) GetDatabaseSize(ctx interface{}) *DB_GetDatabaseSize_Call { - return &DB_GetDatabaseSize_Call{Call: _e.mock.On("GetDatabaseSize", ctx)} -} - -func (_c *DB_GetDatabaseSize_Call) Run(run func(ctx context.Context)) *DB_GetDatabaseSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *DB_GetDatabaseSize_Call) Return(_a0 string, _a1 error) *DB_GetDatabaseSize_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetDatabaseSize_Call) RunAndReturn(run func(context.Context) (string, error)) *DB_GetDatabaseSize_Call { - _c.Call.Return(run) - return _c -} - -// GetSystemName provides a mock function with given fields: ctx, systemID -func (_m *DB) GetSystemName(ctx context.Context, systemID int) (string, error) { - ret := _m.Called(ctx, systemID) - - if len(ret) == 0 { - panic("no return value specified for GetSystemName") - } - - var r0 string - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int) (string, error)); ok { - return rf(ctx, systemID) - } - if rf, ok := ret.Get(0).(func(context.Context, int) string); ok { - r0 = rf(ctx, systemID) - } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { - r1 = rf(ctx, systemID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetSystemName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSystemName' -type DB_GetSystemName_Call struct { - *mock.Call -} - -// GetSystemName is a helper method to define mock.On call -// - ctx context.Context -// - systemID int -func (_e *DB_Expecter) GetSystemName(ctx interface{}, systemID interface{}) *DB_GetSystemName_Call { - return &DB_GetSystemName_Call{Call: _e.mock.On("GetSystemName", ctx, systemID)} -} - -func (_c *DB_GetSystemName_Call) Run(run func(ctx context.Context, systemID int)) *DB_GetSystemName_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int)) - }) - return _c -} - -func (_c *DB_GetSystemName_Call) Return(_a0 string, _a1 error) *DB_GetSystemName_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetSystemName_Call) RunAndReturn(run func(context.Context, int) (string, error)) *DB_GetSystemName_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroup provides a mock function with given fields: ctx, systemID, tgID -func (_m *DB) GetTalkgroup(ctx context.Context, systemID int32, tgID int32) (database.GetTalkgroupRow, error) { - ret := _m.Called(ctx, systemID, tgID) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroup") - } - - var r0 database.GetTalkgroupRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32, int32) (database.GetTalkgroupRow, error)); ok { - return rf(ctx, systemID, tgID) - } - if rf, ok := ret.Get(0).(func(context.Context, int32, int32) database.GetTalkgroupRow); ok { - r0 = rf(ctx, systemID, tgID) - } else { - r0 = ret.Get(0).(database.GetTalkgroupRow) - } - - if rf, ok := ret.Get(1).(func(context.Context, int32, int32) error); ok { - r1 = rf(ctx, systemID, tgID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroup' -type DB_GetTalkgroup_Call struct { - *mock.Call -} - -// GetTalkgroup is a helper method to define mock.On call -// - ctx context.Context -// - systemID int32 -// - tgID int32 -func (_e *DB_Expecter) GetTalkgroup(ctx interface{}, systemID interface{}, tgID interface{}) *DB_GetTalkgroup_Call { - return &DB_GetTalkgroup_Call{Call: _e.mock.On("GetTalkgroup", ctx, systemID, tgID)} -} - -func (_c *DB_GetTalkgroup_Call) Run(run func(ctx context.Context, systemID int32, tgID int32)) *DB_GetTalkgroup_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32), args[2].(int32)) - }) - return _c -} - -func (_c *DB_GetTalkgroup_Call) Return(_a0 database.GetTalkgroupRow, _a1 error) *DB_GetTalkgroup_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroup_Call) RunAndReturn(run func(context.Context, int32, int32) (database.GetTalkgroupRow, error)) *DB_GetTalkgroup_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupIDsByTags provides a mock function with given fields: ctx, anyTags, allTags, notTags -func (_m *DB) GetTalkgroupIDsByTags(ctx context.Context, anyTags []string, allTags []string, notTags []string) ([]database.GetTalkgroupIDsByTagsRow, error) { - ret := _m.Called(ctx, anyTags, allTags, notTags) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupIDsByTags") - } - - var r0 []database.GetTalkgroupIDsByTagsRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []string, []string, []string) ([]database.GetTalkgroupIDsByTagsRow, error)); ok { - return rf(ctx, anyTags, allTags, notTags) - } - if rf, ok := ret.Get(0).(func(context.Context, []string, []string, []string) []database.GetTalkgroupIDsByTagsRow); ok { - r0 = rf(ctx, anyTags, allTags, notTags) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupIDsByTagsRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []string, []string, []string) error); ok { - r1 = rf(ctx, anyTags, allTags, notTags) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupIDsByTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupIDsByTags' -type DB_GetTalkgroupIDsByTags_Call struct { - *mock.Call -} - -// GetTalkgroupIDsByTags is a helper method to define mock.On call -// - ctx context.Context -// - anyTags []string -// - allTags []string -// - notTags []string -func (_e *DB_Expecter) GetTalkgroupIDsByTags(ctx interface{}, anyTags interface{}, allTags interface{}, notTags interface{}) *DB_GetTalkgroupIDsByTags_Call { - return &DB_GetTalkgroupIDsByTags_Call{Call: _e.mock.On("GetTalkgroupIDsByTags", ctx, anyTags, allTags, notTags)} -} - -func (_c *DB_GetTalkgroupIDsByTags_Call) Run(run func(ctx context.Context, anyTags []string, allTags []string, notTags []string)) *DB_GetTalkgroupIDsByTags_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]string), args[2].([]string), args[3].([]string)) - }) - return _c -} - -func (_c *DB_GetTalkgroupIDsByTags_Call) Return(_a0 []database.GetTalkgroupIDsByTagsRow, _a1 error) *DB_GetTalkgroupIDsByTags_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupIDsByTags_Call) RunAndReturn(run func(context.Context, []string, []string, []string) ([]database.GetTalkgroupIDsByTagsRow, error)) *DB_GetTalkgroupIDsByTags_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupTags provides a mock function with given fields: ctx, systemID, tgID -func (_m *DB) GetTalkgroupTags(ctx context.Context, systemID int32, tgID int32) ([]string, error) { - ret := _m.Called(ctx, systemID, tgID) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupTags") - } - - var r0 []string - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32, int32) ([]string, error)); ok { - return rf(ctx, systemID, tgID) - } - if rf, ok := ret.Get(0).(func(context.Context, int32, int32) []string); ok { - r0 = rf(ctx, systemID, tgID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, int32, int32) error); ok { - r1 = rf(ctx, systemID, tgID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupTags' -type DB_GetTalkgroupTags_Call struct { - *mock.Call -} - -// GetTalkgroupTags is a helper method to define mock.On call -// - ctx context.Context -// - systemID int32 -// - tgID int32 -func (_e *DB_Expecter) GetTalkgroupTags(ctx interface{}, systemID interface{}, tgID interface{}) *DB_GetTalkgroupTags_Call { - return &DB_GetTalkgroupTags_Call{Call: _e.mock.On("GetTalkgroupTags", ctx, systemID, tgID)} -} - -func (_c *DB_GetTalkgroupTags_Call) Run(run func(ctx context.Context, systemID int32, tgID int32)) *DB_GetTalkgroupTags_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32), args[2].(int32)) - }) - return _c -} - -func (_c *DB_GetTalkgroupTags_Call) Return(_a0 []string, _a1 error) *DB_GetTalkgroupTags_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupTags_Call) RunAndReturn(run func(context.Context, int32, int32) ([]string, error)) *DB_GetTalkgroupTags_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupWithLearned provides a mock function with given fields: ctx, systemID, tGID -func (_m *DB) GetTalkgroupWithLearned(ctx context.Context, systemID int32, tGID int32) (database.GetTalkgroupWithLearnedRow, error) { - ret := _m.Called(ctx, systemID, tGID) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupWithLearned") - } - - var r0 database.GetTalkgroupWithLearnedRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32, int32) (database.GetTalkgroupWithLearnedRow, error)); ok { - return rf(ctx, systemID, tGID) - } - if rf, ok := ret.Get(0).(func(context.Context, int32, int32) database.GetTalkgroupWithLearnedRow); ok { - r0 = rf(ctx, systemID, tGID) - } else { - r0 = ret.Get(0).(database.GetTalkgroupWithLearnedRow) - } - - if rf, ok := ret.Get(1).(func(context.Context, int32, int32) error); ok { - r1 = rf(ctx, systemID, tGID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupWithLearned_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupWithLearned' -type DB_GetTalkgroupWithLearned_Call struct { - *mock.Call -} - -// GetTalkgroupWithLearned is a helper method to define mock.On call -// - ctx context.Context -// - systemID int32 -// - tGID int32 -func (_e *DB_Expecter) GetTalkgroupWithLearned(ctx interface{}, systemID interface{}, tGID interface{}) *DB_GetTalkgroupWithLearned_Call { - return &DB_GetTalkgroupWithLearned_Call{Call: _e.mock.On("GetTalkgroupWithLearned", ctx, systemID, tGID)} -} - -func (_c *DB_GetTalkgroupWithLearned_Call) Run(run func(ctx context.Context, systemID int32, tGID int32)) *DB_GetTalkgroupWithLearned_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32), args[2].(int32)) - }) - return _c -} - -func (_c *DB_GetTalkgroupWithLearned_Call) Return(_a0 database.GetTalkgroupWithLearnedRow, _a1 error) *DB_GetTalkgroupWithLearned_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupWithLearned_Call) RunAndReturn(run func(context.Context, int32, int32) (database.GetTalkgroupWithLearnedRow, error)) *DB_GetTalkgroupWithLearned_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupsBySysTGID provides a mock function with given fields: ctx, ids -func (_m *DB) GetTalkgroupsBySysTGID(ctx context.Context, ids database.TGTuples) ([]database.GetTalkgroupsRow, error) { - ret := _m.Called(ctx, ids) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupsBySysTGID") - } - - var r0 []database.GetTalkgroupsRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)); ok { - return rf(ctx, ids) - } - if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) []database.GetTalkgroupsRow); ok { - r0 = rf(ctx, ids) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupsRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, database.TGTuples) error); ok { - r1 = rf(ctx, ids) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupsBySysTGID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsBySysTGID' -type DB_GetTalkgroupsBySysTGID_Call struct { - *mock.Call -} - -// GetTalkgroupsBySysTGID is a helper method to define mock.On call -// - ctx context.Context -// - ids database.TGTuples -func (_e *DB_Expecter) GetTalkgroupsBySysTGID(ctx interface{}, ids interface{}) *DB_GetTalkgroupsBySysTGID_Call { - return &DB_GetTalkgroupsBySysTGID_Call{Call: _e.mock.On("GetTalkgroupsBySysTGID", ctx, ids)} -} - -func (_c *DB_GetTalkgroupsBySysTGID_Call) Run(run func(ctx context.Context, ids database.TGTuples)) *DB_GetTalkgroupsBySysTGID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.TGTuples)) - }) - return _c -} - -func (_c *DB_GetTalkgroupsBySysTGID_Call) Return(_a0 []database.GetTalkgroupsRow, _a1 error) *DB_GetTalkgroupsBySysTGID_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupsBySysTGID_Call) RunAndReturn(run func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)) *DB_GetTalkgroupsBySysTGID_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupsWithAllTags provides a mock function with given fields: ctx, tags -func (_m *DB) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]database.GetTalkgroupsWithAllTagsRow, error) { - ret := _m.Called(ctx, tags) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupsWithAllTags") - } - - var r0 []database.GetTalkgroupsWithAllTagsRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.GetTalkgroupsWithAllTagsRow, error)); ok { - return rf(ctx, tags) - } - if rf, ok := ret.Get(0).(func(context.Context, []string) []database.GetTalkgroupsWithAllTagsRow); ok { - r0 = rf(ctx, tags) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupsWithAllTagsRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { - r1 = rf(ctx, tags) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupsWithAllTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithAllTags' -type DB_GetTalkgroupsWithAllTags_Call struct { - *mock.Call -} - -// GetTalkgroupsWithAllTags is a helper method to define mock.On call -// - ctx context.Context -// - tags []string -func (_e *DB_Expecter) GetTalkgroupsWithAllTags(ctx interface{}, tags interface{}) *DB_GetTalkgroupsWithAllTags_Call { - return &DB_GetTalkgroupsWithAllTags_Call{Call: _e.mock.On("GetTalkgroupsWithAllTags", ctx, tags)} -} - -func (_c *DB_GetTalkgroupsWithAllTags_Call) Run(run func(ctx context.Context, tags []string)) *DB_GetTalkgroupsWithAllTags_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]string)) - }) - return _c -} - -func (_c *DB_GetTalkgroupsWithAllTags_Call) Return(_a0 []database.GetTalkgroupsWithAllTagsRow, _a1 error) *DB_GetTalkgroupsWithAllTags_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupsWithAllTags_Call) RunAndReturn(run func(context.Context, []string) ([]database.GetTalkgroupsWithAllTagsRow, error)) *DB_GetTalkgroupsWithAllTags_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupsWithAnyTags provides a mock function with given fields: ctx, tags -func (_m *DB) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]database.GetTalkgroupsWithAnyTagsRow, error) { - ret := _m.Called(ctx, tags) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupsWithAnyTags") - } - - var r0 []database.GetTalkgroupsWithAnyTagsRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.GetTalkgroupsWithAnyTagsRow, error)); ok { - return rf(ctx, tags) - } - if rf, ok := ret.Get(0).(func(context.Context, []string) []database.GetTalkgroupsWithAnyTagsRow); ok { - r0 = rf(ctx, tags) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupsWithAnyTagsRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { - r1 = rf(ctx, tags) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupsWithAnyTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithAnyTags' -type DB_GetTalkgroupsWithAnyTags_Call struct { - *mock.Call -} - -// GetTalkgroupsWithAnyTags is a helper method to define mock.On call -// - ctx context.Context -// - tags []string -func (_e *DB_Expecter) GetTalkgroupsWithAnyTags(ctx interface{}, tags interface{}) *DB_GetTalkgroupsWithAnyTags_Call { - return &DB_GetTalkgroupsWithAnyTags_Call{Call: _e.mock.On("GetTalkgroupsWithAnyTags", ctx, tags)} -} - -func (_c *DB_GetTalkgroupsWithAnyTags_Call) Run(run func(ctx context.Context, tags []string)) *DB_GetTalkgroupsWithAnyTags_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]string)) - }) - return _c -} - -func (_c *DB_GetTalkgroupsWithAnyTags_Call) Return(_a0 []database.GetTalkgroupsWithAnyTagsRow, _a1 error) *DB_GetTalkgroupsWithAnyTags_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupsWithAnyTags_Call) RunAndReturn(run func(context.Context, []string) ([]database.GetTalkgroupsWithAnyTagsRow, error)) *DB_GetTalkgroupsWithAnyTags_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupsWithLearned provides a mock function with given fields: ctx -func (_m *DB) GetTalkgroupsWithLearned(ctx context.Context) ([]database.GetTalkgroupsWithLearnedRow, error) { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupsWithLearned") - } - - var r0 []database.GetTalkgroupsWithLearnedRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]database.GetTalkgroupsWithLearnedRow, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) []database.GetTalkgroupsWithLearnedRow); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupsWithLearnedRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupsWithLearned_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithLearned' -type DB_GetTalkgroupsWithLearned_Call struct { - *mock.Call -} - -// GetTalkgroupsWithLearned is a helper method to define mock.On call -// - ctx context.Context -func (_e *DB_Expecter) GetTalkgroupsWithLearned(ctx interface{}) *DB_GetTalkgroupsWithLearned_Call { - return &DB_GetTalkgroupsWithLearned_Call{Call: _e.mock.On("GetTalkgroupsWithLearned", ctx)} -} - -func (_c *DB_GetTalkgroupsWithLearned_Call) Run(run func(ctx context.Context)) *DB_GetTalkgroupsWithLearned_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *DB_GetTalkgroupsWithLearned_Call) Return(_a0 []database.GetTalkgroupsWithLearnedRow, _a1 error) *DB_GetTalkgroupsWithLearned_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupsWithLearned_Call) RunAndReturn(run func(context.Context) ([]database.GetTalkgroupsWithLearnedRow, error)) *DB_GetTalkgroupsWithLearned_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupsWithLearnedBySysTGID provides a mock function with given fields: ctx, ids -func (_m *DB) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids database.TGTuples) ([]database.GetTalkgroupsRow, error) { - ret := _m.Called(ctx, ids) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupsWithLearnedBySysTGID") - } - - var r0 []database.GetTalkgroupsRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)); ok { - return rf(ctx, ids) - } - if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) []database.GetTalkgroupsRow); ok { - r0 = rf(ctx, ids) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupsRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, database.TGTuples) error); ok { - r1 = rf(ctx, ids) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupsWithLearnedBySysTGID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithLearnedBySysTGID' -type DB_GetTalkgroupsWithLearnedBySysTGID_Call struct { - *mock.Call -} - -// GetTalkgroupsWithLearnedBySysTGID is a helper method to define mock.On call -// - ctx context.Context -// - ids database.TGTuples -func (_e *DB_Expecter) GetTalkgroupsWithLearnedBySysTGID(ctx interface{}, ids interface{}) *DB_GetTalkgroupsWithLearnedBySysTGID_Call { - return &DB_GetTalkgroupsWithLearnedBySysTGID_Call{Call: _e.mock.On("GetTalkgroupsWithLearnedBySysTGID", ctx, ids)} -} - -func (_c *DB_GetTalkgroupsWithLearnedBySysTGID_Call) Run(run func(ctx context.Context, ids database.TGTuples)) *DB_GetTalkgroupsWithLearnedBySysTGID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.TGTuples)) - }) - return _c -} - -func (_c *DB_GetTalkgroupsWithLearnedBySysTGID_Call) Return(_a0 []database.GetTalkgroupsRow, _a1 error) *DB_GetTalkgroupsWithLearnedBySysTGID_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupsWithLearnedBySysTGID_Call) RunAndReturn(run func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)) *DB_GetTalkgroupsWithLearnedBySysTGID_Call { - _c.Call.Return(run) - return _c -} - -// GetTalkgroupsWithLearnedBySystem provides a mock function with given fields: ctx, system -func (_m *DB) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]database.GetTalkgroupsWithLearnedBySystemRow, error) { - ret := _m.Called(ctx, system) - - if len(ret) == 0 { - panic("no return value specified for GetTalkgroupsWithLearnedBySystem") - } - - var r0 []database.GetTalkgroupsWithLearnedBySystemRow - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32) ([]database.GetTalkgroupsWithLearnedBySystemRow, error)); ok { - return rf(ctx, system) - } - if rf, ok := ret.Get(0).(func(context.Context, int32) []database.GetTalkgroupsWithLearnedBySystemRow); ok { - r0 = rf(ctx, system) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.GetTalkgroupsWithLearnedBySystemRow) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { - r1 = rf(ctx, system) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetTalkgroupsWithLearnedBySystem_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithLearnedBySystem' -type DB_GetTalkgroupsWithLearnedBySystem_Call struct { - *mock.Call -} - -// GetTalkgroupsWithLearnedBySystem is a helper method to define mock.On call -// - ctx context.Context -// - system int32 -func (_e *DB_Expecter) GetTalkgroupsWithLearnedBySystem(ctx interface{}, system interface{}) *DB_GetTalkgroupsWithLearnedBySystem_Call { - return &DB_GetTalkgroupsWithLearnedBySystem_Call{Call: _e.mock.On("GetTalkgroupsWithLearnedBySystem", ctx, system)} -} - -func (_c *DB_GetTalkgroupsWithLearnedBySystem_Call) Run(run func(ctx context.Context, system int32)) *DB_GetTalkgroupsWithLearnedBySystem_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32)) - }) - return _c -} - -func (_c *DB_GetTalkgroupsWithLearnedBySystem_Call) Return(_a0 []database.GetTalkgroupsWithLearnedBySystemRow, _a1 error) *DB_GetTalkgroupsWithLearnedBySystem_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetTalkgroupsWithLearnedBySystem_Call) RunAndReturn(run func(context.Context, int32) ([]database.GetTalkgroupsWithLearnedBySystemRow, error)) *DB_GetTalkgroupsWithLearnedBySystem_Call { - _c.Call.Return(run) - return _c -} - -// GetUserByID provides a mock function with given fields: ctx, id -func (_m *DB) GetUserByID(ctx context.Context, id int32) (database.User, error) { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for GetUserByID") - } - - var r0 database.User - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { - return rf(ctx, id) - } - if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { - r0 = rf(ctx, id) - } else { - r0 = ret.Get(0).(database.User) - } - - if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { - r1 = rf(ctx, id) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetUserByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByID' -type DB_GetUserByID_Call struct { - *mock.Call -} - -// GetUserByID is a helper method to define mock.On call -// - ctx context.Context -// - id int32 -func (_e *DB_Expecter) GetUserByID(ctx interface{}, id interface{}) *DB_GetUserByID_Call { - return &DB_GetUserByID_Call{Call: _e.mock.On("GetUserByID", ctx, id)} -} - -func (_c *DB_GetUserByID_Call) Run(run func(ctx context.Context, id int32)) *DB_GetUserByID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32)) - }) - return _c -} - -func (_c *DB_GetUserByID_Call) Return(_a0 database.User, _a1 error) *DB_GetUserByID_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetUserByID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *DB_GetUserByID_Call { - _c.Call.Return(run) - return _c -} - -// GetUserByUID provides a mock function with given fields: ctx, id -func (_m *DB) GetUserByUID(ctx context.Context, id int32) (database.User, error) { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for GetUserByUID") - } - - var r0 database.User - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { - return rf(ctx, id) - } - if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { - r0 = rf(ctx, id) - } else { - r0 = ret.Get(0).(database.User) - } - - if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { - r1 = rf(ctx, id) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetUserByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByUID' -type DB_GetUserByUID_Call struct { - *mock.Call -} - -// GetUserByUID is a helper method to define mock.On call -// - ctx context.Context -// - id int32 -func (_e *DB_Expecter) GetUserByUID(ctx interface{}, id interface{}) *DB_GetUserByUID_Call { - return &DB_GetUserByUID_Call{Call: _e.mock.On("GetUserByUID", ctx, id)} -} - -func (_c *DB_GetUserByUID_Call) Run(run func(ctx context.Context, id int32)) *DB_GetUserByUID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32)) - }) - return _c -} - -func (_c *DB_GetUserByUID_Call) Return(_a0 database.User, _a1 error) *DB_GetUserByUID_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetUserByUID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *DB_GetUserByUID_Call { - _c.Call.Return(run) - return _c -} - -// GetUserByUsername provides a mock function with given fields: ctx, username -func (_m *DB) GetUserByUsername(ctx context.Context, username string) (database.User, error) { - ret := _m.Called(ctx, username) - - if len(ret) == 0 { - panic("no return value specified for GetUserByUsername") - } - - var r0 database.User - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (database.User, error)); ok { - return rf(ctx, username) - } - if rf, ok := ret.Get(0).(func(context.Context, string) database.User); ok { - r0 = rf(ctx, username) - } else { - r0 = ret.Get(0).(database.User) - } - - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, username) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetUserByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByUsername' -type DB_GetUserByUsername_Call struct { - *mock.Call -} - -// GetUserByUsername is a helper method to define mock.On call -// - ctx context.Context -// - username string -func (_e *DB_Expecter) GetUserByUsername(ctx interface{}, username interface{}) *DB_GetUserByUsername_Call { - return &DB_GetUserByUsername_Call{Call: _e.mock.On("GetUserByUsername", ctx, username)} -} - -func (_c *DB_GetUserByUsername_Call) Run(run func(ctx context.Context, username string)) *DB_GetUserByUsername_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string)) - }) - return _c -} - -func (_c *DB_GetUserByUsername_Call) Return(_a0 database.User, _a1 error) *DB_GetUserByUsername_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetUserByUsername_Call) RunAndReturn(run func(context.Context, string) (database.User, error)) *DB_GetUserByUsername_Call { - _c.Call.Return(run) - return _c -} - -// GetUsers provides a mock function with given fields: ctx -func (_m *DB) GetUsers(ctx context.Context) ([]database.User, error) { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for GetUsers") - } - - var r0 []database.User - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]database.User, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) []database.User); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.User) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_GetUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUsers' -type DB_GetUsers_Call struct { - *mock.Call -} - -// GetUsers is a helper method to define mock.On call -// - ctx context.Context -func (_e *DB_Expecter) GetUsers(ctx interface{}) *DB_GetUsers_Call { - return &DB_GetUsers_Call{Call: _e.mock.On("GetUsers", ctx)} -} - -func (_c *DB_GetUsers_Call) Run(run func(ctx context.Context)) *DB_GetUsers_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *DB_GetUsers_Call) Return(_a0 []database.User, _a1 error) *DB_GetUsers_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_GetUsers_Call) RunAndReturn(run func(context.Context) ([]database.User, error)) *DB_GetUsers_Call { - _c.Call.Return(run) - return _c -} - -// SetCallTranscript provides a mock function with given fields: ctx, iD, transcript -func (_m *DB) SetCallTranscript(ctx context.Context, iD uuid.UUID, transcript *string) error { - ret := _m.Called(ctx, iD, transcript) - - if len(ret) == 0 { - panic("no return value specified for SetCallTranscript") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, uuid.UUID, *string) error); ok { - r0 = rf(ctx, iD, transcript) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_SetCallTranscript_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetCallTranscript' -type DB_SetCallTranscript_Call struct { - *mock.Call -} - -// SetCallTranscript is a helper method to define mock.On call -// - ctx context.Context -// - iD uuid.UUID -// - transcript *string -func (_e *DB_Expecter) SetCallTranscript(ctx interface{}, iD interface{}, transcript interface{}) *DB_SetCallTranscript_Call { - return &DB_SetCallTranscript_Call{Call: _e.mock.On("SetCallTranscript", ctx, iD, transcript)} -} - -func (_c *DB_SetCallTranscript_Call) Run(run func(ctx context.Context, iD uuid.UUID, transcript *string)) *DB_SetCallTranscript_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(uuid.UUID), args[2].(*string)) - }) - return _c -} - -func (_c *DB_SetCallTranscript_Call) Return(_a0 error) *DB_SetCallTranscript_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_SetCallTranscript_Call) RunAndReturn(run func(context.Context, uuid.UUID, *string) error) *DB_SetCallTranscript_Call { - _c.Call.Return(run) - return _c -} - -// SetTalkgroupTags provides a mock function with given fields: ctx, tags, systemID, tgID -func (_m *DB) SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tgID int32) error { - ret := _m.Called(ctx, tags, systemID, tgID) - - if len(ret) == 0 { - panic("no return value specified for SetTalkgroupTags") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []string, int32, int32) error); ok { - r0 = rf(ctx, tags, systemID, tgID) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_SetTalkgroupTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetTalkgroupTags' -type DB_SetTalkgroupTags_Call struct { - *mock.Call -} - -// SetTalkgroupTags is a helper method to define mock.On call -// - ctx context.Context -// - tags []string -// - systemID int32 -// - tgID int32 -func (_e *DB_Expecter) SetTalkgroupTags(ctx interface{}, tags interface{}, systemID interface{}, tgID interface{}) *DB_SetTalkgroupTags_Call { - return &DB_SetTalkgroupTags_Call{Call: _e.mock.On("SetTalkgroupTags", ctx, tags, systemID, tgID)} -} - -func (_c *DB_SetTalkgroupTags_Call) Run(run func(ctx context.Context, tags []string, systemID int32, tgID int32)) *DB_SetTalkgroupTags_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]string), args[2].(int32), args[3].(int32)) - }) - return _c -} - -func (_c *DB_SetTalkgroupTags_Call) Return(_a0 error) *DB_SetTalkgroupTags_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_SetTalkgroupTags_Call) RunAndReturn(run func(context.Context, []string, int32, int32) error) *DB_SetTalkgroupTags_Call { - _c.Call.Return(run) - return _c -} - -// UpdatePassword provides a mock function with given fields: ctx, username, password -func (_m *DB) UpdatePassword(ctx context.Context, username string, password string) error { - ret := _m.Called(ctx, username, password) - - if len(ret) == 0 { - panic("no return value specified for UpdatePassword") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { - r0 = rf(ctx, username, password) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// DB_UpdatePassword_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdatePassword' -type DB_UpdatePassword_Call struct { - *mock.Call -} - -// UpdatePassword is a helper method to define mock.On call -// - ctx context.Context -// - username string -// - password string -func (_e *DB_Expecter) UpdatePassword(ctx interface{}, username interface{}, password interface{}) *DB_UpdatePassword_Call { - return &DB_UpdatePassword_Call{Call: _e.mock.On("UpdatePassword", ctx, username, password)} -} - -func (_c *DB_UpdatePassword_Call) Run(run func(ctx context.Context, username string, password string)) *DB_UpdatePassword_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *DB_UpdatePassword_Call) Return(_a0 error) *DB_UpdatePassword_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *DB_UpdatePassword_Call) RunAndReturn(run func(context.Context, string, string) error) *DB_UpdatePassword_Call { - _c.Call.Return(run) - return _c -} - -// UpdateTalkgroup provides a mock function with given fields: ctx, arg -func (_m *DB) UpdateTalkgroup(ctx context.Context, arg database.UpdateTalkgroupParams) (database.Talkgroup, error) { - ret := _m.Called(ctx, arg) - - if len(ret) == 0 { - panic("no return value specified for UpdateTalkgroup") - } - - var r0 database.Talkgroup - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, database.UpdateTalkgroupParams) (database.Talkgroup, error)); ok { - return rf(ctx, arg) - } - if rf, ok := ret.Get(0).(func(context.Context, database.UpdateTalkgroupParams) database.Talkgroup); ok { - r0 = rf(ctx, arg) - } else { - r0 = ret.Get(0).(database.Talkgroup) - } - - if rf, ok := ret.Get(1).(func(context.Context, database.UpdateTalkgroupParams) error); ok { - r1 = rf(ctx, arg) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DB_UpdateTalkgroup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateTalkgroup' -type DB_UpdateTalkgroup_Call struct { - *mock.Call -} - -// UpdateTalkgroup is a helper method to define mock.On call -// - ctx context.Context -// - arg database.UpdateTalkgroupParams -func (_e *DB_Expecter) UpdateTalkgroup(ctx interface{}, arg interface{}) *DB_UpdateTalkgroup_Call { - return &DB_UpdateTalkgroup_Call{Call: _e.mock.On("UpdateTalkgroup", ctx, arg)} -} - -func (_c *DB_UpdateTalkgroup_Call) Run(run func(ctx context.Context, arg database.UpdateTalkgroupParams)) *DB_UpdateTalkgroup_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.UpdateTalkgroupParams)) - }) - return _c -} - -func (_c *DB_UpdateTalkgroup_Call) Return(_a0 database.Talkgroup, _a1 error) *DB_UpdateTalkgroup_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *DB_UpdateTalkgroup_Call) RunAndReturn(run func(context.Context, database.UpdateTalkgroupParams) (database.Talkgroup, error)) *DB_UpdateTalkgroup_Call { - _c.Call.Return(run) - return _c -} - -// NewDB creates a new instance of DB. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDB(t interface { - mock.TestingT - Cleanup(func()) -}) *DB { - mock := &DB{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/database/mocks/Store.go b/pkg/database/mocks/Store.go new file mode 100644 index 0000000..5ea8209 --- /dev/null +++ b/pkg/database/mocks/Store.go @@ -0,0 +1,1786 @@ +// Code generated by mockery v2.47.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + database "dynatron.me/x/stillbox/pkg/database" + mock "github.com/stretchr/testify/mock" + + pgtype "github.com/jackc/pgx/v5/pgtype" + + pgx "github.com/jackc/pgx/v5" + + uuid "github.com/google/uuid" +) + +// Store is an autogenerated mock type for the Store type +type Store struct { + mock.Mock +} + +type Store_Expecter struct { + mock *mock.Mock +} + +func (_m *Store) EXPECT() *Store_Expecter { + return &Store_Expecter{mock: &_m.Mock} +} + +// AddAlert provides a mock function with given fields: ctx, arg +func (_m *Store) AddAlert(ctx context.Context, arg database.AddAlertParams) error { + ret := _m.Called(ctx, arg) + + if len(ret) == 0 { + panic("no return value specified for AddAlert") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.AddAlertParams) error); ok { + r0 = rf(ctx, arg) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_AddAlert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddAlert' +type Store_AddAlert_Call struct { + *mock.Call +} + +// AddAlert is a helper method to define mock.On call +// - ctx context.Context +// - arg database.AddAlertParams +func (_e *Store_Expecter) AddAlert(ctx interface{}, arg interface{}) *Store_AddAlert_Call { + return &Store_AddAlert_Call{Call: _e.mock.On("AddAlert", ctx, arg)} +} + +func (_c *Store_AddAlert_Call) Run(run func(ctx context.Context, arg database.AddAlertParams)) *Store_AddAlert_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.AddAlertParams)) + }) + return _c +} + +func (_c *Store_AddAlert_Call) Return(_a0 error) *Store_AddAlert_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_AddAlert_Call) RunAndReturn(run func(context.Context, database.AddAlertParams) error) *Store_AddAlert_Call { + _c.Call.Return(run) + return _c +} + +// AddCall provides a mock function with given fields: ctx, arg +func (_m *Store) AddCall(ctx context.Context, arg database.AddCallParams) error { + ret := _m.Called(ctx, arg) + + if len(ret) == 0 { + panic("no return value specified for AddCall") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.AddCallParams) error); ok { + r0 = rf(ctx, arg) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_AddCall_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddCall' +type Store_AddCall_Call struct { + *mock.Call +} + +// AddCall is a helper method to define mock.On call +// - ctx context.Context +// - arg database.AddCallParams +func (_e *Store_Expecter) AddCall(ctx interface{}, arg interface{}) *Store_AddCall_Call { + return &Store_AddCall_Call{Call: _e.mock.On("AddCall", ctx, arg)} +} + +func (_c *Store_AddCall_Call) Run(run func(ctx context.Context, arg database.AddCallParams)) *Store_AddCall_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.AddCallParams)) + }) + return _c +} + +func (_c *Store_AddCall_Call) Return(_a0 error) *Store_AddCall_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_AddCall_Call) RunAndReturn(run func(context.Context, database.AddCallParams) error) *Store_AddCall_Call { + _c.Call.Return(run) + return _c +} + +// AddLearnedTalkgroup provides a mock function with given fields: ctx, arg +func (_m *Store) AddLearnedTalkgroup(ctx context.Context, arg database.AddLearnedTalkgroupParams) (int, error) { + ret := _m.Called(ctx, arg) + + if len(ret) == 0 { + panic("no return value specified for AddLearnedTalkgroup") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.AddLearnedTalkgroupParams) (int, error)); ok { + return rf(ctx, arg) + } + if rf, ok := ret.Get(0).(func(context.Context, database.AddLearnedTalkgroupParams) int); ok { + r0 = rf(ctx, arg) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context, database.AddLearnedTalkgroupParams) error); ok { + r1 = rf(ctx, arg) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_AddLearnedTalkgroup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddLearnedTalkgroup' +type Store_AddLearnedTalkgroup_Call struct { + *mock.Call +} + +// AddLearnedTalkgroup is a helper method to define mock.On call +// - ctx context.Context +// - arg database.AddLearnedTalkgroupParams +func (_e *Store_Expecter) AddLearnedTalkgroup(ctx interface{}, arg interface{}) *Store_AddLearnedTalkgroup_Call { + return &Store_AddLearnedTalkgroup_Call{Call: _e.mock.On("AddLearnedTalkgroup", ctx, arg)} +} + +func (_c *Store_AddLearnedTalkgroup_Call) Run(run func(ctx context.Context, arg database.AddLearnedTalkgroupParams)) *Store_AddLearnedTalkgroup_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.AddLearnedTalkgroupParams)) + }) + return _c +} + +func (_c *Store_AddLearnedTalkgroup_Call) Return(_a0 int, _a1 error) *Store_AddLearnedTalkgroup_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_AddLearnedTalkgroup_Call) RunAndReturn(run func(context.Context, database.AddLearnedTalkgroupParams) (int, error)) *Store_AddLearnedTalkgroup_Call { + _c.Call.Return(run) + return _c +} + +// AddTalkgroupWithLearnedFlag provides a mock function with given fields: ctx, systemID, tGID +func (_m *Store) AddTalkgroupWithLearnedFlag(ctx context.Context, systemID int32, tGID int32) error { + ret := _m.Called(ctx, systemID, tGID) + + if len(ret) == 0 { + panic("no return value specified for AddTalkgroupWithLearnedFlag") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) error); ok { + r0 = rf(ctx, systemID, tGID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_AddTalkgroupWithLearnedFlag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddTalkgroupWithLearnedFlag' +type Store_AddTalkgroupWithLearnedFlag_Call struct { + *mock.Call +} + +// AddTalkgroupWithLearnedFlag is a helper method to define mock.On call +// - ctx context.Context +// - systemID int32 +// - tGID int32 +func (_e *Store_Expecter) AddTalkgroupWithLearnedFlag(ctx interface{}, systemID interface{}, tGID interface{}) *Store_AddTalkgroupWithLearnedFlag_Call { + return &Store_AddTalkgroupWithLearnedFlag_Call{Call: _e.mock.On("AddTalkgroupWithLearnedFlag", ctx, systemID, tGID)} +} + +func (_c *Store_AddTalkgroupWithLearnedFlag_Call) Run(run func(ctx context.Context, systemID int32, tGID int32)) *Store_AddTalkgroupWithLearnedFlag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32), args[2].(int32)) + }) + return _c +} + +func (_c *Store_AddTalkgroupWithLearnedFlag_Call) Return(_a0 error) *Store_AddTalkgroupWithLearnedFlag_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_AddTalkgroupWithLearnedFlag_Call) RunAndReturn(run func(context.Context, int32, int32) error) *Store_AddTalkgroupWithLearnedFlag_Call { + _c.Call.Return(run) + return _c +} + +// BulkSetTalkgroupTags provides a mock function with given fields: ctx, tgs, tags +func (_m *Store) BulkSetTalkgroupTags(ctx context.Context, tgs database.TGTuples, tags []string) error { + ret := _m.Called(ctx, tgs, tags) + + if len(ret) == 0 { + panic("no return value specified for BulkSetTalkgroupTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples, []string) error); ok { + r0 = rf(ctx, tgs, tags) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_BulkSetTalkgroupTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BulkSetTalkgroupTags' +type Store_BulkSetTalkgroupTags_Call struct { + *mock.Call +} + +// BulkSetTalkgroupTags is a helper method to define mock.On call +// - ctx context.Context +// - tgs database.TGTuples +// - tags []string +func (_e *Store_Expecter) BulkSetTalkgroupTags(ctx interface{}, tgs interface{}, tags interface{}) *Store_BulkSetTalkgroupTags_Call { + return &Store_BulkSetTalkgroupTags_Call{Call: _e.mock.On("BulkSetTalkgroupTags", ctx, tgs, tags)} +} + +func (_c *Store_BulkSetTalkgroupTags_Call) Run(run func(ctx context.Context, tgs database.TGTuples, tags []string)) *Store_BulkSetTalkgroupTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TGTuples), args[2].([]string)) + }) + return _c +} + +func (_c *Store_BulkSetTalkgroupTags_Call) Return(_a0 error) *Store_BulkSetTalkgroupTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_BulkSetTalkgroupTags_Call) RunAndReturn(run func(context.Context, database.TGTuples, []string) error) *Store_BulkSetTalkgroupTags_Call { + _c.Call.Return(run) + return _c +} + +// CreateAPIKey provides a mock function with given fields: ctx, owner, expires, disabled +func (_m *Store) CreateAPIKey(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool) (database.ApiKey, error) { + ret := _m.Called(ctx, owner, expires, disabled) + + if len(ret) == 0 { + panic("no return value specified for CreateAPIKey") + } + + var r0 database.ApiKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int, pgtype.Timestamp, *bool) (database.ApiKey, error)); ok { + return rf(ctx, owner, expires, disabled) + } + if rf, ok := ret.Get(0).(func(context.Context, int, pgtype.Timestamp, *bool) database.ApiKey); ok { + r0 = rf(ctx, owner, expires, disabled) + } else { + r0 = ret.Get(0).(database.ApiKey) + } + + if rf, ok := ret.Get(1).(func(context.Context, int, pgtype.Timestamp, *bool) error); ok { + r1 = rf(ctx, owner, expires, disabled) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_CreateAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAPIKey' +type Store_CreateAPIKey_Call struct { + *mock.Call +} + +// CreateAPIKey is a helper method to define mock.On call +// - ctx context.Context +// - owner int +// - expires pgtype.Timestamp +// - disabled *bool +func (_e *Store_Expecter) CreateAPIKey(ctx interface{}, owner interface{}, expires interface{}, disabled interface{}) *Store_CreateAPIKey_Call { + return &Store_CreateAPIKey_Call{Call: _e.mock.On("CreateAPIKey", ctx, owner, expires, disabled)} +} + +func (_c *Store_CreateAPIKey_Call) Run(run func(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool)) *Store_CreateAPIKey_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(pgtype.Timestamp), args[3].(*bool)) + }) + return _c +} + +func (_c *Store_CreateAPIKey_Call) Return(_a0 database.ApiKey, _a1 error) *Store_CreateAPIKey_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_CreateAPIKey_Call) RunAndReturn(run func(context.Context, int, pgtype.Timestamp, *bool) (database.ApiKey, error)) *Store_CreateAPIKey_Call { + _c.Call.Return(run) + return _c +} + +// CreateUser provides a mock function with given fields: ctx, arg +func (_m *Store) CreateUser(ctx context.Context, arg database.CreateUserParams) (database.User, error) { + ret := _m.Called(ctx, arg) + + if len(ret) == 0 { + panic("no return value specified for CreateUser") + } + + var r0 database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.CreateUserParams) (database.User, error)); ok { + return rf(ctx, arg) + } + if rf, ok := ret.Get(0).(func(context.Context, database.CreateUserParams) database.User); ok { + r0 = rf(ctx, arg) + } else { + r0 = ret.Get(0).(database.User) + } + + if rf, ok := ret.Get(1).(func(context.Context, database.CreateUserParams) error); ok { + r1 = rf(ctx, arg) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_CreateUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateUser' +type Store_CreateUser_Call struct { + *mock.Call +} + +// CreateUser is a helper method to define mock.On call +// - ctx context.Context +// - arg database.CreateUserParams +func (_e *Store_Expecter) CreateUser(ctx interface{}, arg interface{}) *Store_CreateUser_Call { + return &Store_CreateUser_Call{Call: _e.mock.On("CreateUser", ctx, arg)} +} + +func (_c *Store_CreateUser_Call) Run(run func(ctx context.Context, arg database.CreateUserParams)) *Store_CreateUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.CreateUserParams)) + }) + return _c +} + +func (_c *Store_CreateUser_Call) Return(_a0 database.User, _a1 error) *Store_CreateUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_CreateUser_Call) RunAndReturn(run func(context.Context, database.CreateUserParams) (database.User, error)) *Store_CreateUser_Call { + _c.Call.Return(run) + return _c +} + +// DB provides a mock function with given fields: +func (_m *Store) DB() *database.Database { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for DB") + } + + var r0 *database.Database + if rf, ok := ret.Get(0).(func() *database.Database); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Database) + } + } + + return r0 +} + +// Store_DB_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DB' +type Store_DB_Call struct { + *mock.Call +} + +// DB is a helper method to define mock.On call +func (_e *Store_Expecter) DB() *Store_DB_Call { + return &Store_DB_Call{Call: _e.mock.On("DB")} +} + +func (_c *Store_DB_Call) Run(run func()) *Store_DB_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Store_DB_Call) Return(_a0 *database.Database) *Store_DB_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_DB_Call) RunAndReturn(run func() *database.Database) *Store_DB_Call { + _c.Call.Return(run) + return _c +} + +// DeleteAPIKey provides a mock function with given fields: ctx, apiKey +func (_m *Store) DeleteAPIKey(ctx context.Context, apiKey string) error { + ret := _m.Called(ctx, apiKey) + + if len(ret) == 0 { + panic("no return value specified for DeleteAPIKey") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, apiKey) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_DeleteAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAPIKey' +type Store_DeleteAPIKey_Call struct { + *mock.Call +} + +// DeleteAPIKey is a helper method to define mock.On call +// - ctx context.Context +// - apiKey string +func (_e *Store_Expecter) DeleteAPIKey(ctx interface{}, apiKey interface{}) *Store_DeleteAPIKey_Call { + return &Store_DeleteAPIKey_Call{Call: _e.mock.On("DeleteAPIKey", ctx, apiKey)} +} + +func (_c *Store_DeleteAPIKey_Call) Run(run func(ctx context.Context, apiKey string)) *Store_DeleteAPIKey_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Store_DeleteAPIKey_Call) Return(_a0 error) *Store_DeleteAPIKey_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_DeleteAPIKey_Call) RunAndReturn(run func(context.Context, string) error) *Store_DeleteAPIKey_Call { + _c.Call.Return(run) + return _c +} + +// DeleteUser provides a mock function with given fields: ctx, username +func (_m *Store) DeleteUser(ctx context.Context, username string) error { + ret := _m.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for DeleteUser") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, username) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_DeleteUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteUser' +type Store_DeleteUser_Call struct { + *mock.Call +} + +// DeleteUser is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *Store_Expecter) DeleteUser(ctx interface{}, username interface{}) *Store_DeleteUser_Call { + return &Store_DeleteUser_Call{Call: _e.mock.On("DeleteUser", ctx, username)} +} + +func (_c *Store_DeleteUser_Call) Run(run func(ctx context.Context, username string)) *Store_DeleteUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Store_DeleteUser_Call) Return(_a0 error) *Store_DeleteUser_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_DeleteUser_Call) RunAndReturn(run func(context.Context, string) error) *Store_DeleteUser_Call { + _c.Call.Return(run) + return _c +} + +// GetAPIKey provides a mock function with given fields: ctx, apiKey +func (_m *Store) GetAPIKey(ctx context.Context, apiKey string) (database.ApiKey, error) { + ret := _m.Called(ctx, apiKey) + + if len(ret) == 0 { + panic("no return value specified for GetAPIKey") + } + + var r0 database.ApiKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.ApiKey, error)); ok { + return rf(ctx, apiKey) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.ApiKey); ok { + r0 = rf(ctx, apiKey) + } else { + r0 = ret.Get(0).(database.ApiKey) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, apiKey) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAPIKey' +type Store_GetAPIKey_Call struct { + *mock.Call +} + +// GetAPIKey is a helper method to define mock.On call +// - ctx context.Context +// - apiKey string +func (_e *Store_Expecter) GetAPIKey(ctx interface{}, apiKey interface{}) *Store_GetAPIKey_Call { + return &Store_GetAPIKey_Call{Call: _e.mock.On("GetAPIKey", ctx, apiKey)} +} + +func (_c *Store_GetAPIKey_Call) Run(run func(ctx context.Context, apiKey string)) *Store_GetAPIKey_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Store_GetAPIKey_Call) Return(_a0 database.ApiKey, _a1 error) *Store_GetAPIKey_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetAPIKey_Call) RunAndReturn(run func(context.Context, string) (database.ApiKey, error)) *Store_GetAPIKey_Call { + _c.Call.Return(run) + return _c +} + +// GetDatabaseSize provides a mock function with given fields: ctx +func (_m *Store) GetDatabaseSize(ctx context.Context) (string, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetDatabaseSize") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (string, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) string); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetDatabaseSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDatabaseSize' +type Store_GetDatabaseSize_Call struct { + *mock.Call +} + +// GetDatabaseSize is a helper method to define mock.On call +// - ctx context.Context +func (_e *Store_Expecter) GetDatabaseSize(ctx interface{}) *Store_GetDatabaseSize_Call { + return &Store_GetDatabaseSize_Call{Call: _e.mock.On("GetDatabaseSize", ctx)} +} + +func (_c *Store_GetDatabaseSize_Call) Run(run func(ctx context.Context)) *Store_GetDatabaseSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Store_GetDatabaseSize_Call) Return(_a0 string, _a1 error) *Store_GetDatabaseSize_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetDatabaseSize_Call) RunAndReturn(run func(context.Context) (string, error)) *Store_GetDatabaseSize_Call { + _c.Call.Return(run) + return _c +} + +// GetSystemName provides a mock function with given fields: ctx, systemID +func (_m *Store) GetSystemName(ctx context.Context, systemID int) (string, error) { + ret := _m.Called(ctx, systemID) + + if len(ret) == 0 { + panic("no return value specified for GetSystemName") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int) (string, error)); ok { + return rf(ctx, systemID) + } + if rf, ok := ret.Get(0).(func(context.Context, int) string); ok { + r0 = rf(ctx, systemID) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { + r1 = rf(ctx, systemID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetSystemName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSystemName' +type Store_GetSystemName_Call struct { + *mock.Call +} + +// GetSystemName is a helper method to define mock.On call +// - ctx context.Context +// - systemID int +func (_e *Store_Expecter) GetSystemName(ctx interface{}, systemID interface{}) *Store_GetSystemName_Call { + return &Store_GetSystemName_Call{Call: _e.mock.On("GetSystemName", ctx, systemID)} +} + +func (_c *Store_GetSystemName_Call) Run(run func(ctx context.Context, systemID int)) *Store_GetSystemName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int)) + }) + return _c +} + +func (_c *Store_GetSystemName_Call) Return(_a0 string, _a1 error) *Store_GetSystemName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetSystemName_Call) RunAndReturn(run func(context.Context, int) (string, error)) *Store_GetSystemName_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroup provides a mock function with given fields: ctx, systemID, tGID +func (_m *Store) GetTalkgroup(ctx context.Context, systemID int32, tGID int32) (database.GetTalkgroupRow, error) { + ret := _m.Called(ctx, systemID, tGID) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroup") + } + + var r0 database.GetTalkgroupRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) (database.GetTalkgroupRow, error)); ok { + return rf(ctx, systemID, tGID) + } + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) database.GetTalkgroupRow); ok { + r0 = rf(ctx, systemID, tGID) + } else { + r0 = ret.Get(0).(database.GetTalkgroupRow) + } + + if rf, ok := ret.Get(1).(func(context.Context, int32, int32) error); ok { + r1 = rf(ctx, systemID, tGID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroup' +type Store_GetTalkgroup_Call struct { + *mock.Call +} + +// GetTalkgroup is a helper method to define mock.On call +// - ctx context.Context +// - systemID int32 +// - tGID int32 +func (_e *Store_Expecter) GetTalkgroup(ctx interface{}, systemID interface{}, tGID interface{}) *Store_GetTalkgroup_Call { + return &Store_GetTalkgroup_Call{Call: _e.mock.On("GetTalkgroup", ctx, systemID, tGID)} +} + +func (_c *Store_GetTalkgroup_Call) Run(run func(ctx context.Context, systemID int32, tGID int32)) *Store_GetTalkgroup_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32), args[2].(int32)) + }) + return _c +} + +func (_c *Store_GetTalkgroup_Call) Return(_a0 database.GetTalkgroupRow, _a1 error) *Store_GetTalkgroup_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroup_Call) RunAndReturn(run func(context.Context, int32, int32) (database.GetTalkgroupRow, error)) *Store_GetTalkgroup_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupIDsByTags provides a mock function with given fields: ctx, anyTags, allTags, notTags +func (_m *Store) GetTalkgroupIDsByTags(ctx context.Context, anyTags []string, allTags []string, notTags []string) ([]database.GetTalkgroupIDsByTagsRow, error) { + ret := _m.Called(ctx, anyTags, allTags, notTags) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupIDsByTags") + } + + var r0 []database.GetTalkgroupIDsByTagsRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string, []string, []string) ([]database.GetTalkgroupIDsByTagsRow, error)); ok { + return rf(ctx, anyTags, allTags, notTags) + } + if rf, ok := ret.Get(0).(func(context.Context, []string, []string, []string) []database.GetTalkgroupIDsByTagsRow); ok { + r0 = rf(ctx, anyTags, allTags, notTags) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupIDsByTagsRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string, []string, []string) error); ok { + r1 = rf(ctx, anyTags, allTags, notTags) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupIDsByTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupIDsByTags' +type Store_GetTalkgroupIDsByTags_Call struct { + *mock.Call +} + +// GetTalkgroupIDsByTags is a helper method to define mock.On call +// - ctx context.Context +// - anyTags []string +// - allTags []string +// - notTags []string +func (_e *Store_Expecter) GetTalkgroupIDsByTags(ctx interface{}, anyTags interface{}, allTags interface{}, notTags interface{}) *Store_GetTalkgroupIDsByTags_Call { + return &Store_GetTalkgroupIDsByTags_Call{Call: _e.mock.On("GetTalkgroupIDsByTags", ctx, anyTags, allTags, notTags)} +} + +func (_c *Store_GetTalkgroupIDsByTags_Call) Run(run func(ctx context.Context, anyTags []string, allTags []string, notTags []string)) *Store_GetTalkgroupIDsByTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string), args[2].([]string), args[3].([]string)) + }) + return _c +} + +func (_c *Store_GetTalkgroupIDsByTags_Call) Return(_a0 []database.GetTalkgroupIDsByTagsRow, _a1 error) *Store_GetTalkgroupIDsByTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupIDsByTags_Call) RunAndReturn(run func(context.Context, []string, []string, []string) ([]database.GetTalkgroupIDsByTagsRow, error)) *Store_GetTalkgroupIDsByTags_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupTags provides a mock function with given fields: ctx, systemID, tGID +func (_m *Store) GetTalkgroupTags(ctx context.Context, systemID int32, tGID int32) ([]string, error) { + ret := _m.Called(ctx, systemID, tGID) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupTags") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) ([]string, error)); ok { + return rf(ctx, systemID, tGID) + } + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) []string); ok { + r0 = rf(ctx, systemID, tGID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int32, int32) error); ok { + r1 = rf(ctx, systemID, tGID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupTags' +type Store_GetTalkgroupTags_Call struct { + *mock.Call +} + +// GetTalkgroupTags is a helper method to define mock.On call +// - ctx context.Context +// - systemID int32 +// - tGID int32 +func (_e *Store_Expecter) GetTalkgroupTags(ctx interface{}, systemID interface{}, tGID interface{}) *Store_GetTalkgroupTags_Call { + return &Store_GetTalkgroupTags_Call{Call: _e.mock.On("GetTalkgroupTags", ctx, systemID, tGID)} +} + +func (_c *Store_GetTalkgroupTags_Call) Run(run func(ctx context.Context, systemID int32, tGID int32)) *Store_GetTalkgroupTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32), args[2].(int32)) + }) + return _c +} + +func (_c *Store_GetTalkgroupTags_Call) Return(_a0 []string, _a1 error) *Store_GetTalkgroupTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupTags_Call) RunAndReturn(run func(context.Context, int32, int32) ([]string, error)) *Store_GetTalkgroupTags_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupWithLearned provides a mock function with given fields: ctx, systemID, tGID +func (_m *Store) GetTalkgroupWithLearned(ctx context.Context, systemID int32, tGID int32) (database.GetTalkgroupWithLearnedRow, error) { + ret := _m.Called(ctx, systemID, tGID) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupWithLearned") + } + + var r0 database.GetTalkgroupWithLearnedRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) (database.GetTalkgroupWithLearnedRow, error)); ok { + return rf(ctx, systemID, tGID) + } + if rf, ok := ret.Get(0).(func(context.Context, int32, int32) database.GetTalkgroupWithLearnedRow); ok { + r0 = rf(ctx, systemID, tGID) + } else { + r0 = ret.Get(0).(database.GetTalkgroupWithLearnedRow) + } + + if rf, ok := ret.Get(1).(func(context.Context, int32, int32) error); ok { + r1 = rf(ctx, systemID, tGID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupWithLearned_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupWithLearned' +type Store_GetTalkgroupWithLearned_Call struct { + *mock.Call +} + +// GetTalkgroupWithLearned is a helper method to define mock.On call +// - ctx context.Context +// - systemID int32 +// - tGID int32 +func (_e *Store_Expecter) GetTalkgroupWithLearned(ctx interface{}, systemID interface{}, tGID interface{}) *Store_GetTalkgroupWithLearned_Call { + return &Store_GetTalkgroupWithLearned_Call{Call: _e.mock.On("GetTalkgroupWithLearned", ctx, systemID, tGID)} +} + +func (_c *Store_GetTalkgroupWithLearned_Call) Run(run func(ctx context.Context, systemID int32, tGID int32)) *Store_GetTalkgroupWithLearned_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32), args[2].(int32)) + }) + return _c +} + +func (_c *Store_GetTalkgroupWithLearned_Call) Return(_a0 database.GetTalkgroupWithLearnedRow, _a1 error) *Store_GetTalkgroupWithLearned_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupWithLearned_Call) RunAndReturn(run func(context.Context, int32, int32) (database.GetTalkgroupWithLearnedRow, error)) *Store_GetTalkgroupWithLearned_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupsBySysTGID provides a mock function with given fields: ctx, ids +func (_m *Store) GetTalkgroupsBySysTGID(ctx context.Context, ids database.TGTuples) ([]database.GetTalkgroupsRow, error) { + ret := _m.Called(ctx, ids) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupsBySysTGID") + } + + var r0 []database.GetTalkgroupsRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)); ok { + return rf(ctx, ids) + } + if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) []database.GetTalkgroupsRow); ok { + r0 = rf(ctx, ids) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupsRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.TGTuples) error); ok { + r1 = rf(ctx, ids) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupsBySysTGID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsBySysTGID' +type Store_GetTalkgroupsBySysTGID_Call struct { + *mock.Call +} + +// GetTalkgroupsBySysTGID is a helper method to define mock.On call +// - ctx context.Context +// - ids database.TGTuples +func (_e *Store_Expecter) GetTalkgroupsBySysTGID(ctx interface{}, ids interface{}) *Store_GetTalkgroupsBySysTGID_Call { + return &Store_GetTalkgroupsBySysTGID_Call{Call: _e.mock.On("GetTalkgroupsBySysTGID", ctx, ids)} +} + +func (_c *Store_GetTalkgroupsBySysTGID_Call) Run(run func(ctx context.Context, ids database.TGTuples)) *Store_GetTalkgroupsBySysTGID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TGTuples)) + }) + return _c +} + +func (_c *Store_GetTalkgroupsBySysTGID_Call) Return(_a0 []database.GetTalkgroupsRow, _a1 error) *Store_GetTalkgroupsBySysTGID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupsBySysTGID_Call) RunAndReturn(run func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)) *Store_GetTalkgroupsBySysTGID_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupsWithAllTags provides a mock function with given fields: ctx, tags +func (_m *Store) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]database.GetTalkgroupsWithAllTagsRow, error) { + ret := _m.Called(ctx, tags) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupsWithAllTags") + } + + var r0 []database.GetTalkgroupsWithAllTagsRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.GetTalkgroupsWithAllTagsRow, error)); ok { + return rf(ctx, tags) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []database.GetTalkgroupsWithAllTagsRow); ok { + r0 = rf(ctx, tags) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupsWithAllTagsRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, tags) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupsWithAllTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithAllTags' +type Store_GetTalkgroupsWithAllTags_Call struct { + *mock.Call +} + +// GetTalkgroupsWithAllTags is a helper method to define mock.On call +// - ctx context.Context +// - tags []string +func (_e *Store_Expecter) GetTalkgroupsWithAllTags(ctx interface{}, tags interface{}) *Store_GetTalkgroupsWithAllTags_Call { + return &Store_GetTalkgroupsWithAllTags_Call{Call: _e.mock.On("GetTalkgroupsWithAllTags", ctx, tags)} +} + +func (_c *Store_GetTalkgroupsWithAllTags_Call) Run(run func(ctx context.Context, tags []string)) *Store_GetTalkgroupsWithAllTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *Store_GetTalkgroupsWithAllTags_Call) Return(_a0 []database.GetTalkgroupsWithAllTagsRow, _a1 error) *Store_GetTalkgroupsWithAllTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupsWithAllTags_Call) RunAndReturn(run func(context.Context, []string) ([]database.GetTalkgroupsWithAllTagsRow, error)) *Store_GetTalkgroupsWithAllTags_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupsWithAnyTags provides a mock function with given fields: ctx, tags +func (_m *Store) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]database.GetTalkgroupsWithAnyTagsRow, error) { + ret := _m.Called(ctx, tags) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupsWithAnyTags") + } + + var r0 []database.GetTalkgroupsWithAnyTagsRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.GetTalkgroupsWithAnyTagsRow, error)); ok { + return rf(ctx, tags) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []database.GetTalkgroupsWithAnyTagsRow); ok { + r0 = rf(ctx, tags) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupsWithAnyTagsRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, tags) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupsWithAnyTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithAnyTags' +type Store_GetTalkgroupsWithAnyTags_Call struct { + *mock.Call +} + +// GetTalkgroupsWithAnyTags is a helper method to define mock.On call +// - ctx context.Context +// - tags []string +func (_e *Store_Expecter) GetTalkgroupsWithAnyTags(ctx interface{}, tags interface{}) *Store_GetTalkgroupsWithAnyTags_Call { + return &Store_GetTalkgroupsWithAnyTags_Call{Call: _e.mock.On("GetTalkgroupsWithAnyTags", ctx, tags)} +} + +func (_c *Store_GetTalkgroupsWithAnyTags_Call) Run(run func(ctx context.Context, tags []string)) *Store_GetTalkgroupsWithAnyTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *Store_GetTalkgroupsWithAnyTags_Call) Return(_a0 []database.GetTalkgroupsWithAnyTagsRow, _a1 error) *Store_GetTalkgroupsWithAnyTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupsWithAnyTags_Call) RunAndReturn(run func(context.Context, []string) ([]database.GetTalkgroupsWithAnyTagsRow, error)) *Store_GetTalkgroupsWithAnyTags_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupsWithLearned provides a mock function with given fields: ctx +func (_m *Store) GetTalkgroupsWithLearned(ctx context.Context) ([]database.GetTalkgroupsWithLearnedRow, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupsWithLearned") + } + + var r0 []database.GetTalkgroupsWithLearnedRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.GetTalkgroupsWithLearnedRow, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.GetTalkgroupsWithLearnedRow); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupsWithLearnedRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupsWithLearned_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithLearned' +type Store_GetTalkgroupsWithLearned_Call struct { + *mock.Call +} + +// GetTalkgroupsWithLearned is a helper method to define mock.On call +// - ctx context.Context +func (_e *Store_Expecter) GetTalkgroupsWithLearned(ctx interface{}) *Store_GetTalkgroupsWithLearned_Call { + return &Store_GetTalkgroupsWithLearned_Call{Call: _e.mock.On("GetTalkgroupsWithLearned", ctx)} +} + +func (_c *Store_GetTalkgroupsWithLearned_Call) Run(run func(ctx context.Context)) *Store_GetTalkgroupsWithLearned_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Store_GetTalkgroupsWithLearned_Call) Return(_a0 []database.GetTalkgroupsWithLearnedRow, _a1 error) *Store_GetTalkgroupsWithLearned_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupsWithLearned_Call) RunAndReturn(run func(context.Context) ([]database.GetTalkgroupsWithLearnedRow, error)) *Store_GetTalkgroupsWithLearned_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupsWithLearnedBySysTGID provides a mock function with given fields: ctx, ids +func (_m *Store) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids database.TGTuples) ([]database.GetTalkgroupsRow, error) { + ret := _m.Called(ctx, ids) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupsWithLearnedBySysTGID") + } + + var r0 []database.GetTalkgroupsRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)); ok { + return rf(ctx, ids) + } + if rf, ok := ret.Get(0).(func(context.Context, database.TGTuples) []database.GetTalkgroupsRow); ok { + r0 = rf(ctx, ids) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupsRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.TGTuples) error); ok { + r1 = rf(ctx, ids) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupsWithLearnedBySysTGID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithLearnedBySysTGID' +type Store_GetTalkgroupsWithLearnedBySysTGID_Call struct { + *mock.Call +} + +// GetTalkgroupsWithLearnedBySysTGID is a helper method to define mock.On call +// - ctx context.Context +// - ids database.TGTuples +func (_e *Store_Expecter) GetTalkgroupsWithLearnedBySysTGID(ctx interface{}, ids interface{}) *Store_GetTalkgroupsWithLearnedBySysTGID_Call { + return &Store_GetTalkgroupsWithLearnedBySysTGID_Call{Call: _e.mock.On("GetTalkgroupsWithLearnedBySysTGID", ctx, ids)} +} + +func (_c *Store_GetTalkgroupsWithLearnedBySysTGID_Call) Run(run func(ctx context.Context, ids database.TGTuples)) *Store_GetTalkgroupsWithLearnedBySysTGID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TGTuples)) + }) + return _c +} + +func (_c *Store_GetTalkgroupsWithLearnedBySysTGID_Call) Return(_a0 []database.GetTalkgroupsRow, _a1 error) *Store_GetTalkgroupsWithLearnedBySysTGID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupsWithLearnedBySysTGID_Call) RunAndReturn(run func(context.Context, database.TGTuples) ([]database.GetTalkgroupsRow, error)) *Store_GetTalkgroupsWithLearnedBySysTGID_Call { + _c.Call.Return(run) + return _c +} + +// GetTalkgroupsWithLearnedBySystem provides a mock function with given fields: ctx, system +func (_m *Store) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]database.GetTalkgroupsWithLearnedBySystemRow, error) { + ret := _m.Called(ctx, system) + + if len(ret) == 0 { + panic("no return value specified for GetTalkgroupsWithLearnedBySystem") + } + + var r0 []database.GetTalkgroupsWithLearnedBySystemRow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int32) ([]database.GetTalkgroupsWithLearnedBySystemRow, error)); ok { + return rf(ctx, system) + } + if rf, ok := ret.Get(0).(func(context.Context, int32) []database.GetTalkgroupsWithLearnedBySystemRow); ok { + r0 = rf(ctx, system) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GetTalkgroupsWithLearnedBySystemRow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { + r1 = rf(ctx, system) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetTalkgroupsWithLearnedBySystem_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTalkgroupsWithLearnedBySystem' +type Store_GetTalkgroupsWithLearnedBySystem_Call struct { + *mock.Call +} + +// GetTalkgroupsWithLearnedBySystem is a helper method to define mock.On call +// - ctx context.Context +// - system int32 +func (_e *Store_Expecter) GetTalkgroupsWithLearnedBySystem(ctx interface{}, system interface{}) *Store_GetTalkgroupsWithLearnedBySystem_Call { + return &Store_GetTalkgroupsWithLearnedBySystem_Call{Call: _e.mock.On("GetTalkgroupsWithLearnedBySystem", ctx, system)} +} + +func (_c *Store_GetTalkgroupsWithLearnedBySystem_Call) Run(run func(ctx context.Context, system int32)) *Store_GetTalkgroupsWithLearnedBySystem_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32)) + }) + return _c +} + +func (_c *Store_GetTalkgroupsWithLearnedBySystem_Call) Return(_a0 []database.GetTalkgroupsWithLearnedBySystemRow, _a1 error) *Store_GetTalkgroupsWithLearnedBySystem_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetTalkgroupsWithLearnedBySystem_Call) RunAndReturn(run func(context.Context, int32) ([]database.GetTalkgroupsWithLearnedBySystemRow, error)) *Store_GetTalkgroupsWithLearnedBySystem_Call { + _c.Call.Return(run) + return _c +} + +// GetUserByID provides a mock function with given fields: ctx, id +func (_m *Store) GetUserByID(ctx context.Context, id int32) (database.User, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetUserByID") + } + + var r0 database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(database.User) + } + + if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetUserByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByID' +type Store_GetUserByID_Call struct { + *mock.Call +} + +// GetUserByID is a helper method to define mock.On call +// - ctx context.Context +// - id int32 +func (_e *Store_Expecter) GetUserByID(ctx interface{}, id interface{}) *Store_GetUserByID_Call { + return &Store_GetUserByID_Call{Call: _e.mock.On("GetUserByID", ctx, id)} +} + +func (_c *Store_GetUserByID_Call) Run(run func(ctx context.Context, id int32)) *Store_GetUserByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32)) + }) + return _c +} + +func (_c *Store_GetUserByID_Call) Return(_a0 database.User, _a1 error) *Store_GetUserByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetUserByID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *Store_GetUserByID_Call { + _c.Call.Return(run) + return _c +} + +// GetUserByUID provides a mock function with given fields: ctx, id +func (_m *Store) GetUserByUID(ctx context.Context, id int32) (database.User, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetUserByUID") + } + + var r0 database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(database.User) + } + + if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetUserByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByUID' +type Store_GetUserByUID_Call struct { + *mock.Call +} + +// GetUserByUID is a helper method to define mock.On call +// - ctx context.Context +// - id int32 +func (_e *Store_Expecter) GetUserByUID(ctx interface{}, id interface{}) *Store_GetUserByUID_Call { + return &Store_GetUserByUID_Call{Call: _e.mock.On("GetUserByUID", ctx, id)} +} + +func (_c *Store_GetUserByUID_Call) Run(run func(ctx context.Context, id int32)) *Store_GetUserByUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int32)) + }) + return _c +} + +func (_c *Store_GetUserByUID_Call) Return(_a0 database.User, _a1 error) *Store_GetUserByUID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetUserByUID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *Store_GetUserByUID_Call { + _c.Call.Return(run) + return _c +} + +// GetUserByUsername provides a mock function with given fields: ctx, username +func (_m *Store) GetUserByUsername(ctx context.Context, username string) (database.User, error) { + ret := _m.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for GetUserByUsername") + } + + var r0 database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.User, error)); ok { + return rf(ctx, username) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.User); ok { + r0 = rf(ctx, username) + } else { + r0 = ret.Get(0).(database.User) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetUserByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByUsername' +type Store_GetUserByUsername_Call struct { + *mock.Call +} + +// GetUserByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *Store_Expecter) GetUserByUsername(ctx interface{}, username interface{}) *Store_GetUserByUsername_Call { + return &Store_GetUserByUsername_Call{Call: _e.mock.On("GetUserByUsername", ctx, username)} +} + +func (_c *Store_GetUserByUsername_Call) Run(run func(ctx context.Context, username string)) *Store_GetUserByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Store_GetUserByUsername_Call) Return(_a0 database.User, _a1 error) *Store_GetUserByUsername_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetUserByUsername_Call) RunAndReturn(run func(context.Context, string) (database.User, error)) *Store_GetUserByUsername_Call { + _c.Call.Return(run) + return _c +} + +// GetUsers provides a mock function with given fields: ctx +func (_m *Store) GetUsers(ctx context.Context) ([]database.User, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetUsers") + } + + var r0 []database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.User, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.User); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_GetUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUsers' +type Store_GetUsers_Call struct { + *mock.Call +} + +// GetUsers is a helper method to define mock.On call +// - ctx context.Context +func (_e *Store_Expecter) GetUsers(ctx interface{}) *Store_GetUsers_Call { + return &Store_GetUsers_Call{Call: _e.mock.On("GetUsers", ctx)} +} + +func (_c *Store_GetUsers_Call) Run(run func(ctx context.Context)) *Store_GetUsers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *Store_GetUsers_Call) Return(_a0 []database.User, _a1 error) *Store_GetUsers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_GetUsers_Call) RunAndReturn(run func(context.Context) ([]database.User, error)) *Store_GetUsers_Call { + _c.Call.Return(run) + return _c +} + +// InTx provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Store) InTx(_a0 context.Context, _a1 func(database.Store) error, _a2 pgx.TxOptions) error { + ret := _m.Called(_a0, _a1, _a2) + + if len(ret) == 0 { + panic("no return value specified for InTx") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, func(database.Store) error, pgx.TxOptions) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_InTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InTx' +type Store_InTx_Call struct { + *mock.Call +} + +// InTx is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 func(database.Store) error +// - _a2 pgx.TxOptions +func (_e *Store_Expecter) InTx(_a0 interface{}, _a1 interface{}, _a2 interface{}) *Store_InTx_Call { + return &Store_InTx_Call{Call: _e.mock.On("InTx", _a0, _a1, _a2)} +} + +func (_c *Store_InTx_Call) Run(run func(_a0 context.Context, _a1 func(database.Store) error, _a2 pgx.TxOptions)) *Store_InTx_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(func(database.Store) error), args[2].(pgx.TxOptions)) + }) + return _c +} + +func (_c *Store_InTx_Call) Return(_a0 error) *Store_InTx_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_InTx_Call) RunAndReturn(run func(context.Context, func(database.Store) error, pgx.TxOptions) error) *Store_InTx_Call { + _c.Call.Return(run) + return _c +} + +// SetCallTranscript provides a mock function with given fields: ctx, iD, transcript +func (_m *Store) SetCallTranscript(ctx context.Context, iD uuid.UUID, transcript *string) error { + ret := _m.Called(ctx, iD, transcript) + + if len(ret) == 0 { + panic("no return value specified for SetCallTranscript") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uuid.UUID, *string) error); ok { + r0 = rf(ctx, iD, transcript) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_SetCallTranscript_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetCallTranscript' +type Store_SetCallTranscript_Call struct { + *mock.Call +} + +// SetCallTranscript is a helper method to define mock.On call +// - ctx context.Context +// - iD uuid.UUID +// - transcript *string +func (_e *Store_Expecter) SetCallTranscript(ctx interface{}, iD interface{}, transcript interface{}) *Store_SetCallTranscript_Call { + return &Store_SetCallTranscript_Call{Call: _e.mock.On("SetCallTranscript", ctx, iD, transcript)} +} + +func (_c *Store_SetCallTranscript_Call) Run(run func(ctx context.Context, iD uuid.UUID, transcript *string)) *Store_SetCallTranscript_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uuid.UUID), args[2].(*string)) + }) + return _c +} + +func (_c *Store_SetCallTranscript_Call) Return(_a0 error) *Store_SetCallTranscript_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_SetCallTranscript_Call) RunAndReturn(run func(context.Context, uuid.UUID, *string) error) *Store_SetCallTranscript_Call { + _c.Call.Return(run) + return _c +} + +// SetTalkgroupTags provides a mock function with given fields: ctx, tags, systemID, tGID +func (_m *Store) SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tGID int32) error { + ret := _m.Called(ctx, tags, systemID, tGID) + + if len(ret) == 0 { + panic("no return value specified for SetTalkgroupTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []string, int32, int32) error); ok { + r0 = rf(ctx, tags, systemID, tGID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_SetTalkgroupTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetTalkgroupTags' +type Store_SetTalkgroupTags_Call struct { + *mock.Call +} + +// SetTalkgroupTags is a helper method to define mock.On call +// - ctx context.Context +// - tags []string +// - systemID int32 +// - tGID int32 +func (_e *Store_Expecter) SetTalkgroupTags(ctx interface{}, tags interface{}, systemID interface{}, tGID interface{}) *Store_SetTalkgroupTags_Call { + return &Store_SetTalkgroupTags_Call{Call: _e.mock.On("SetTalkgroupTags", ctx, tags, systemID, tGID)} +} + +func (_c *Store_SetTalkgroupTags_Call) Run(run func(ctx context.Context, tags []string, systemID int32, tGID int32)) *Store_SetTalkgroupTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string), args[2].(int32), args[3].(int32)) + }) + return _c +} + +func (_c *Store_SetTalkgroupTags_Call) Return(_a0 error) *Store_SetTalkgroupTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_SetTalkgroupTags_Call) RunAndReturn(run func(context.Context, []string, int32, int32) error) *Store_SetTalkgroupTags_Call { + _c.Call.Return(run) + return _c +} + +// UpdatePassword provides a mock function with given fields: ctx, username, password +func (_m *Store) UpdatePassword(ctx context.Context, username string, password string) error { + ret := _m.Called(ctx, username, password) + + if len(ret) == 0 { + panic("no return value specified for UpdatePassword") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, username, password) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Store_UpdatePassword_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdatePassword' +type Store_UpdatePassword_Call struct { + *mock.Call +} + +// UpdatePassword is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - password string +func (_e *Store_Expecter) UpdatePassword(ctx interface{}, username interface{}, password interface{}) *Store_UpdatePassword_Call { + return &Store_UpdatePassword_Call{Call: _e.mock.On("UpdatePassword", ctx, username, password)} +} + +func (_c *Store_UpdatePassword_Call) Run(run func(ctx context.Context, username string, password string)) *Store_UpdatePassword_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Store_UpdatePassword_Call) Return(_a0 error) *Store_UpdatePassword_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Store_UpdatePassword_Call) RunAndReturn(run func(context.Context, string, string) error) *Store_UpdatePassword_Call { + _c.Call.Return(run) + return _c +} + +// UpdateTalkgroup provides a mock function with given fields: ctx, arg +func (_m *Store) UpdateTalkgroup(ctx context.Context, arg database.UpdateTalkgroupParams) (database.Talkgroup, error) { + ret := _m.Called(ctx, arg) + + if len(ret) == 0 { + panic("no return value specified for UpdateTalkgroup") + } + + var r0 database.Talkgroup + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.UpdateTalkgroupParams) (database.Talkgroup, error)); ok { + return rf(ctx, arg) + } + if rf, ok := ret.Get(0).(func(context.Context, database.UpdateTalkgroupParams) database.Talkgroup); ok { + r0 = rf(ctx, arg) + } else { + r0 = ret.Get(0).(database.Talkgroup) + } + + if rf, ok := ret.Get(1).(func(context.Context, database.UpdateTalkgroupParams) error); ok { + r1 = rf(ctx, arg) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Store_UpdateTalkgroup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateTalkgroup' +type Store_UpdateTalkgroup_Call struct { + *mock.Call +} + +// UpdateTalkgroup is a helper method to define mock.On call +// - ctx context.Context +// - arg database.UpdateTalkgroupParams +func (_e *Store_Expecter) UpdateTalkgroup(ctx interface{}, arg interface{}) *Store_UpdateTalkgroup_Call { + return &Store_UpdateTalkgroup_Call{Call: _e.mock.On("UpdateTalkgroup", ctx, arg)} +} + +func (_c *Store_UpdateTalkgroup_Call) Run(run func(ctx context.Context, arg database.UpdateTalkgroupParams)) *Store_UpdateTalkgroup_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.UpdateTalkgroupParams)) + }) + return _c +} + +func (_c *Store_UpdateTalkgroup_Call) Return(_a0 database.Talkgroup, _a1 error) *Store_UpdateTalkgroup_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Store_UpdateTalkgroup_Call) RunAndReturn(run func(context.Context, database.UpdateTalkgroupParams) (database.Talkgroup, error)) *Store_UpdateTalkgroup_Call { + _c.Call.Return(run) + return _c +} + +// NewStore creates a new instance of Store. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStore(t interface { + mock.TestingT + Cleanup(func()) +}) *Store { + mock := &Store{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/database/models.go b/pkg/database/models.go index bd113fb..987df9c 100644 --- a/pkg/database/models.go +++ b/pkg/database/models.go @@ -14,7 +14,7 @@ import ( ) type Alert struct { - ID uuid.UUID `json:"id"` + ID int `json:"id"` Time pgtype.Timestamptz `json:"time"` TGID int `json:"tgid"` SystemID int `json:"system_id"` @@ -48,9 +48,9 @@ type Call struct { Frequency int `json:"frequency"` Frequencies []int `json:"frequencies"` Patches []int `json:"patches"` - TgLabel *string `json:"tg_label"` - TgAlphaTag *string `json:"tg_alpha_tag"` - TgGroup *string `json:"tg_group"` + TGLabel *string `json:"tg_label"` + TGAlphaTag *string `json:"tg_alpha_tag"` + TGGroup *string `json:"tg_group"` Source int `json:"source"` Transcript *string `json:"transcript"` } @@ -83,27 +83,29 @@ type System struct { } type Talkgroup struct { - ID uuid.UUID `json:"id"` + ID int `json:"id"` SystemID int32 `json:"system_id"` TGID int32 `json:"tgid"` Name *string `json:"name"` AlphaTag *string `json:"alpha_tag"` - TgGroup *string `json:"tg_group"` + TGGroup *string `json:"tg_group"` Frequency *int32 `json:"frequency"` Metadata jsontypes.Metadata `json:"metadata"` Tags []string `json:"tags"` Alert bool `json:"alert"` AlertConfig rules.AlertRules `json:"alert_config"` Weight float32 `json:"weight"` + Learned bool `json:"learned"` } type TalkgroupsLearned struct { - ID uuid.UUID `json:"id"` - SystemID int `json:"system_id"` - TGID int `json:"tgid"` - Name string `json:"name"` - AlphaTag *string `json:"alpha_tag"` - Ignored *bool `json:"ignored"` + ID int `json:"id"` + SystemID int `json:"system_id"` + TGID int `json:"tgid"` + Name string `json:"name"` + AlphaTag *string `json:"alpha_tag"` + TGGroup *string `json:"tg_group"` + Ignored *bool `json:"ignored"` } type User struct { diff --git a/pkg/database/querier.go b/pkg/database/querier.go index cd63b24..d1358a4 100644 --- a/pkg/database/querier.go +++ b/pkg/database/querier.go @@ -14,6 +14,8 @@ import ( type Querier interface { AddAlert(ctx context.Context, arg AddAlertParams) error AddCall(ctx context.Context, arg AddCallParams) error + AddLearnedTalkgroup(ctx context.Context, arg AddLearnedTalkgroupParams) (int, error) + AddTalkgroupWithLearnedFlag(ctx context.Context, systemID int32, tGID int32) error CreateAPIKey(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool) (ApiKey, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) DeleteAPIKey(ctx context.Context, apiKey string) error @@ -21,9 +23,9 @@ type Querier interface { GetAPIKey(ctx context.Context, apiKey string) (ApiKey, error) GetDatabaseSize(ctx context.Context) (string, error) GetSystemName(ctx context.Context, systemID int) (string, error) - GetTalkgroup(ctx context.Context, systemID int32, tgID int32) (GetTalkgroupRow, error) + GetTalkgroup(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupRow, error) GetTalkgroupIDsByTags(ctx context.Context, anyTags []string, allTags []string, notTags []string) ([]GetTalkgroupIDsByTagsRow, error) - GetTalkgroupTags(ctx context.Context, systemID int32, tgID int32) ([]string, error) + GetTalkgroupTags(ctx context.Context, systemID int32, tGID int32) ([]string, error) GetTalkgroupWithLearned(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupWithLearnedRow, error) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAllTagsRow, error) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAnyTagsRow, error) @@ -34,7 +36,7 @@ type Querier interface { GetUserByUsername(ctx context.Context, username string) (User, error) GetUsers(ctx context.Context) ([]User, error) SetCallTranscript(ctx context.Context, iD uuid.UUID, transcript *string) error - SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tgID int32) error + SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tGID int32) error UpdatePassword(ctx context.Context, username string, password string) error UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams) (Talkgroup, error) } diff --git a/pkg/database/talkgroups.go b/pkg/database/talkgroups.go index 276b0d8..d3bae6a 100644 --- a/pkg/database/talkgroups.go +++ b/pkg/database/talkgroups.go @@ -2,6 +2,9 @@ package database import ( "context" + "errors" + + "github.com/jackc/pgx/v5/pgconn" ) type talkgroupQuerier interface { @@ -12,6 +15,17 @@ type talkgroupQuerier interface { type TGTuples [2][]uint32 +const TGConstraintName = "" + +func IsTGConstraintViolation(e error) bool { + var err *pgconn.PgError + if errors.As(e, &err) && err.Code == "23503" && err.ConstraintName == TGConstraintName { + return true + } + + return false +} + func MakeTGTuples(cap int) TGTuples { return [2][]uint32{ make([]uint32, 0, cap), @@ -27,11 +41,11 @@ func (t *TGTuples) Append(sys, tg uint32) { // Below queries are here because sqlc refuses to parse unnest(x, y) const getTalkgroupsWithLearnedBySysTGID = `SELECT -tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name, -FALSE learned +tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name, tg.learned FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg) +WHERE tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -46,7 +60,6 @@ JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tgl.system_id = tgt.sys type GetTalkgroupsRow struct { Talkgroup Talkgroup `json:"talkgroup"` System System `json:"system"` - Learned bool `json:"learned"` } func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGTuples) ([]GetTalkgroupsRow, error) { @@ -64,7 +77,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, @@ -73,7 +86,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT &i.Talkgroup.Weight, &i.System.ID, &i.System.Name, - &i.Learned, + &i.Talkgroup.Learned, ); err != nil { return nil, err } @@ -87,7 +100,8 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT const getTalkgroupsBySysTGID = `SELECT tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id -JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg);` +JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg) +WHERE tg.learned IS NOT TRUE;` func (q *Queries) GetTalkgroupsBySysTGID(ctx context.Context, ids TGTuples) ([]GetTalkgroupsRow, error) { rows, err := q.db.Query(ctx, getTalkgroupsBySysTGID, ids[0], ids[1]) @@ -104,7 +118,7 @@ func (q *Queries) GetTalkgroupsBySysTGID(ctx context.Context, ids TGTuples) ([]G &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, diff --git a/pkg/database/talkgroups.sql.go b/pkg/database/talkgroups.sql.go index a369ff2..3780a64 100644 --- a/pkg/database/talkgroups.sql.go +++ b/pkg/database/talkgroups.sql.go @@ -10,9 +10,62 @@ import ( "dynatron.me/x/stillbox/internal/jsontypes" "dynatron.me/x/stillbox/pkg/alerting/rules" - "github.com/jackc/pgx/v5/pgtype" ) +const addLearnedTalkgroup = `-- name: AddLearnedTalkgroup :one +INSERT INTO talkgroups_learned( + system_id, + tgid, + name, + alpha_tag, + tg_group +) VALUES ( + $1, + $2, + $3, + $4, + $5 +) RETURNING id +` + +type AddLearnedTalkgroupParams struct { + SystemID int `json:"system_id"` + TGID int `json:"tgid"` + Name *string `json:"name"` + AlphaTag *string `json:"alpha_tag"` + TGGroup *string `json:"tg_group"` +} + +func (q *Queries) AddLearnedTalkgroup(ctx context.Context, arg AddLearnedTalkgroupParams) (int, error) { + row := q.db.QueryRow(ctx, addLearnedTalkgroup, + arg.SystemID, + arg.TGID, + arg.Name, + arg.AlphaTag, + arg.TGGroup, + ) + var id int + err := row.Scan(&id) + return id, err +} + +const addTalkgroupWithLearnedFlag = `-- name: AddTalkgroupWithLearnedFlag :exec +INSERT INTO talkgroups ( + system_id, + tgid, + learned +) VALUES( + $1, + $2, + 't' +) +` + +func (q *Queries) AddTalkgroupWithLearnedFlag(ctx context.Context, systemID int32, tGID int32) error { + _, err := q.db.Exec(ctx, addTalkgroupWithLearnedFlag, systemID, tGID) + return err +} + const getSystemName = `-- name: GetSystemName :one SELECT name FROM systems WHERE id = $1 ` @@ -25,7 +78,7 @@ func (q *Queries) GetSystemName(ctx context.Context, systemID int) (string, erro } const getTalkgroup = `-- name: GetTalkgroup :one -SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight FROM talkgroups +SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned FROM talkgroups WHERE (system_id, tgid) = ($1, $2) ` @@ -33,8 +86,8 @@ type GetTalkgroupRow struct { Talkgroup Talkgroup `json:"talkgroup"` } -func (q *Queries) GetTalkgroup(ctx context.Context, systemID int32, tgID int32) (GetTalkgroupRow, error) { - row := q.db.QueryRow(ctx, getTalkgroup, systemID, tgID) +func (q *Queries) GetTalkgroup(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupRow, error) { + row := q.db.QueryRow(ctx, getTalkgroup, systemID, tGID) var i GetTalkgroupRow err := row.Scan( &i.Talkgroup.ID, @@ -42,13 +95,14 @@ func (q *Queries) GetTalkgroup(ctx context.Context, systemID int32, tgID int32) &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, &i.Talkgroup.Alert, &i.Talkgroup.AlertConfig, &i.Talkgroup.Weight, + &i.Talkgroup.Learned, ) return i, err } @@ -90,8 +144,8 @@ SELECT tags FROM talkgroups WHERE system_id = $1 AND tgid = $2 ` -func (q *Queries) GetTalkgroupTags(ctx context.Context, systemID int32, tgID int32) ([]string, error) { - row := q.db.QueryRow(ctx, getTalkgroupTags, systemID, tgID) +func (q *Queries) GetTalkgroupTags(ctx context.Context, systemID int32, tGID int32) ([]string, error) { + row := q.db.QueryRow(ctx, getTalkgroupTags, systemID, tGID) var tags []string err := row.Scan(&tags) return tags, err @@ -99,11 +153,10 @@ func (q *Queries) GetTalkgroupTags(ctx context.Context, systemID int32, tgID int const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one SELECT -tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name, -FALSE learned +tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, sys.id, sys.name FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id -WHERE (tg.system_id, tg.tgid) = ($1, $2) +WHERE (tg.system_id, tg.tgid) = ($1, $2) AND tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -119,7 +172,6 @@ WHERE tgl.system_id = $1 AND tgl.tgid = $2 AND ignored IS NOT TRUE type GetTalkgroupWithLearnedRow struct { Talkgroup Talkgroup `json:"talkgroup"` System System `json:"system"` - Learned bool `json:"learned"` } func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupWithLearnedRow, error) { @@ -131,22 +183,22 @@ func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int32, t &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, &i.Talkgroup.Alert, &i.Talkgroup.AlertConfig, &i.Talkgroup.Weight, + &i.Talkgroup.Learned, &i.System.ID, &i.System.Name, - &i.Learned, ) return i, err } const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many -SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight FROM talkgroups +SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned FROM talkgroups WHERE tags && ARRAY[$1] ` @@ -169,13 +221,14 @@ func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ( &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, &i.Talkgroup.Alert, &i.Talkgroup.AlertConfig, &i.Talkgroup.Weight, + &i.Talkgroup.Learned, ); err != nil { return nil, err } @@ -188,7 +241,7 @@ func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ( } const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many -SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight FROM talkgroups +SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned FROM talkgroups WHERE tags @> ARRAY[$1] ` @@ -211,13 +264,14 @@ func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ( &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, &i.Talkgroup.Alert, &i.Talkgroup.AlertConfig, &i.Talkgroup.Weight, + &i.Talkgroup.Learned, ); err != nil { return nil, err } @@ -231,10 +285,10 @@ func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ( const getTalkgroupsWithLearned = `-- name: GetTalkgroupsWithLearned :many SELECT -tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name, -FALSE learned +tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, sys.id, sys.name FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id +WHERE tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -250,7 +304,6 @@ WHERE ignored IS NOT TRUE type GetTalkgroupsWithLearnedRow struct { Talkgroup Talkgroup `json:"talkgroup"` System System `json:"system"` - Learned bool `json:"learned"` } func (q *Queries) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroupsWithLearnedRow, error) { @@ -268,16 +321,16 @@ func (q *Queries) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroups &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, &i.Talkgroup.Alert, &i.Talkgroup.AlertConfig, &i.Talkgroup.Weight, + &i.Talkgroup.Learned, &i.System.ID, &i.System.Name, - &i.Learned, ); err != nil { return nil, err } @@ -291,11 +344,10 @@ func (q *Queries) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroups const getTalkgroupsWithLearnedBySystem = `-- name: GetTalkgroupsWithLearnedBySystem :many SELECT -tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name, -FALSE learned +tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, sys.id, sys.name FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id -WHERE tg.system_id = $1 +WHERE tg.system_id = $1 AND tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -311,7 +363,6 @@ WHERE tgl.system_id = $1 AND ignored IS NOT TRUE type GetTalkgroupsWithLearnedBySystemRow struct { Talkgroup Talkgroup `json:"talkgroup"` System System `json:"system"` - Learned bool `json:"learned"` } func (q *Queries) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]GetTalkgroupsWithLearnedBySystemRow, error) { @@ -329,16 +380,16 @@ func (q *Queries) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system i &i.Talkgroup.TGID, &i.Talkgroup.Name, &i.Talkgroup.AlphaTag, - &i.Talkgroup.TgGroup, + &i.Talkgroup.TGGroup, &i.Talkgroup.Frequency, &i.Talkgroup.Metadata, &i.Talkgroup.Tags, &i.Talkgroup.Alert, &i.Talkgroup.AlertConfig, &i.Talkgroup.Weight, + &i.Talkgroup.Learned, &i.System.ID, &i.System.Name, - &i.Learned, ); err != nil { return nil, err } @@ -355,8 +406,8 @@ UPDATE talkgroups SET tags = $1 WHERE system_id = $2 AND tgid = $3 ` -func (q *Queries) SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tgID int32) error { - _, err := q.db.Exec(ctx, setTalkgroupTags, tags, systemID, tgID) +func (q *Queries) SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tGID int32) error { + _, err := q.db.Exec(ctx, setTalkgroupTags, tags, systemID, tGID) return err } @@ -373,20 +424,20 @@ SET alert_config = COALESCE($8, alert_config), weight = COALESCE($9, weight) WHERE id = $10 OR (system_id = $11 AND tgid = $12) -RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight +RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned ` type UpdateTalkgroupParams struct { Name *string `json:"name"` AlphaTag *string `json:"alpha_tag"` - TgGroup *string `json:"tg_group"` + TGGroup *string `json:"tg_group"` Frequency *int32 `json:"frequency"` Metadata jsontypes.Metadata `json:"metadata"` Tags []string `json:"tags"` Alert *bool `json:"alert"` AlertConfig rules.AlertRules `json:"alert_config"` Weight *float32 `json:"weight"` - ID pgtype.UUID `json:"id"` + ID *int32 `json:"id"` SystemID *int32 `json:"system_id"` TGID *int32 `json:"tgid"` } @@ -395,7 +446,7 @@ func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams row := q.db.QueryRow(ctx, updateTalkgroup, arg.Name, arg.AlphaTag, - arg.TgGroup, + arg.TGGroup, arg.Frequency, arg.Metadata, arg.Tags, @@ -413,13 +464,14 @@ func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams &i.TGID, &i.Name, &i.AlphaTag, - &i.TgGroup, + &i.TGGroup, &i.Frequency, &i.Metadata, &i.Tags, &i.Alert, &i.AlertConfig, &i.Weight, + &i.Learned, ) return i, err } diff --git a/pkg/nexus/commands.go b/pkg/nexus/commands.go index 502859a..4c4bcaa 100644 --- a/pkg/nexus/commands.go +++ b/pkg/nexus/commands.go @@ -78,7 +78,7 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error { resp := &pb.TalkgroupInfo{ Tg: tg, Name: tgi.Talkgroup.Name, - Group: tgi.Talkgroup.TgGroup, + Group: tgi.Talkgroup.TGGroup, Frequency: tgi.Talkgroup.Frequency, Metadata: md, Tags: tgi.Talkgroup.Tags, diff --git a/pkg/server/server.go b/pkg/server/server.go index 4357d12..b26cc34 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -27,7 +27,7 @@ const shutdownTimeout = 5 * time.Second type Server struct { auth *auth.Auth conf *config.Config - db database.DB + db database.Store r *chi.Mux sources sources.Sources sinks sinks.Sinks @@ -78,7 +78,7 @@ func New(ctx context.Context, cfg *config.Config) (*Server, error) { rest: api, } - srv.sinks.Register("database", sinks.NewDatabaseSink(srv.db), true) + srv.sinks.Register("database", sinks.NewDatabaseSink(), true) srv.sinks.Register("nexus", sinks.NewNexusSink(srv.nex), false) if srv.alerter.Enabled() { @@ -112,7 +112,7 @@ func New(ctx context.Context, cfg *config.Config) (*Server, error) { } func (s *Server) Go(ctx context.Context) error { - defer s.db.DB().Close() + defer database.Close(s.db) s.installHupHandler() diff --git a/pkg/sinks/database.go b/pkg/sinks/database.go index fa557cc..f0a8674 100644 --- a/pkg/sinks/database.go +++ b/pkg/sinks/database.go @@ -8,16 +8,16 @@ import ( "dynatron.me/x/stillbox/pkg/calls" "dynatron.me/x/stillbox/pkg/database" + "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" "github.com/rs/zerolog/log" ) type DatabaseSink struct { - db database.DB } -func NewDatabaseSink(db database.DB) *DatabaseSink { - return &DatabaseSink{db: db} +func NewDatabaseSink() *DatabaseSink { + return &DatabaseSink{} } func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error { @@ -26,14 +26,28 @@ func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error { return nil } - err := s.db.AddCall(ctx, s.toAddCallParams(call)) - if err != nil { - return fmt.Errorf("add call: %w", err) - } + return database.FromCtx(ctx).InTx(ctx, func(tx database.Store) error { + params := s.toAddCallParams(call) + err := tx.AddCall(ctx, params) + if err != nil { + if database.IsTGConstraintViolation(err) { + _, err := call.LearnTG(ctx, tx) + if err != nil { + return fmt.Errorf("add call: learn tg: %w", err) + } - log.Debug().Str("id", call.ID.String()).Int("system", call.System).Int("tgid", call.Talkgroup).Msg("stored") + err = tx.AddCall(ctx, params) + if err != nil { + return fmt.Errorf("add call: retry: %w", err) + } + } + return fmt.Errorf("add call: %w", err) + } - return nil + log.Debug().Str("id", call.ID.String()).Int("system", call.System).Int("tgid", call.Talkgroup).Msg("stored") + + return nil + }, pgx.TxOptions{}) } func (s *DatabaseSink) SinkType() string { @@ -54,9 +68,9 @@ func (s *DatabaseSink) toAddCallParams(call *calls.Call) database.AddCallParams Frequency: call.Frequency, Frequencies: call.Frequencies, Patches: call.Patches, - TgLabel: call.TalkgroupLabel, - TgAlphaTag: call.TGAlphaTag, - TgGroup: call.TalkgroupGroup, + TGLabel: call.TalkgroupLabel, + TGAlphaTag: call.TGAlphaTag, + TGGroup: call.TalkgroupGroup, Source: call.Source, } } diff --git a/pkg/talkgroups/importer/import.go b/pkg/talkgroups/importer/import.go index 82730fe..b616a3b 100644 --- a/pkg/talkgroups/importer/import.go +++ b/pkg/talkgroups/importer/import.go @@ -10,8 +10,6 @@ import ( "strconv" "strings" - "github.com/google/uuid" - "dynatron.me/x/stillbox/internal/jsontypes" "dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/talkgroups" @@ -112,12 +110,11 @@ func (rr *radioReferenceImporter) importTalkgroups(ctx context.Context, sys int, gn := groupName // must take a copy tgs = append(tgs, talkgroups.Talkgroup{ Talkgroup: database.Talkgroup{ - ID: uuid.New(), TGID: int32(tgt.Talkgroup), SystemID: int32(tgt.System), Name: &fields[4], AlphaTag: &fields[3], - TgGroup: &gn, + TGGroup: &gn, Metadata: metadata, Tags: tags, Weight: 1.0, diff --git a/sql/postgres/migrations/001_initial.up.sql b/sql/postgres/migrations/001_initial.up.sql index cd37bc9..ff926bf 100644 --- a/sql/postgres/migrations/001_initial.up.sql +++ b/sql/postgres/migrations/001_initial.up.sql @@ -49,6 +49,7 @@ CREATE TABLE IF NOT EXISTS talkgroups_learned( tgid INTEGER NOT NULL, name TEXT NOT NULL, alpha_tag TEXT, + tg_group TEXT, ignored BOOLEAN, UNIQUE (system_id, tgid, name) ); @@ -65,22 +66,6 @@ CREATE TABLE IF NOT EXISTS alerts( metadata JSONB ); -CREATE OR REPLACE FUNCTION learn_talkgroup() -RETURNS TRIGGER AS $$ -BEGIN - IF NOT EXISTS ( - SELECT tg.system_id, tg.tgid, tg.name, tg.alpha_tag FROM talkgroups tg WHERE tg.system_id = NEW.system AND tg.tgid = NEW.talkgroup - UNION - SELECT tgl.system_id, tgl.tgid, tgl.name, tgl.alpha_tag FROM talkgroups_learned tgl WHERE tgl.system_id = NEW.system AND tgl.tgid = NEW.talkgroup - ) THEN - INSERT INTO talkgroups_learned(system_id, tgid, name, alpha_tag) VALUES( - NEW.system, NEW.talkgroup, NEW.tg_label, NEW.tg_alpha_tag - ) ON CONFLICT DO NOTHING; - END IF; - RETURN NEW; -END -$$ LANGUAGE plpgsql; - CREATE TABLE IF NOT EXISTS calls( id UUID PRIMARY KEY, submitter INTEGER REFERENCES api_keys(id) ON DELETE SET NULL, @@ -102,9 +87,6 @@ CREATE TABLE IF NOT EXISTS calls( transcript TEXT ); -CREATE OR REPLACE TRIGGER learn_tg AFTER INSERT ON calls -FOR EACH ROW EXECUTE FUNCTION learn_talkgroup(); - CREATE INDEX IF NOT EXISTS calls_transcript_idx ON calls USING GIN (to_tsvector('english', transcript)); CREATE INDEX IF NOT EXISTS calls_call_date_tg_idx ON calls(system, talkgroup, call_date); diff --git a/sql/postgres/migrations/002_tglearned.down.sql b/sql/postgres/migrations/002_tglearned.down.sql new file mode 100644 index 0000000..846075d --- /dev/null +++ b/sql/postgres/migrations/002_tglearned.down.sql @@ -0,0 +1,34 @@ +ALTER TABLE calls DROP CONSTRAINT IF EXISTS calls_talkgroup_id_fkey; + +ALTER TABLE talkgroups ALTER COLUMN id DROP IDENTITY IF EXISTS; +ALTER TABLE talkgroups_learned ALTER COLUMN id SET DATA TYPE UUID USING (gen_random_uuid()); +DROP SEQUENCE IF EXISTS talkgroups_id_seq; + +ALTER TABLE talkgroups DROP COLUMN IF EXISTS learned; + +CREATE OR REPLACE FUNCTION learn_talkgroup() +RETURNS TRIGGER AS $$ +BEGIN + IF NOT EXISTS ( + SELECT tg.system_id, tg.tgid, tg.name, tg.alpha_tag FROM talkgroups tg WHERE tg.system_id = NEW.system AND tg.tgid = NEW.talkgroup + UNION + SELECT tgl.system_id, tgl.tgid, tgl.name, tgl.alpha_tag FROM talkgroups_learned tgl WHERE tgl.system_id = NEW.system AND tgl.tgid = NEW.talkgroup + ) THEN + INSERT INTO talkgroups_learned(system_id, tgid, name, alpha_tag) VALUES( + NEW.system, NEW.talkgroup, NEW.tg_label, NEW.tg_alpha_tag + ) ON CONFLICT DO NOTHING; + END IF; + RETURN NEW; +END +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE TRIGGER learn_tg AFTER INSERT ON calls FOR EACH ROW EXECUTE FUNCTION learn_talkgroup(); + +ALTER TABLE talkgroups_learned ALTER COLUMN id DROP IDENTITY IF EXISTS; +ALTER TABLE talkgroups_learned ALTER COLUMN id SET DATA TYPE UUID USING (gen_random_uuid()); +DROP SEQUENCE IF EXISTS talkgroups_learned_id_seq; + +ALTER TABLE alerts ALTER COLUMN id DROP IDENTITY IF EXISTS; +ALTER TABLE alerts ALTER COLUMN id SET DATA TYPE UUID USING (gen_random_uuid()); +DROP SEQUENCE IF EXISTS alerts_id_seq; + diff --git a/sql/postgres/migrations/002_tglearned.up.sql b/sql/postgres/migrations/002_tglearned.up.sql new file mode 100644 index 0000000..309c0c1 --- /dev/null +++ b/sql/postgres/migrations/002_tglearned.up.sql @@ -0,0 +1,21 @@ +CREATE SEQUENCE IF NOT EXISTS alerts_id_seq START WITH 1; +ALTER TABLE alerts ALTER COLUMN id SET DATA TYPE INTEGER USING (nextval('alerts_id_seq')); +ALTER TABLE alerts ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY; +DROP SEQUENCE IF EXISTS alerts_id_seq; + +CREATE SEQUENCE IF NOT EXISTS talkgroups_learned_id_seq START WITH 1; +ALTER TABLE talkgroups_learned ALTER COLUMN id SET DATA TYPE INTEGER USING (nextval('talkgroups_learned_id_seq')); +ALTER TABLE talkgroups_learned ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY; +DROP SEQUENCE IF EXISTS talkgroup_learned_id_seq; + +DROP TRIGGER IF EXISTS learn_tg ON calls; +DROP FUNCTION IF EXISTS learn_talkgroup(); + +ALTER TABLE talkgroups ADD COLUMN IF NOT EXISTS learned BOOLEAN NOT NULL DEFAULT FALSE; + +CREATE SEQUENCE IF NOT EXISTS talkgroups_id_seq START WITH 1; +ALTER TABLE talkgroups ALTER COLUMN id SET DATA TYPE INTEGER USING (nextval('talkgroups_id_seq')); +ALTER TABLE talkgroups ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY; +DROP SEQUENCE IF EXISTS talkgroups_id_seq; + +ALTER TABLE calls ADD CONSTRAINT calls_talkgroup_id_fkey FOREIGN KEY (system, talkgroup_id) REFERENCES talkgroups(system_id, tgid); diff --git a/sql/postgres/migrations/initial.sql b/sql/postgres/migrations/initial.sql new file mode 100644 index 0000000..1006883 --- /dev/null +++ b/sql/postgres/migrations/initial.sql @@ -0,0 +1,120 @@ +CREATE TABLE IF NOT EXISTS users( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + username VARCHAR (255) UNIQUE NOT NULL, + password TEXT NOT NULL, + email TEXT NOT NULL, + is_admin BOOLEAN NOT NULL, + prefs JSONB +); + +CREATE INDEX IF NOT EXISTS users_username_idx ON users(username); + +CREATE TABLE IF NOT EXISTS api_keys( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + owner INTEGER REFERENCES users(id) NOT NULL, + created_at TIMESTAMP NOT NULL, + expires TIMESTAMP, + disabled BOOLEAN, + api_key TEXT UNIQUE NOT NULL +); + +CREATE TABLE IF NOT EXISTS systems( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL +); + +CREATE TABLE IF NOT EXISTS talkgroups( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + system_id INT4 REFERENCES systems(id) NOT NULL, + tgid INT4 NOT NULL, + name TEXT, + alpha_tag TEXT, + tg_group TEXT, + frequency INTEGER, + metadata JSONB, + tags TEXT[] NOT NULL DEFAULT '{}', + alert BOOLEAN NOT NULL DEFAULT 'true', + alert_config JSONB, + weight REAL NOT NULL DEFAULT 1.0, + learned BOOLEAN, + UNIQUE (system_id, tgid) +); + +CREATE INDEX talkgroups_system_tgid_idx ON talkgroups (system_id, tgid); + +CREATE INDEX IF NOT EXISTS talkgroup_id_tags ON talkgroups USING GIN (tags); + +CREATE TABLE IF NOT EXISTS talkgroups_learned( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + system_id INTEGER REFERENCES systems(id) NOT NULL, + tgid INTEGER NOT NULL, + name TEXT NOT NULL, + alpha_tag TEXT, + tg_group TEXT, + ignored BOOLEAN, + UNIQUE (system_id, tgid, name) +); + +CREATE TABLE IF NOT EXISTS alerts( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + time TIMESTAMPTZ NOT NULL, + tgid INTEGER NOT NULL, + system_id INTEGER REFERENCES systems(id) NOT NULL, + weight REAL, + score REAL, + orig_score REAL, + notified BOOLEAN NOT NULL DEFAULT 'false', + metadata JSONB +); + +CREATE TABLE IF NOT EXISTS calls( + id UUID PRIMARY KEY, + submitter INTEGER REFERENCES api_keys(id) ON DELETE SET NULL, + system INTEGER NOT NULL, + talkgroup INTEGER NOT NULL, + call_date TIMESTAMPTZ NOT NULL, + audio_name TEXT, + audio_blob BYTEA, + duration INTEGER, + audio_type TEXT, + audio_url TEXT, + frequency INTEGER NOT NULL, + frequencies INTEGER[], + patches INTEGER[], + tg_label TEXT, + tg_alpha_tag TEXT, + tg_group TEXT, + source INTEGER NOT NULL, + transcript TEXT +); + +CREATE INDEX IF NOT EXISTS calls_transcript_idx ON calls USING GIN (to_tsvector('english', transcript)); +CREATE INDEX IF NOT EXISTS calls_call_date_tg_idx ON calls(system, talkgroup, call_date); + +CREATE TABLE IF NOT EXISTS settings( + name TEXT PRIMARY KEY, + updated_by INTEGER REFERENCES users(id), + value JSONB +); + +CREATE TABLE IF NOT EXISTS incidents( + id UUID PRIMARY KEY, + name TEXT NOT NULL, + description TEXT, + start_time TIMESTAMP, + end_time TIMESTAMP, + location JSONB, + metadata JSONB +); + +CREATE INDEX IF NOT EXISTS incidents_name_description_idx ON incidents USING GIN ( + (to_tsvector('english', name) || to_tsvector('english', coalesce(description, '')) + ) +); + +CREATE TABLE IF NOT EXISTS incidents_calls( + incident_id UUID REFERENCES incidents(id) ON UPDATE CASCADE ON DELETE CASCADE, + call_id UUID REFERENCES calls(id) ON UPDATE CASCADE, + notes JSONB, + PRIMARY KEY (incident_id, call_id) +); diff --git a/sql/postgres/queries/calls.sql b/sql/postgres/queries/calls.sql index 1cb09fe..5253556 100644 --- a/sql/postgres/queries/calls.sql +++ b/sql/postgres/queries/calls.sql @@ -41,10 +41,9 @@ source UPDATE calls SET transcript = $2 WHERE id = $1; -- name: AddAlert :exec -INSERT INTO alerts (id, time, tgid, system_id, weight, score, orig_score, notified, metadata) +INSERT INTO alerts (time, tgid, system_id, weight, score, orig_score, notified, metadata) VALUES ( - sqlc.arg(id), sqlc.arg(time), sqlc.arg(tgid), sqlc.arg(system_id), diff --git a/sql/postgres/queries/talkgroups.sql b/sql/postgres/queries/talkgroups.sql index 6b58ae8..272757f 100644 --- a/sql/postgres/queries/talkgroups.sql +++ b/sql/postgres/queries/talkgroups.sql @@ -26,11 +26,10 @@ WHERE (system_id, tgid) = (@system_id, @tg_id); -- name: GetTalkgroupWithLearned :one SELECT -sqlc.embed(tg), sqlc.embed(sys), -FALSE learned +sqlc.embed(tg), sqlc.embed(sys) FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id -WHERE (tg.system_id, tg.tgid) = (@system_id, @tgid) +WHERE (tg.system_id, tg.tgid) = (@system_id, @tgid) AND tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -44,11 +43,10 @@ WHERE tgl.system_id = @system_id AND tgl.tgid = @tgid AND ignored IS NOT TRUE; -- name: GetTalkgroupsWithLearnedBySystem :many SELECT -sqlc.embed(tg), sqlc.embed(sys), -FALSE learned +sqlc.embed(tg), sqlc.embed(sys) FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id -WHERE tg.system_id = @system +WHERE tg.system_id = @system AND tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -62,10 +60,10 @@ WHERE tgl.system_id = @system AND ignored IS NOT TRUE; -- name: GetTalkgroupsWithLearned :many SELECT -sqlc.embed(tg), sqlc.embed(sys), -FALSE learned +sqlc.embed(tg), sqlc.embed(sys) FROM talkgroups tg JOIN systems sys ON tg.system_id = sys.id +WHERE tg.learned IS NOT TRUE UNION SELECT tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name, @@ -94,3 +92,29 @@ SET weight = COALESCE(sqlc.narg('weight'), weight) WHERE id = sqlc.narg('id') OR (system_id = sqlc.narg('system_id') AND tgid = sqlc.narg('tgid')) RETURNING *; + +-- name: AddTalkgroupWithLearnedFlag :exec +INSERT INTO talkgroups ( + system_id, + tgid, + learned +) VALUES( + @system_id, + @tgid, + 't' +); + +-- name: AddLearnedTalkgroup :one +INSERT INTO talkgroups_learned( + system_id, + tgid, + name, + alpha_tag, + tg_group +) VALUES ( + @system_id, + @tgid, + sqlc.narg('name'), + sqlc.narg('alpha_tag'), + sqlc.narg('tg_group') +) RETURNING id; diff --git a/sql/sqlc.yaml b/sql/sqlc.yaml index 506170a..4ce8915 100644 --- a/sql/sqlc.yaml +++ b/sql/sqlc.yaml @@ -14,6 +14,7 @@ sql: initialisms: - id - tgid + - tg emit_pointers_for_null_types: true overrides: - db_type: "uuid"