Initial commit: Open sourcing all of the Maple Open Technologies code.

This commit is contained in:
Bartlomiej Mika 2025-12-02 14:33:08 -05:00
commit 755d54a99d
2010 changed files with 448675 additions and 0 deletions

View file

@ -0,0 +1,52 @@
// monorepo/cloud/backend/internal/maplefile/usecase/filemetadata/check_exists.go
package filemetadata
import (
"go.uber.org/zap"
"github.com/gocql/gocql"
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
dom_file "codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/domain/file"
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/pkg/httperror"
)
type CheckFileExistsUseCase interface {
Execute(id gocql.UUID) (bool, error)
}
type checkFileExistsUseCaseImpl struct {
config *config.Configuration
logger *zap.Logger
repo dom_file.FileMetadataRepository
}
func NewCheckFileExistsUseCase(
config *config.Configuration,
logger *zap.Logger,
repo dom_file.FileMetadataRepository,
) CheckFileExistsUseCase {
logger = logger.Named("CheckFileExistsUseCase")
return &checkFileExistsUseCaseImpl{config, logger, repo}
}
func (uc *checkFileExistsUseCaseImpl) Execute(id gocql.UUID) (bool, error) {
//
// STEP 1: Validation.
//
e := make(map[string]string)
if id.String() == "" {
e["id"] = "File ID is required"
}
if len(e) != 0 {
uc.logger.Warn("Failed validating file existence check",
zap.Any("error", e))
return false, httperror.NewForBadRequest(&e)
}
//
// STEP 2: Check existence in database.
//
return uc.repo.CheckIfExistsByID(id)
}