This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
api/tribehistory/usecase/tribehistory_usecase.go

33 lines
794 B
Go

package usecase
import (
"context"
"github.com/tribalwarshelp/api/tribehistory"
"github.com/tribalwarshelp/api/utils"
"github.com/tribalwarshelp/shared/models"
)
type usecase struct {
repo tribehistory.Repository
}
func New(repo tribehistory.Repository) tribehistory.Usecase {
return &usecase{repo}
}
func (ucase *usecase) Fetch(ctx context.Context, server string, filter *models.TribeHistoryFilter) ([]*models.TribeHistory, int, error) {
if filter == nil {
filter = &models.TribeHistoryFilter{}
}
if filter.Limit > tribehistory.PaginationLimit || filter.Limit <= 0 {
filter.Limit = tribehistory.PaginationLimit
}
filter.Sort = utils.SanitizeSort(filter.Sort)
return ucase.repo.Fetch(ctx, tribehistory.FetchConfig{
Server: server,
Filter: filter,
Count: true,
})
}