Talker alias filter backend

This commit is contained in:
Daniel Ponte 2025-02-22 18:40:49 -05:00
parent 8fd0c85c1e
commit 6d7c82c3a8
3 changed files with 62 additions and 43 deletions

View file

@ -203,6 +203,7 @@ type CallsParams struct {
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
SourceFilter *string `json:"sourceFilter"`
AtLeastSeconds *float32 `json:"atLeastSeconds"`
UnknownTG bool `json:"unknownTG"`
}
@ -217,15 +218,16 @@ func (s *postgresStore) Calls(ctx context.Context, p CallsParams) (rows []databa
offset, perPage := p.Pagination.OffsetPerPage(100)
par := database.ListCallsPParams{
Start: p.Start.PGTypeTSTZ(),
End: p.End.PGTypeTSTZ(),
TagsAny: p.TagsAny,
TagsNot: p.TagsNot,
Offset: offset,
PerPage: perPage,
Direction: p.Direction.DirString(common.DirAsc),
TGFilter: p.TGFilter,
UnknownTG: p.UnknownTG,
Start: p.Start.PGTypeTSTZ(),
End: p.End.PGTypeTSTZ(),
TagsAny: p.TagsAny,
TagsNot: p.TagsNot,
Offset: offset,
PerPage: perPage,
Direction: p.Direction.DirString(common.DirAsc),
TGFilter: p.TGFilter,
SourceFilter: p.SourceFilter,
UnknownTG: p.UnknownTG,
}
if p.AtLeastSeconds != nil {
@ -241,13 +243,14 @@ func (s *postgresStore) Calls(ctx context.Context, p CallsParams) (rows []databa
txErr := db.InTx(ctx, func(db database.Store) error {
var err error
count, err = db.ListCallsCount(ctx, database.ListCallsCountParams{
Start: par.Start,
End: par.End,
TagsAny: par.TagsAny,
TagsNot: par.TagsNot,
TGFilter: par.TGFilter,
LongerThan: par.LongerThan,
UnknownTG: par.UnknownTG,
Start: par.Start,
End: par.End,
TagsAny: par.TagsAny,
TagsNot: par.TagsNot,
TGFilter: par.TGFilter,
SourceFilter: p.SourceFilter,
LongerThan: par.LongerThan,
UnknownTG: par.UnknownTG,
})
if err != nil {
return err

View file

@ -317,22 +317,26 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN
tgs.name ILIKE '%' || $5 || '%' OR
tgs.alpha_tag ILIKE '%' || $5 || '%'
) ELSE TRUE END) AND
(CASE WHEN $6::NUMERIC IS NOT NULL THEN (
c.duration > $6
(CASE WHEN $6::TEXT IS NOT NULL THEN (
c.talker_alias ILIKE '%' || $6 || '%'
) ELSE TRUE END) AND
(CASE WHEN $7::BOOLEAN = TRUE THEN (
(CASE WHEN $7::NUMERIC IS NOT NULL THEN (
c.duration > $7
) ELSE TRUE END) AND
(CASE WHEN $8::BOOLEAN = TRUE THEN (
tgs.tgid IS NULL
) ELSE TRUE END)
`
type ListCallsCountParams struct {
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
LongerThan pgtype.Numeric `json:"longerThan"`
UnknownTG bool `json:"unknownTg"`
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
SourceFilter *string `json:"sourceFilter"`
LongerThan pgtype.Numeric `json:"longerThan"`
UnknownTG bool `json:"unknownTg"`
}
func (q *Queries) ListCallsCount(ctx context.Context, arg ListCallsCountParams) (int64, error) {
@ -342,6 +346,7 @@ func (q *Queries) ListCallsCount(ctx context.Context, arg ListCallsCountParams)
arg.TagsAny,
arg.TagsNot,
arg.TGFilter,
arg.SourceFilter,
arg.LongerThan,
arg.UnknownTG,
)
@ -377,31 +382,35 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN
tgs.name ILIKE '%' || $5 || '%' OR
tgs.alpha_tag ILIKE '%' || $5 || '%'
) ELSE TRUE END) AND
(CASE WHEN $6::NUMERIC IS NOT NULL THEN (
c.duration > $6
(CASE WHEN $6::TEXT IS NOT NULL THEN (
c.talker_alias ILIKE '%' || $6 || '%'
) ELSE TRUE END) AND
(CASE WHEN $7::BOOLEAN = TRUE THEN (
(CASE WHEN $7::NUMERIC IS NOT NULL THEN (
c.duration > $7
) ELSE TRUE END) AND
(CASE WHEN $8::BOOLEAN = TRUE THEN (
tgs.tgid IS NULL
) ELSE TRUE END)
GROUP BY c.id, c.call_date
ORDER BY
CASE WHEN $8::TEXT = 'asc' THEN c.call_date END ASC,
CASE WHEN $8 = 'desc' THEN c.call_date END DESC
OFFSET $9 ROWS
FETCH NEXT $10 ROWS ONLY
CASE WHEN $9::TEXT = 'asc' THEN c.call_date END ASC,
CASE WHEN $9 = 'desc' THEN c.call_date END DESC
OFFSET $10 ROWS
FETCH NEXT $11 ROWS ONLY
`
type ListCallsPParams struct {
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
LongerThan pgtype.Numeric `json:"longerThan"`
UnknownTG bool `json:"unknownTg"`
Direction string `json:"direction"`
Offset int32 `json:"offset"`
PerPage int32 `json:"perPage"`
Start pgtype.Timestamptz `json:"start"`
End pgtype.Timestamptz `json:"end"`
TagsAny []string `json:"tagsAny"`
TagsNot []string `json:"tagsNot"`
TGFilter *string `json:"tgFilter"`
SourceFilter *string `json:"sourceFilter"`
LongerThan pgtype.Numeric `json:"longerThan"`
UnknownTG bool `json:"unknownTg"`
Direction string `json:"direction"`
Offset int32 `json:"offset"`
PerPage int32 `json:"perPage"`
}
type ListCallsPRow struct {
@ -421,6 +430,7 @@ func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListC
arg.TagsAny,
arg.TagsNot,
arg.TGFilter,
arg.SourceFilter,
arg.LongerThan,
arg.UnknownTG,
arg.Direction,

View file

@ -125,6 +125,9 @@ CASE WHEN sqlc.narg('tags_not')::TEXT[] IS NOT NULL THEN
tgs.name ILIKE '%' || @tg_filter || '%' OR
tgs.alpha_tag ILIKE '%' || @tg_filter || '%'
) ELSE TRUE END) AND
(CASE WHEN sqlc.narg('source_filter')::TEXT IS NOT NULL THEN (
c.talker_alias ILIKE '%' || @source_filter || '%'
) ELSE TRUE END) AND
(CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN (
c.duration > @longer_than
) ELSE TRUE END) AND
@ -158,6 +161,9 @@ CASE WHEN sqlc.narg('tags_not')::TEXT[] IS NOT NULL THEN
tgs.name ILIKE '%' || @tg_filter || '%' OR
tgs.alpha_tag ILIKE '%' || @tg_filter || '%'
) ELSE TRUE END) AND
(CASE WHEN sqlc.narg('source_filter')::TEXT IS NOT NULL THEN (
c.talker_alias ILIKE '%' || @source_filter || '%'
) ELSE TRUE END) AND
(CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN (
c.duration > @longer_than
) ELSE TRUE END) AND