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

31 lines
763 B
Go
Raw Normal View History

2020-06-21 11:27:08 +00:00
package usecase
import (
"context"
2020-08-09 12:32:46 +00:00
"github.com/tribalwarshelp/api/middleware"
2020-06-21 11:27:08 +00:00
"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, cfg tribehistory.FetchConfig) ([]*models.TribeHistory, int, error) {
if cfg.Filter == nil {
cfg.Filter = &models.TribeHistoryFilter{}
2020-06-21 11:27:08 +00:00
}
2021-03-21 06:42:12 +00:00
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > tribehistory.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = tribehistory.FetchLimit
}
cfg.Sort = utils.SanitizeSorts(cfg.Sort)
return ucase.repo.Fetch(ctx, cfg)
2020-06-21 11:27:08 +00:00
}