Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
55
cloud/maplepress-backend/internal/usecase/site/list.go
Normal file
55
cloud/maplepress-backend/internal/usecase/site/list.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package site
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
"go.uber.org/zap"
|
||||
|
||||
domainsite "codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/internal/domain/site"
|
||||
)
|
||||
|
||||
// ListSitesUseCase handles listing sites for a tenant
|
||||
type ListSitesUseCase struct {
|
||||
repo domainsite.Repository
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// ProvideListSitesUseCase creates a new ListSitesUseCase
|
||||
func ProvideListSitesUseCase(repo domainsite.Repository, logger *zap.Logger) *ListSitesUseCase {
|
||||
return &ListSitesUseCase{
|
||||
repo: repo,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// ListSitesInput is the input for listing sites
|
||||
type ListSitesInput struct {
|
||||
PageSize int
|
||||
PageState []byte
|
||||
}
|
||||
|
||||
// ListSitesOutput is the output after listing sites
|
||||
type ListSitesOutput struct {
|
||||
Sites []*domainsite.Site
|
||||
PageState []byte
|
||||
}
|
||||
|
||||
// Execute lists all sites for a tenant
|
||||
func (uc *ListSitesUseCase) Execute(ctx context.Context, tenantID gocql.UUID, input *ListSitesInput) (*ListSitesOutput, error) {
|
||||
pageSize := input.PageSize
|
||||
if pageSize == 0 {
|
||||
pageSize = 20 // Default page size
|
||||
}
|
||||
|
||||
sites, nextPageState, err := uc.repo.ListByTenant(ctx, tenantID, pageSize, input.PageState)
|
||||
if err != nil {
|
||||
uc.logger.Error("failed to list sites", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ListSitesOutput{
|
||||
Sites: sites,
|
||||
PageState: nextPageState,
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue