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/dailyplayerstats/usecase/dailyplayerstats_usecase.go

31 lines
819 B
Go

package usecase
import (
"context"
"github.com/tribalwarshelp/api/dailyplayerstats"
"github.com/tribalwarshelp/api/middleware"
"github.com/tribalwarshelp/api/utils"
"github.com/tribalwarshelp/shared/models"
)
type usecase struct {
repo dailyplayerstats.Repository
}
func New(repo dailyplayerstats.Repository) dailyplayerstats.Usecase {
return &usecase{repo}
}
func (ucase *usecase) Fetch(ctx context.Context, cfg dailyplayerstats.FetchConfig) ([]*models.DailyPlayerStats, int, error) {
if cfg.Filter == nil {
cfg.Filter = &models.DailyPlayerStatsFilter{}
}
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > dailyplayerstats.PaginationLimit || cfg.Limit <= 0) {
cfg.Limit = dailyplayerstats.PaginationLimit
}
cfg.Sort = utils.SanitizeSortExpressions(cfg.Sort)
return ucase.repo.Fetch(ctx, cfg)
}