Shares #109
6 changed files with 50 additions and 47 deletions
|
@ -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
|
// 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)
|
ret := _m.Called(ctx, arg)
|
||||||
|
|
||||||
if len(ret) == 0 {
|
if len(ret) == 0 {
|
||||||
panic("no return value specified for GetSharesP")
|
panic("no return value specified for GetSharesP")
|
||||||
}
|
}
|
||||||
|
|
||||||
var r0 []database.Share
|
var r0 []database.GetSharesPRow
|
||||||
var r1 error
|
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)
|
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)
|
r0 = rf(ctx, arg)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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
|
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)
|
_c.Call.Return(_a0, _a1)
|
||||||
return _c
|
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)
|
_c.Call.Return(run)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ type Querier interface {
|
||||||
GetIncidentOwner(ctx context.Context, id uuid.UUID) (int, error)
|
GetIncidentOwner(ctx context.Context, id uuid.UUID) (int, error)
|
||||||
GetIncidentTalkgroups(ctx context.Context, incidentID uuid.UUID) ([]GetIncidentTalkgroupsRow, error)
|
GetIncidentTalkgroups(ctx context.Context, incidentID uuid.UUID) ([]GetIncidentTalkgroupsRow, error)
|
||||||
GetShare(ctx context.Context, id string) (Share, 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)
|
GetSharesPCount(ctx context.Context, owner *int32) (int64, error)
|
||||||
GetSystemName(ctx context.Context, systemID int) (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)
|
||||||
|
|
|
@ -55,14 +55,14 @@ func (q *Queries) DeleteShare(ctx context.Context, id string) error {
|
||||||
|
|
||||||
const getShare = `-- name: GetShare :one
|
const getShare = `-- name: GetShare :one
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
s.id,
|
||||||
entity_type,
|
s.entity_type,
|
||||||
entity_id,
|
s.entity_id,
|
||||||
entity_date,
|
s.entity_date,
|
||||||
owner,
|
s.owner,
|
||||||
expiration
|
s.expiration
|
||||||
FROM shares
|
FROM shares s
|
||||||
WHERE id = $1
|
WHERE s.id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetShare(ctx context.Context, id string) (Share, error) {
|
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
|
const getSharesP = `-- name: GetSharesP :many
|
||||||
SELECT
|
SELECT
|
||||||
s.id,
|
s.id, s.entity_type, s.entity_id, s.entity_date, s.owner, s.expiration,
|
||||||
s.entity_type,
|
u.username
|
||||||
s.entity_id,
|
|
||||||
s.entity_date,
|
|
||||||
s.owner,
|
|
||||||
s.expiration
|
|
||||||
FROM shares s
|
FROM shares s
|
||||||
|
JOIN users u ON (s.owner = u.id)
|
||||||
WHERE
|
WHERE
|
||||||
CASE WHEN $1::INTEGER IS NOT NULL THEN
|
CASE WHEN $1::INTEGER IS NOT NULL THEN
|
||||||
s.owner = $1 ELSE TRUE END
|
s.owner = $1 ELSE TRUE END
|
||||||
|
@ -105,7 +102,12 @@ type GetSharesPParams struct {
|
||||||
PerPage int32 `json:"perPage"`
|
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,
|
rows, err := q.db.Query(ctx, getSharesP,
|
||||||
arg.Owner,
|
arg.Owner,
|
||||||
arg.Direction,
|
arg.Direction,
|
||||||
|
@ -116,16 +118,17 @@ func (q *Queries) GetSharesP(ctx context.Context, arg GetSharesPParams) ([]Share
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var items []Share
|
var items []GetSharesPRow
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i Share
|
var i GetSharesPRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.Share.ID,
|
||||||
&i.EntityType,
|
&i.Share.EntityType,
|
||||||
&i.EntityID,
|
&i.Share.EntityID,
|
||||||
&i.EntityDate,
|
&i.Share.EntityDate,
|
||||||
&i.Owner,
|
&i.Share.Owner,
|
||||||
&i.Expiration,
|
&i.Share.Expiration,
|
||||||
|
&i.Username,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,8 @@ type Share struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type EntityType `json:"entityType"`
|
Type EntityType `json:"entityType"`
|
||||||
Date *jsontypes.Time `json:"entityDate,omitempty"` // we handle this for the user
|
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"`
|
EntityID uuid.UUID `json:"entityID"`
|
||||||
Expiration *jsontypes.Time `json:"expiration"`
|
Expiration *jsontypes.Time `json:"expiration"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,9 @@ func (s *postgresStore) Shares(ctx context.Context, p SharesParams) (shares []*S
|
||||||
|
|
||||||
shares = make([]*Share, 0, len(shs))
|
shares = make([]*Share, 0, len(shs))
|
||||||
for _, v := range 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
|
return shares, int(count), nil
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
-- name: GetShare :one
|
-- name: GetShare :one
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
s.id,
|
||||||
entity_type,
|
s.entity_type,
|
||||||
entity_id,
|
s.entity_id,
|
||||||
entity_date,
|
s.entity_date,
|
||||||
owner,
|
s.owner,
|
||||||
expiration
|
s.expiration
|
||||||
FROM shares
|
FROM shares s
|
||||||
WHERE id = @id;
|
WHERE s.id = @id;
|
||||||
|
|
||||||
-- name: CreateShare :exec
|
-- name: CreateShare :exec
|
||||||
INSERT INTO shares (
|
INSERT INTO shares (
|
||||||
|
@ -27,13 +27,10 @@ DELETE FROM shares WHERE expiration < NOW();
|
||||||
|
|
||||||
-- name: GetSharesP :many
|
-- name: GetSharesP :many
|
||||||
SELECT
|
SELECT
|
||||||
s.id,
|
sqlc.embed(s),
|
||||||
s.entity_type,
|
u.username
|
||||||
s.entity_id,
|
|
||||||
s.entity_date,
|
|
||||||
s.owner,
|
|
||||||
s.expiration
|
|
||||||
FROM shares s
|
FROM shares s
|
||||||
|
JOIN users u ON (s.owner = u.id)
|
||||||
WHERE
|
WHERE
|
||||||
CASE WHEN sqlc.narg('owner')::INTEGER IS NOT NULL THEN
|
CASE WHEN sqlc.narg('owner')::INTEGER IS NOT NULL THEN
|
||||||
s.owner = @owner ELSE TRUE END
|
s.owner = @owner ELSE TRUE END
|
||||||
|
|
Loading…
Add table
Reference in a new issue