Fix schema responses not matching tests

This commit is contained in:
Jamie Curnow 2023-05-29 14:19:17 +10:00
parent 4b39ef0eba
commit c849938da2
No known key found for this signature in database
GPG Key ID: FFBB624C43388E9E
14 changed files with 28 additions and 13 deletions

View File

@ -14,6 +14,7 @@ import (
"npm/internal/entity/dnsprovider"
"npm/internal/entity/host"
"npm/internal/entity/nginxtemplate"
"npm/internal/entity/setting"
"npm/internal/entity/stream"
"npm/internal/entity/upstream"
"npm/internal/entity/user"
@ -133,8 +134,11 @@ func applyRoutes(r chi.Router) chi.Router {
// Settings
r.With(middleware.EnforceSetup(true), middleware.Enforce(user.CapabilitySettingsManage)).Route("/settings", func(r chi.Router) {
// r.With(middleware.Filters(setting.GetFilterSchema())).
r.Get("/", handler.GetSettings())
// List
r.With(
middleware.Filters(setting.Model{}),
).Get("/", handler.GetSettings())
r.Get("/{name}", handler.GetSetting())
r.With(middleware.EnforceRequestSchema(schema.CreateSetting())).
Post("/", handler.CreateSetting())

View File

@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -65,7 +65,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -51,7 +51,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"npm/internal/logger"
"npm/internal/model"
"gorm.io/gorm"
@ -36,6 +37,8 @@ func ScopeOrderBy(pageInfo *model.PageInfo, defaultSort model.Sort) func(db *gor
}
func ScopeFilters(filters []model.Filter, filterMap map[string]filterMapValue) func(db *gorm.DB) *gorm.DB {
logger.Debug("FILTERS: %+v", filters)
logger.Debug("FILTERMAP: %+v", filterMap)
return func(db *gorm.DB) *gorm.DB {
for _, f := range filters {
// Lookup this filter field from the name map

View File

@ -49,7 +49,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -46,7 +46,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -49,7 +49,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -73,7 +73,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Sort: pageInfo.GetSort(defaultSort),
Filter: filters,
}

View File

@ -14,3 +14,11 @@ type Sort struct {
Field string `json:"field"`
Direction string `json:"direction"`
}
// TableName overrides the table name used by gorm
func (p *PageInfo) GetSort(def Sort) []Sort {
if p.Sort == nil {
return []Sort{def}
}
return p.Sort
}