nginx-proxy-manager-zh/backend/internal/entity/lists.go

38 lines
995 B
Go
Raw Normal View History

package entity
import (
"npm/internal/database"
"npm/internal/model"
"gorm.io/gorm"
)
// ListableModel is a interface for common use
type ListableModel interface {
TableName() string
}
// ListResponse is the JSON response for users list
type ListResponse struct {
Total int64 `json:"total"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Sort []model.Sort `json:"sort"`
Filter []model.Filter `json:"filter,omitempty"`
Items interface{} `json:"items,omitempty"`
}
// ListQueryBuilder is used to setup queries for lists
func ListQueryBuilder(
pageInfo *model.PageInfo,
defaultSort model.Sort,
filters []model.Filter,
2023-05-28 23:53:16 -04:00
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))
2023-05-28 23:53:16 -04:00
scopes = append(scopes, ScopeFilters(filters, filterMap))
return database.GetDB().Scopes(scopes...)
}