fix filter

This commit is contained in:
Daniel Ponte 2024-12-29 19:04:06 -05:00
parent 841b9f1b16
commit 223f4d5bbe
5 changed files with 29 additions and 41 deletions

View file

@ -231,24 +231,12 @@ CASE WHEN $2::TIMESTAMPTZ IS NOT NULL THEN
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 || '%'
i.description ILIKE '%' || $3 || '%'
) ELSE TRUE 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,
)
func (q *Queries) ListIncidentsCount(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz, filter *string) (int64, error) {
row := q.db.QueryRow(ctx, listIncidentsCount, start, end, filter)
var count int64
err := row.Scan(&count)
return count, err
@ -271,20 +259,19 @@ CASE WHEN $2::TIMESTAMPTZ IS NOT NULL THEN
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 || '%'
i.description ILIKE '%' || $3 || '%'
) ELSE TRUE END)
ORDER BY
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
CASE WHEN $4::TEXT = 'asc' THEN i.start_time END ASC,
CASE WHEN $4::TEXT = 'desc' THEN i.start_time END DESC
OFFSET $5 ROWS
FETCH NEXT $6 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"`
@ -295,7 +282,6 @@ func (q *Queries) ListIncidentsP(ctx context.Context, arg ListIncidentsPParams)
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, arg
func (_m *Store) ListIncidentsCount(ctx context.Context, arg database.ListIncidentsCountParams) (int64, error) {
ret := _m.Called(ctx, arg)
// ListIncidentsCount provides a mock function with given fields: ctx, start, end, filter
func (_m *Store) ListIncidentsCount(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz, filter *string) (int64, error) {
ret := _m.Called(ctx, start, end, filter)
if len(ret) == 0 {
panic("no return value specified for ListIncidentsCount")
@ -2779,17 +2779,17 @@ func (_m *Store) ListIncidentsCount(ctx context.Context, arg database.ListIncide
var r0 int64
var r1 error
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, *string) (int64, error)); ok {
return rf(ctx, start, end, filter)
}
if rf, ok := ret.Get(0).(func(context.Context, database.ListIncidentsCountParams) int64); ok {
r0 = rf(ctx, arg)
if rf, ok := ret.Get(0).(func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz, *string) int64); ok {
r0 = rf(ctx, start, end, filter)
} else {
r0 = ret.Get(0).(int64)
}
if rf, ok := ret.Get(1).(func(context.Context, database.ListIncidentsCountParams) error); ok {
r1 = rf(ctx, arg)
if rf, ok := ret.Get(1).(func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz, *string) error); ok {
r1 = rf(ctx, start, end, filter)
} else {
r1 = ret.Error(1)
}
@ -2804,14 +2804,16 @@ type Store_ListIncidentsCount_Call struct {
// ListIncidentsCount is a helper method to define mock.On call
// - ctx context.Context
// - 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)}
// - start pgtype.Timestamptz
// - end pgtype.Timestamptz
// - filter *string
func (_e *Store_Expecter) ListIncidentsCount(ctx interface{}, start interface{}, end interface{}, filter interface{}) *Store_ListIncidentsCount_Call {
return &Store_ListIncidentsCount_Call{Call: _e.mock.On("ListIncidentsCount", ctx, start, end, filter)}
}
func (_c *Store_ListIncidentsCount_Call) Run(run func(ctx context.Context, arg database.ListIncidentsCountParams)) *Store_ListIncidentsCount_Call {
func (_c *Store_ListIncidentsCount_Call) Run(run func(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz, filter *string)) *Store_ListIncidentsCount_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(database.ListIncidentsCountParams))
run(args[0].(context.Context), args[1].(pgtype.Timestamptz), args[2].(pgtype.Timestamptz), args[3].(*string))
})
return _c
}
@ -2821,7 +2823,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, database.ListIncidentsCountParams) (int64, error)) *Store_ListIncidentsCount_Call {
func (_c *Store_ListIncidentsCount_Call) RunAndReturn(run func(context.Context, pgtype.Timestamptz, pgtype.Timestamptz, *string) (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, arg ListIncidentsCountParams) (int64, error)
ListIncidentsCount(ctx context.Context, start pgtype.Timestamptz, end pgtype.Timestamptz, filter *string) (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

@ -169,7 +169,7 @@ func (s *store) Incidents(ctx context.Context, p IncidentsParams) (incs []incide
var rows []database.Incident
txErr := db.InTx(ctx, func(db database.Store) error {
var err error
count, err = db.ListIncidentsCount(ctx, dbParam.Start, dbParam.End)
count, err = db.ListIncidentsCount(ctx, dbParam.Start, dbParam.End, dbParam.Filter)
if err != nil {
return err
}

View file

@ -67,7 +67,7 @@ CASE WHEN sqlc.narg('end')::TIMESTAMPTZ IS NOT NULL THEN
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 || '%'
i.description ILIKE '%' || @filter || '%'
) ELSE TRUE END)
ORDER BY
CASE WHEN @direction::TEXT = 'asc' THEN i.start_time END ASC,
@ -86,7 +86,7 @@ CASE WHEN sqlc.narg('end')::TIMESTAMPTZ IS NOT NULL THEN
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 || '%'
i.description ILIKE '%' || @filter || '%'
) ELSE TRUE END)
;