35 lines
759 B
Go
35 lines
759 B
Go
package useCases
|
|
|
|
import "RenewCMS/internal/domain/site"
|
|
|
|
type ListSitesUseCase struct {
|
|
siteRepository site.Repository
|
|
}
|
|
|
|
type ListSitesCommand struct {
|
|
Q string
|
|
Page int
|
|
Size int
|
|
}
|
|
|
|
type SitePage struct {
|
|
Items []site.Site
|
|
Total int
|
|
}
|
|
|
|
func NewListSitesUseCase(siteRepository site.Repository) *ListSitesUseCase {
|
|
return &ListSitesUseCase{siteRepository}
|
|
}
|
|
|
|
func (u *ListSitesUseCase) List() ([]site.Site, error) {
|
|
return u.siteRepository.List()
|
|
}
|
|
|
|
func (u *ListSitesUseCase) ListPage(command ListSitesCommand) (SitePage, error) {
|
|
found, err := u.siteRepository.Find(site.ListQuery{Q: command.Q, Page: command.Page, Size: command.Size})
|
|
if err != nil {
|
|
return SitePage{}, err
|
|
}
|
|
return SitePage{Items: found.Items, Total: found.Total}, nil
|
|
}
|