This commit is contained in:
Daniel 2024-11-19 09:10:55 -05:00
parent 7e5a7b6a78
commit d72608bc41
7 changed files with 29 additions and 29 deletions

View file

@ -98,7 +98,7 @@ func (a *Auth) Login(ctx context.Context, username, password string) (token stri
return a.newToken(found.ID), nil return a.newToken(found.ID), nil
} }
func (a *Auth) newToken(uid int32) string { func (a *Auth) newToken(uid int) string {
claims := claims{ claims := claims{
"sub": strconv.Itoa(int(uid)), "sub": strconv.Itoa(int(uid)),
} }
@ -134,7 +134,7 @@ func (a *Auth) routeRefresh(w http.ResponseWriter, r *http.Request) {
return return
} }
tok := a.newToken(int32(uid)) tok := a.newToken(uid)
cookie := &http.Cookie{ cookie := &http.Cookie{
Name: "jwt", Name: "jwt",

View file

@ -1293,7 +1293,7 @@ func (_c *Store_GetTalkgroupsWithLearnedBySystem_Call) RunAndReturn(run func(con
} }
// GetUserByID provides a mock function with given fields: ctx, id // GetUserByID provides a mock function with given fields: ctx, id
func (_m *Store) GetUserByID(ctx context.Context, id int32) (database.User, error) { func (_m *Store) GetUserByID(ctx context.Context, id int) (database.User, error) {
ret := _m.Called(ctx, id) ret := _m.Called(ctx, id)
if len(ret) == 0 { if len(ret) == 0 {
@ -1302,16 +1302,16 @@ func (_m *Store) GetUserByID(ctx context.Context, id int32) (database.User, erro
var r0 database.User var r0 database.User
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, int) (database.User, error)); ok {
return rf(ctx, id) return rf(ctx, id)
} }
if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { if rf, ok := ret.Get(0).(func(context.Context, int) database.User); ok {
r0 = rf(ctx, id) r0 = rf(ctx, id)
} else { } else {
r0 = ret.Get(0).(database.User) r0 = ret.Get(0).(database.User)
} }
if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { if rf, ok := ret.Get(1).(func(context.Context, int) error); ok {
r1 = rf(ctx, id) r1 = rf(ctx, id)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1327,14 +1327,14 @@ type Store_GetUserByID_Call struct {
// GetUserByID is a helper method to define mock.On call // GetUserByID is a helper method to define mock.On call
// - ctx context.Context // - ctx context.Context
// - id int32 // - id int
func (_e *Store_Expecter) GetUserByID(ctx interface{}, id interface{}) *Store_GetUserByID_Call { func (_e *Store_Expecter) GetUserByID(ctx interface{}, id interface{}) *Store_GetUserByID_Call {
return &Store_GetUserByID_Call{Call: _e.mock.On("GetUserByID", ctx, id)} 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 { func (_c *Store_GetUserByID_Call) Run(run func(ctx context.Context, id int)) *Store_GetUserByID_Call {
_c.Call.Run(func(args mock.Arguments) { _c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(int32)) run(args[0].(context.Context), args[1].(int))
}) })
return _c return _c
} }
@ -1344,13 +1344,13 @@ func (_c *Store_GetUserByID_Call) Return(_a0 database.User, _a1 error) *Store_Ge
return _c return _c
} }
func (_c *Store_GetUserByID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *Store_GetUserByID_Call { func (_c *Store_GetUserByID_Call) RunAndReturn(run func(context.Context, int) (database.User, error)) *Store_GetUserByID_Call {
_c.Call.Return(run) _c.Call.Return(run)
return _c return _c
} }
// GetUserByUID provides a mock function with given fields: ctx, id // GetUserByUID provides a mock function with given fields: ctx, id
func (_m *Store) GetUserByUID(ctx context.Context, id int32) (database.User, error) { func (_m *Store) GetUserByUID(ctx context.Context, id int) (database.User, error) {
ret := _m.Called(ctx, id) ret := _m.Called(ctx, id)
if len(ret) == 0 { if len(ret) == 0 {
@ -1359,16 +1359,16 @@ func (_m *Store) GetUserByUID(ctx context.Context, id int32) (database.User, err
var r0 database.User var r0 database.User
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, int) (database.User, error)); ok {
return rf(ctx, id) return rf(ctx, id)
} }
if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { if rf, ok := ret.Get(0).(func(context.Context, int) database.User); ok {
r0 = rf(ctx, id) r0 = rf(ctx, id)
} else { } else {
r0 = ret.Get(0).(database.User) r0 = ret.Get(0).(database.User)
} }
if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { if rf, ok := ret.Get(1).(func(context.Context, int) error); ok {
r1 = rf(ctx, id) r1 = rf(ctx, id)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1384,14 +1384,14 @@ type Store_GetUserByUID_Call struct {
// GetUserByUID is a helper method to define mock.On call // GetUserByUID is a helper method to define mock.On call
// - ctx context.Context // - ctx context.Context
// - id int32 // - id int
func (_e *Store_Expecter) GetUserByUID(ctx interface{}, id interface{}) *Store_GetUserByUID_Call { func (_e *Store_Expecter) GetUserByUID(ctx interface{}, id interface{}) *Store_GetUserByUID_Call {
return &Store_GetUserByUID_Call{Call: _e.mock.On("GetUserByUID", ctx, id)} 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 { func (_c *Store_GetUserByUID_Call) Run(run func(ctx context.Context, id int)) *Store_GetUserByUID_Call {
_c.Call.Run(func(args mock.Arguments) { _c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(int32)) run(args[0].(context.Context), args[1].(int))
}) })
return _c return _c
} }
@ -1401,7 +1401,7 @@ func (_c *Store_GetUserByUID_Call) Return(_a0 database.User, _a1 error) *Store_G
return _c return _c
} }
func (_c *Store_GetUserByUID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *Store_GetUserByUID_Call { func (_c *Store_GetUserByUID_Call) RunAndReturn(run func(context.Context, int) (database.User, error)) *Store_GetUserByUID_Call {
_c.Call.Return(run) _c.Call.Return(run)
return _c return _c
} }

View file

@ -26,7 +26,7 @@ type Alert struct {
} }
type ApiKey struct { type ApiKey struct {
ID int32 `json:"id"` ID int `json:"id"`
Owner int `json:"owner"` Owner int `json:"owner"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
Expires pgtype.Timestamp `json:"expires"` Expires pgtype.Timestamp `json:"expires"`
@ -109,7 +109,7 @@ type TalkgroupsLearned struct {
} }
type User struct { type User struct {
ID int32 `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
Email string `json:"email"` Email string `json:"email"`

View file

@ -31,8 +31,8 @@ type Querier interface {
GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAnyTagsRow, error) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAnyTagsRow, error)
GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroupsWithLearnedRow, error) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroupsWithLearnedRow, error)
GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]GetTalkgroupsWithLearnedBySystemRow, error) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]GetTalkgroupsWithLearnedBySystemRow, error)
GetUserByID(ctx context.Context, id int32) (User, error) GetUserByID(ctx context.Context, id int) (User, error)
GetUserByUID(ctx context.Context, id int32) (User, error) GetUserByUID(ctx context.Context, id int) (User, error)
GetUserByUsername(ctx context.Context, username string) (User, error) GetUserByUsername(ctx context.Context, username string) (User, error)
GetUsers(ctx context.Context) ([]User, error) GetUsers(ctx context.Context) ([]User, error)
SetCallTranscript(ctx context.Context, iD uuid.UUID, transcript *string) error SetCallTranscript(ctx context.Context, iD uuid.UUID, transcript *string) error

View file

@ -113,7 +113,7 @@ SELECT id, username, password, email, is_admin, prefs FROM users
WHERE id = $1 LIMIT 1 WHERE id = $1 LIMIT 1
` `
func (q *Queries) GetUserByID(ctx context.Context, id int32) (User, error) { func (q *Queries) GetUserByID(ctx context.Context, id int) (User, error) {
row := q.db.QueryRow(ctx, getUserByID, id) row := q.db.QueryRow(ctx, getUserByID, id)
var i User var i User
err := row.Scan( err := row.Scan(
@ -132,7 +132,7 @@ SELECT id, username, password, email, is_admin, prefs FROM users
WHERE id = $1 LIMIT 1 WHERE id = $1 LIMIT 1
` `
func (q *Queries) GetUserByUID(ctx context.Context, id int32) (User, error) { func (q *Queries) GetUserByUID(ctx context.Context, id int) (User, error) {
row := q.db.QueryRow(ctx, getUserByUID, id) row := q.db.QueryRow(ctx, getUserByUID, id)
var i User var i User
err := row.Scan( err := row.Scan(

View file

@ -44,21 +44,20 @@ func NewRelayManager(s Sinks, cfgs []config.Relay) (*RelayManager, error) {
} }
for i, cfg := range cfgs { for i, cfg := range cfgs {
rs, err := rm.newRelay(cfg) rs, err := rm.newRelay(i, cfg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
rm.relays = append(rm.relays, rs) rm.relays = append(rm.relays, rs)
sinkName := fmt.Sprintf("relay%d:%s", i, rs.url.Host) s.Register(rs.Name, rs, cfg.Required)
s.Register(sinkName, rs, cfg.Required)
} }
return rm, nil return rm, nil
} }
func (rs *RelayManager) newRelay(cfg config.Relay) (*Relay, error) { func (rs *RelayManager) newRelay(idx int, cfg config.Relay) (*Relay, error) {
u, err := url.Parse(cfg.URL) u, err := url.Parse(cfg.URL)
if err != nil { if err != nil {
return nil, err return nil, err
@ -71,6 +70,7 @@ func (rs *RelayManager) newRelay(cfg config.Relay) (*Relay, error) {
u = u.JoinPath("/api/call-upload") u = u.JoinPath("/api/call-upload")
return &Relay{ return &Relay{
Name: fmt.Sprintf("relay%d:%s", idx, u.Host),
Relay: cfg, Relay: cfg,
url: u, url: u,
mgr: rs, mgr: rs,

View file

@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS talkgroups(
alert BOOLEAN NOT NULL DEFAULT 'true', alert BOOLEAN NOT NULL DEFAULT 'true',
alert_config JSONB, alert_config JSONB,
weight REAL NOT NULL DEFAULT 1.0, weight REAL NOT NULL DEFAULT 1.0,
learned BOOLEAN, learned BOOLEAN NOT NULL DEFAULT FALSE,
UNIQUE (system_id, tgid) UNIQUE (system_id, tgid)
); );