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
782 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/playerhistory"
"github.com/tribalwarshelp/api/utils"
"github.com/tribalwarshelp/shared/models"
)
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) ([]*models.PlayerHistory, int, error) {
if cfg.Filter == nil {
cfg.Filter = &models.PlayerHistoryFilter{}
2020-06-21 11:27:08 +00:00
}
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > playerhistory.PaginationLimit || cfg.Limit <= 0) {
cfg.Limit = playerhistory.PaginationLimit
}
cfg.Sort = utils.SanitizeSorts(cfg.Sort)
return ucase.repo.Fetch(ctx, cfg)
2020-06-21 11:27:08 +00:00
}