package contribution import ( "context" "tercul/internal/app/authz" "tercul/internal/domain" platform_auth "tercul/internal/platform/auth" ) // Commands contains the command handlers for the contribution aggregate. type Commands struct { repo domain.ContributionRepository authzSvc *authz.Service } // NewCommands creates a new Commands handler. func NewCommands(repo domain.ContributionRepository, authzSvc *authz.Service) *Commands { return &Commands{ repo: repo, authzSvc: authzSvc, } } // CreateContributionInput represents the input for creating a new contribution. type CreateContributionInput struct { Name string Status string WorkID *uint TranslationID *uint } // CreateContribution creates a new contribution. func (c *Commands) CreateContribution(ctx context.Context, input CreateContributionInput) (*domain.Contribution, error) { actorID, ok := platform_auth.GetUserIDFromContext(ctx) if !ok { return nil, domain.ErrUnauthorized } // TODO: Add authorization check using authzSvc if necessary contribution := &domain.Contribution{ Name: input.Name, Status: input.Status, UserID: actorID, WorkID: input.WorkID, TranslationID: input.TranslationID, } err := c.repo.Create(ctx, contribution) if err != nil { return nil, err } return contribution, nil }