nginx-proxy-manager/backend/internal/entity/upstream/methods.go

55 lines
1.1 KiB
Go
Raw Normal View History

package upstream
import (
"npm/internal/entity"
"npm/internal/model"
)
// GetByID finds a Upstream by ID
func GetByID(id uint) (Model, error) {
var m Model
err := m.LoadByID(id)
return m, err
}
// List will return a list of Upstreams
func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (entity.ListResponse, error) {
var result entity.ListResponse
defaultSort := model.Sort{
Field: "name",
Direction: "ASC",
}
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters)
// Get count of items in this search
var totalRows int64
if res := dbo.Model(&Model{}).Count(&totalRows); res.Error != nil {
return result, res.Error
}
// Get rows
items := make([]Model, 0)
if res := dbo.Find(&items); res.Error != nil {
return result, res.Error
}
// Expand to get servers, at a minimum
for idx := range items {
// nolint: errcheck, gosec
items[idx].Expand(expand)
}
result = entity.ListResponse{
Items: items,
Total: totalRows,
Limit: pageInfo.Limit,
Offset: pageInfo.Offset,
Sort: pageInfo.Sort,
Filter: filters,
}
return result, nil
}