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/playerhistory/usecase/playerhistory_usecase.go

31 lines
794 B
Go

package usecase
import (
"context"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/tribalwarshelp/api/middleware"
"github.com/tribalwarshelp/api/playerhistory"
)
type usecase struct {
repo playerhistory.Repository
}
func New(repo playerhistory.Repository) playerhistory.Usecase {
return &usecase{repo}
}
func (ucase *usecase) Fetch(ctx context.Context, cfg playerhistory.FetchConfig) ([]*twmodel.PlayerHistory, int, error) {
if cfg.Filter == nil {
cfg.Filter = &twmodel.PlayerHistoryFilter{}
}
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > playerhistory.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = playerhistory.FetchLimit
}
if len(cfg.Sort) > playerhistory.MaxOrders {
cfg.Sort = cfg.Sort[0:playerhistory.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}