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
|
|
@ -0,0 +1,46 @@
|
|||
package site
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
domainsite "codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/internal/domain/site"
|
||||
)
|
||||
|
||||
// ValidateDomainUseCase checks if a domain is available for registration
|
||||
type ValidateDomainUseCase struct {
|
||||
repo domainsite.Repository
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// ProvideValidateDomainUseCase creates a new ValidateDomainUseCase
|
||||
func ProvideValidateDomainUseCase(
|
||||
repo domainsite.Repository,
|
||||
logger *zap.Logger,
|
||||
) *ValidateDomainUseCase {
|
||||
return &ValidateDomainUseCase{
|
||||
repo: repo,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute validates if a domain can be used for a new site
|
||||
func (uc *ValidateDomainUseCase) Execute(ctx context.Context, domain string) error {
|
||||
// Check if domain already exists
|
||||
exists, err := uc.repo.DomainExists(ctx, domain)
|
||||
if err != nil {
|
||||
uc.logger.Error("failed to check domain existence",
|
||||
zap.String("domain", domain),
|
||||
zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if exists {
|
||||
uc.logger.Warn("domain already exists", zap.String("domain", domain))
|
||||
return domainsite.ErrDomainAlreadyExists
|
||||
}
|
||||
|
||||
uc.logger.Info("domain is available", zap.String("domain", domain))
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue