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
65
cloud/maplefile-backend/internal/usecase/collection/get.go
Normal file
65
cloud/maplefile-backend/internal/usecase/collection/get.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// monorepo/cloud/backend/internal/maplefile/usecase/collection/get.go
|
||||
package collection
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
dom_collection "codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/domain/collection"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/pkg/httperror"
|
||||
)
|
||||
|
||||
type GetCollectionUseCase interface {
|
||||
Execute(ctx context.Context, id gocql.UUID) (*dom_collection.Collection, error)
|
||||
}
|
||||
|
||||
type getCollectionUseCaseImpl struct {
|
||||
config *config.Configuration
|
||||
logger *zap.Logger
|
||||
repo dom_collection.CollectionRepository
|
||||
}
|
||||
|
||||
func NewGetCollectionUseCase(
|
||||
config *config.Configuration,
|
||||
logger *zap.Logger,
|
||||
repo dom_collection.CollectionRepository,
|
||||
) GetCollectionUseCase {
|
||||
logger = logger.Named("GetCollectionUseCase")
|
||||
return &getCollectionUseCaseImpl{config, logger, repo}
|
||||
}
|
||||
|
||||
func (uc *getCollectionUseCaseImpl) Execute(ctx context.Context, id gocql.UUID) (*dom_collection.Collection, error) {
|
||||
//
|
||||
// STEP 1: Validation.
|
||||
//
|
||||
|
||||
e := make(map[string]string)
|
||||
if id.String() == "" {
|
||||
e["id"] = "Collection ID is required"
|
||||
}
|
||||
if len(e) != 0 {
|
||||
uc.logger.Warn("Failed validating collection retrieval",
|
||||
zap.Any("error", e))
|
||||
return nil, httperror.NewForBadRequest(&e)
|
||||
}
|
||||
|
||||
//
|
||||
// STEP 2: Get from database.
|
||||
//
|
||||
|
||||
collection, err := uc.repo.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if collection == nil {
|
||||
uc.logger.Debug("Collection not found",
|
||||
zap.Any("id", id))
|
||||
return nil, httperror.NewForNotFoundWithSingleField("message", "Collection not found")
|
||||
}
|
||||
|
||||
return collection, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue