add incident filtering

This commit is contained in:
Daniel Ponte 2024-12-29 19:01:13 -05:00
parent 3b914ba19e
commit 841b9f1b16
5 changed files with 60 additions and 27 deletions

View file

@ -228,11 +228,27 @@ WHERE
CASE WHEN $1::TIMESTAMPTZ IS NOT NULL THEN
i.start_time >= $1 ELSE TRUE END AND
CASE WHEN $2::TIMESTAMPTZ IS NOT NULL THEN
i.start_time <= $2 ELSE TRUE END
i.start_time <= $2 ELSE TRUE END AND
(CASE WHEN $3::TEXT IS NOT NULL THEN (
i.name ILIKE '%' || $3 || '%' OR
i.description ILIKE '%' || $4 || '%'
) ELSE TRUE END)
`
func (q *Queries) ListIncidentsCount(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz) (int64, error) {
row := q.db.QueryRow(ctx, listIncidentsCount, start, end)
type ListIncidentsCountParams struct {
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
Filter *string `json:"filter"`
TGFilter *string `json:"tg_filter"`
}
func (q *Queries) ListIncidentsCount(ctx context.Context, arg ListIncidentsCountParams) (int64, error) {
row := q.db.QueryRow(ctx, listIncidentsCount,
arg.Start,
arg.End,
arg.Filter,
arg.TGFilter,
)
var count int64
err := row.Scan(&count)
return count, err
@ -252,17 +268,23 @@ WHERE
CASE WHEN $1::TIMESTAMPTZ IS NOT NULL THEN
i.start_time >= $1 ELSE TRUE END AND
CASE WHEN $2::TIMESTAMPTZ IS NOT NULL THEN
i.start_time <= $2 ELSE TRUE END
i.start_time <= $2 ELSE TRUE END AND
(CASE WHEN $3::TEXT IS NOT NULL THEN (
i.name ILIKE '%' || $3 || '%' OR
i.description ILIKE '%' || $4 || '%'
) ELSE TRUE END)
ORDER BY
CASE WHEN $3::TEXT = 'asc' THEN i.start_time END ASC,
CASE WHEN $3::TEXT = 'desc' THEN i.start_time END DESC
OFFSET $4 ROWS
FETCH NEXT $5 ROWS ONLY
CASE WHEN $5::TEXT = 'asc' THEN i.start_time END ASC,
CASE WHEN $5::TEXT = 'desc' THEN i.start_time END DESC
OFFSET $6 ROWS
FETCH NEXT $7 ROWS ONLY
`
type ListIncidentsPParams struct {
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
Filter *string `json:"filter"`
TGFilter *string `json:"tg_filter"`
Direction string `json:"direction"`
Offset int32 `json:"offset"`
PerPage int32 `json:"per_page"`
@ -272,6 +294,8 @@ func (q *Queries) ListIncidentsP(ctx context.Context, arg ListIncidentsPParams)
rows, err := q.db.Query(ctx, listIncidentsP,
arg.Start,
arg.End,
arg.Filter,
arg.TGFilter,
arg.Direction,
arg.Offset,
arg.PerPage,

View file

@ -2769,9 +2769,9 @@ func (_c *Store_ListCallsP_Call) RunAndReturn(run func(context.Context, database
return _c
}
// ListIncidentsCount provides a mock function with given fields: ctx, start, end
func (_m *Store) ListIncidentsCount(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz) (int64, error) {
ret := _m.Called(ctx, start, end)
// ListIncidentsCount provides a mock function with given fields: ctx, arg
func (_m *Store) ListIncidentsCount(ctx context.Context, arg database.ListIncidentsCountParams) (int64, error) {
ret := _m.Called(ctx, arg)
if len(ret) == 0 {
panic("no return value specified for ListIncidentsCount")
@ -2779,17 +2779,17 @@ func (_m *Store) ListIncidentsCount(ctx context.Context, start pgtype.Timestampt
var r0 int64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz) (int64, error)); ok {
return rf(ctx, start, end)
if rf, ok := ret.Get(0).(func(context.Context, database.ListIncidentsCountParams) (int64, error)); ok {
return rf(ctx, arg)
}
if rf, ok := ret.Get(0).(func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz) int64); ok {
r0 = rf(ctx, start, end)
if rf, ok := ret.Get(0).(func(context.Context, database.ListIncidentsCountParams) int64); ok {
r0 = rf(ctx, arg)
} else {
r0 = ret.Get(0).(int64)
}
if rf, ok := ret.Get(1).(func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz) error); ok {
r1 = rf(ctx, start, end)
if rf, ok := ret.Get(1).(func(context.Context, database.ListIncidentsCountParams) error); ok {
r1 = rf(ctx, arg)
} else {
r1 = ret.Error(1)
}
@ -2804,15 +2804,14 @@ type Store_ListIncidentsCount_Call struct {
// ListIncidentsCount is a helper method to define mock.On call
// - ctx context.Context
// - start pgtype.Timestamptz
// - end pgtype.Timestamptz
func (_e *Store_Expecter) ListIncidentsCount(ctx interface{}, start interface{}, end interface{}) *Store_ListIncidentsCount_Call {
return &Store_ListIncidentsCount_Call{Call: _e.mock.On("ListIncidentsCount", ctx, start, end)}
// - arg database.ListIncidentsCountParams
func (_e *Store_Expecter) ListIncidentsCount(ctx interface{}, arg interface{}) *Store_ListIncidentsCount_Call {
return &Store_ListIncidentsCount_Call{Call: _e.mock.On("ListIncidentsCount", ctx, arg)}
}
func (_c *Store_ListIncidentsCount_Call) Run(run func(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz)) *Store_ListIncidentsCount_Call {
func (_c *Store_ListIncidentsCount_Call) Run(run func(ctx context.Context, arg database.ListIncidentsCountParams)) *Store_ListIncidentsCount_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(pgtype.Timestamptz), args[2].(pgtype.Timestamptz))
run(args[0].(context.Context), args[1].(database.ListIncidentsCountParams))
})
return _c
}
@ -2822,7 +2821,7 @@ func (_c *Store_ListIncidentsCount_Call) Return(_a0 int64, _a1 error) *Store_Lis
return _c
}
func (_c *Store_ListIncidentsCount_Call) RunAndReturn(run func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz) (int64, error)) *Store_ListIncidentsCount_Call {
func (_c *Store_ListIncidentsCount_Call) RunAndReturn(run func(context.Context, database.ListIncidentsCountParams) (int64, error)) *Store_ListIncidentsCount_Call {
_c.Call.Return(run)
return _c
}

View file

@ -53,7 +53,7 @@ type Querier interface {
GetUsers(ctx context.Context) ([]User, error)
ListCallsCount(ctx context.Context, arg ListCallsCountParams) (int64, error)
ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListCallsPRow, error)
ListIncidentsCount(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz) (int64, error)
ListIncidentsCount(ctx context.Context, arg ListIncidentsCountParams) (int64, error)
ListIncidentsP(ctx context.Context, arg ListIncidentsPParams) ([]Incident, error)
RemoveFromIncident(ctx context.Context, iD uuid.UUID, callIds []uuid.UUID) error
RestoreTalkgroupVersion(ctx context.Context, versionIds int) (Talkgroup, error)

View file

@ -17,6 +17,7 @@ import (
type IncidentsParams struct {
common.Pagination
Direction *common.SortDirection `json:"dir"`
Filter *string `json:"filter"`
Start *jsontypes.Time `json:"start"`
End *jsontypes.Time `json:"end"`
@ -158,6 +159,7 @@ func (s *store) Incidents(ctx context.Context, p IncidentsParams) (incs []incide
dbParam := database.ListIncidentsPParams{
Start: p.Start.PGTypeTSTZ(),
End: p.End.PGTypeTSTZ(),
Filter: p.Filter,
Direction: p.Direction.DirString(common.DirAsc),
Offset: offset,
PerPage: perPage,

View file

@ -64,7 +64,11 @@ WHERE
CASE WHEN sqlc.narg('start')::TIMESTAMPTZ IS NOT NULL THEN
i.start_time >= sqlc.narg('start') ELSE TRUE END AND
CASE WHEN sqlc.narg('end')::TIMESTAMPTZ IS NOT NULL THEN
i.start_time <= sqlc.narg('end') ELSE TRUE END
i.start_time <= sqlc.narg('end') ELSE TRUE END AND
(CASE WHEN sqlc.narg('filter')::TEXT IS NOT NULL THEN (
i.name ILIKE '%' || @filter || '%' OR
i.description ILIKE '%' || @tg_filter || '%'
) ELSE TRUE END)
ORDER BY
CASE WHEN @direction::TEXT = 'asc' THEN i.start_time END ASC,
CASE WHEN @direction::TEXT = 'desc' THEN i.start_time END DESC
@ -79,7 +83,11 @@ WHERE
CASE WHEN sqlc.narg('start')::TIMESTAMPTZ IS NOT NULL THEN
i.start_time >= sqlc.narg('start') ELSE TRUE END AND
CASE WHEN sqlc.narg('end')::TIMESTAMPTZ IS NOT NULL THEN
i.start_time <= sqlc.narg('end') ELSE TRUE END
i.start_time <= sqlc.narg('end') ELSE TRUE END AND
(CASE WHEN sqlc.narg('filter')::TEXT IS NOT NULL THEN (
i.name ILIKE '%' || @filter || '%' OR
i.description ILIKE '%' || @tg_filter || '%'
) ELSE TRUE END)
;
-- name: GetIncidentCalls :many