This commit is contained in:
Jamie Curnow
2023-05-31 13:52:58 +10:00
parent 94b6971ef7
commit 4b4c7baea4
14 changed files with 54 additions and 27 deletions

View File

@ -25,13 +25,21 @@ type ListResponse struct {
// ListQueryBuilder is used to setup queries for lists
func ListQueryBuilder(
pageInfo *model.PageInfo,
defaultSort model.Sort,
filters []model.Filter,
filterMap map[string]filterMapValue,
) *gorm.DB {
scopes := make([]func(*gorm.DB) *gorm.DB, 0)
scopes = append(scopes, ScopeOrderBy(pageInfo, defaultSort))
scopes = append(scopes, ScopeOffsetLimit(pageInfo))
scopes = append(scopes, ScopeFilters(filters, filterMap))
return database.GetDB().Scopes(scopes...)
}
// AddOrderToList is used after query above is used for counting
// Postgres in particular doesn't like count(*) when ordering at the same time
func AddOrderToList(
dbo *gorm.DB,
pageInfo *model.PageInfo,
defaultSort model.Sort,
) *gorm.DB {
return dbo.Scopes(ScopeOrderBy(pageInfo, defaultSort))
}