mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
This commit addresses several high-priority tasks from the TASKS.md file, including: - **Fix Background Job Panic:** Replaced `log.Fatalf` with `log.Printf` in the `asynq` server to prevent crashes. - **Refactor API Server Setup:** Consolidated the GraphQL Playground and Prometheus metrics endpoints into the main API server. - **Implement `DeleteUser` Mutation:** Implemented the `DeleteUser` resolver. - **Implement `CreateContribution` Mutation:** Implemented the `CreateContribution` resolver and its required application service. Additionally, this commit includes a major refactoring of the configuration management system to fix a broken build. The global `config.Cfg` variable has been removed and replaced with a dependency injection approach, where the configuration object is passed to all components that require it. This change has been applied across the entire codebase, including the test suite, to ensure a stable and testable application.
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
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
|
|
} |