share UI backend

This commit is contained in:
Daniel Ponte 2025-02-14 00:19:24 -05:00
parent 48903bb4a2
commit 68d4e3e269
6 changed files with 50 additions and 47 deletions

View file

@ -1925,23 +1925,23 @@ func (_c *Store_GetShare_Call) RunAndReturn(run func(context.Context, string) (d
}
// GetSharesP provides a mock function with given fields: ctx, arg
func (_m *Store) GetSharesP(ctx context.Context, arg database.GetSharesPParams) ([]database.Share, error) {
func (_m *Store) GetSharesP(ctx context.Context, arg database.GetSharesPParams) ([]database.GetSharesPRow, error) {
ret := _m.Called(ctx, arg)
if len(ret) == 0 {
panic("no return value specified for GetSharesP")
}
var r0 []database.Share
var r0 []database.GetSharesPRow
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, database.GetSharesPParams) ([]database.Share, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, database.GetSharesPParams) ([]database.GetSharesPRow, error)); ok {
return rf(ctx, arg)
}
if rf, ok := ret.Get(0).(func(context.Context, database.GetSharesPParams) []database.Share); ok {
if rf, ok := ret.Get(0).(func(context.Context, database.GetSharesPParams) []database.GetSharesPRow); ok {
r0 = rf(ctx, arg)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]database.Share)
r0 = ret.Get(0).([]database.GetSharesPRow)
}
}
@ -1973,12 +1973,12 @@ func (_c *Store_GetSharesP_Call) Run(run func(ctx context.Context, arg database.
return _c
}
func (_c *Store_GetSharesP_Call) Return(_a0 []database.Share, _a1 error) *Store_GetSharesP_Call {
func (_c *Store_GetSharesP_Call) Return(_a0 []database.GetSharesPRow, _a1 error) *Store_GetSharesP_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *Store_GetSharesP_Call) RunAndReturn(run func(context.Context, database.GetSharesPParams) ([]database.Share, error)) *Store_GetSharesP_Call {
func (_c *Store_GetSharesP_Call) RunAndReturn(run func(context.Context, database.GetSharesPParams) ([]database.GetSharesPRow, error)) *Store_GetSharesP_Call {
_c.Call.Return(run)
return _c
}

View file

@ -42,7 +42,7 @@ type Querier interface {
GetIncidentOwner(ctx context.Context, id uuid.UUID) (int, error)
GetIncidentTalkgroups(ctx context.Context, incidentID uuid.UUID) ([]GetIncidentTalkgroupsRow, error)
GetShare(ctx context.Context, id string) (Share, error)
GetSharesP(ctx context.Context, arg GetSharesPParams) ([]Share, error)
GetSharesP(ctx context.Context, arg GetSharesPParams) ([]GetSharesPRow, error)
GetSharesPCount(ctx context.Context, owner *int32) (int64, error)
GetSystemName(ctx context.Context, systemID int) (string, error)
GetTalkgroup(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupRow, error)

View file

@ -55,14 +55,14 @@ func (q *Queries) DeleteShare(ctx context.Context, id string) error {
const getShare = `-- name: GetShare :one
SELECT
id,
entity_type,
entity_id,
entity_date,
owner,
expiration
FROM shares
WHERE id = $1
s.id,
s.entity_type,
s.entity_id,
s.entity_date,
s.owner,
s.expiration
FROM shares s
WHERE s.id = $1
`
func (q *Queries) GetShare(ctx context.Context, id string) (Share, error) {
@ -81,13 +81,10 @@ func (q *Queries) GetShare(ctx context.Context, id string) (Share, error) {
const getSharesP = `-- name: GetSharesP :many
SELECT
s.id,
s.entity_type,
s.entity_id,
s.entity_date,
s.owner,
s.expiration
s.id, s.entity_type, s.entity_id, s.entity_date, s.owner, s.expiration,
u.username
FROM shares s
JOIN users u ON (s.owner = u.id)
WHERE
CASE WHEN $1::INTEGER IS NOT NULL THEN
s.owner = $1 ELSE TRUE END
@ -105,7 +102,12 @@ type GetSharesPParams struct {
PerPage int32 `json:"perPage"`
}
func (q *Queries) GetSharesP(ctx context.Context, arg GetSharesPParams) ([]Share, error) {
type GetSharesPRow struct {
Share Share `json:"share"`
Username string `json:"username"`
}
func (q *Queries) GetSharesP(ctx context.Context, arg GetSharesPParams) ([]GetSharesPRow, error) {
rows, err := q.db.Query(ctx, getSharesP,
arg.Owner,
arg.Direction,
@ -116,16 +118,17 @@ func (q *Queries) GetSharesP(ctx context.Context, arg GetSharesPParams) ([]Share
return nil, err
}
defer rows.Close()
var items []Share
var items []GetSharesPRow
for rows.Next() {
var i Share
var i GetSharesPRow
if err := rows.Scan(
&i.ID,
&i.EntityType,
&i.EntityID,
&i.EntityDate,
&i.Owner,
&i.Expiration,
&i.Share.ID,
&i.Share.EntityType,
&i.Share.EntityID,
&i.Share.EntityDate,
&i.Share.Owner,
&i.Share.Expiration,
&i.Username,
); err != nil {
return nil, err
}

View file

@ -48,7 +48,8 @@ type Share struct {
ID string `json:"id"`
Type EntityType `json:"entityType"`
Date *jsontypes.Time `json:"entityDate,omitempty"` // we handle this for the user
Owner users.UserID `json:"owner"`
Owner users.UserID `json:"-"`
OwnerUser *string `json:"owner,omitempty"`
EntityID uuid.UUID `json:"entityID"`
Expiration *jsontypes.Time `json:"expiration"`
}

View file

@ -148,7 +148,9 @@ func (s *postgresStore) Shares(ctx context.Context, p SharesParams) (shares []*S
shares = make([]*Share, 0, len(shs))
for _, v := range shs {
shares = append(shares, recToShare(v))
s := recToShare(v.Share)
s.OwnerUser = &v.Username
shares = append(shares, s)
}
return shares, int(count), nil

View file

@ -1,13 +1,13 @@
-- name: GetShare :one
SELECT
id,
entity_type,
entity_id,
entity_date,
owner,
expiration
FROM shares
WHERE id = @id;
s.id,
s.entity_type,
s.entity_id,
s.entity_date,
s.owner,
s.expiration
FROM shares s
WHERE s.id = @id;
-- name: CreateShare :exec
INSERT INTO shares (
@ -27,13 +27,10 @@ DELETE FROM shares WHERE expiration < NOW();
-- name: GetSharesP :many
SELECT
s.id,
s.entity_type,
s.entity_id,
s.entity_date,
s.owner,
s.expiration
sqlc.embed(s),
u.username
FROM shares s
JOIN users u ON (s.owner = u.id)
WHERE
CASE WHEN sqlc.narg('owner')::INTEGER IS NOT NULL THEN
s.owner = @owner ELSE TRUE END