mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit addresses a broken build state caused by a mid-stream architectural refactoring. The changes align the existing code with the new Domain-Driven Design (DDD-lite) structure outlined in `refactor.md`. Key changes include: - Defined missing domain interfaces for `Auth`, `Localization`, and `Search`. - Refactored application services to use a `Commands` and `Queries` pattern. - Updated GraphQL resolvers to call application services instead of accessing repositories directly. - Fixed dependency injection in `cmd/api/main.go` by removing the non-existent `ApplicationBuilder` and manually instantiating services. - Corrected numerous test files (`integration`, `unit`, and `repository` tests) to reflect the new architecture, including fixing mock objects and test suite setups. - Added missing database migrations for test schemas to resolve "no such table" errors. This effort successfully gets the application to a compilable state and passes a significant portion of the test suite, laying the groundwork for further development and fixing the remaining test failures.
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package translation
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// TranslationCommands contains the command handlers for the translation aggregate.
|
|
type TranslationCommands struct {
|
|
repo domain.TranslationRepository
|
|
}
|
|
|
|
// NewTranslationCommands creates a new TranslationCommands handler.
|
|
func NewTranslationCommands(repo domain.TranslationRepository) *TranslationCommands {
|
|
return &TranslationCommands{repo: repo}
|
|
}
|
|
|
|
// CreateTranslationInput represents the input for creating a new translation.
|
|
type CreateTranslationInput struct {
|
|
Title string
|
|
Content string
|
|
Description string
|
|
Language string
|
|
Status domain.TranslationStatus
|
|
TranslatableID uint
|
|
TranslatableType string
|
|
TranslatorID *uint
|
|
IsOriginalLanguage bool
|
|
}
|
|
|
|
// CreateTranslation creates a new translation.
|
|
func (c *TranslationCommands) CreateTranslation(ctx context.Context, input CreateTranslationInput) (*domain.Translation, error) {
|
|
translation := &domain.Translation{
|
|
Title: input.Title,
|
|
Content: input.Content,
|
|
Description: input.Description,
|
|
Language: input.Language,
|
|
Status: input.Status,
|
|
TranslatableID: input.TranslatableID,
|
|
TranslatableType: input.TranslatableType,
|
|
TranslatorID: input.TranslatorID,
|
|
IsOriginalLanguage: input.IsOriginalLanguage,
|
|
}
|
|
err := c.repo.Create(ctx, translation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return translation, nil
|
|
}
|
|
|
|
// UpdateTranslationInput represents the input for updating an existing translation.
|
|
type UpdateTranslationInput struct {
|
|
ID uint
|
|
Title string
|
|
Content string
|
|
Description string
|
|
Language string
|
|
Status domain.TranslationStatus
|
|
}
|
|
|
|
// UpdateTranslation updates an existing translation.
|
|
func (c *TranslationCommands) UpdateTranslation(ctx context.Context, input UpdateTranslationInput) (*domain.Translation, error) {
|
|
translation, err := c.repo.GetByID(ctx, input.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
translation.Title = input.Title
|
|
translation.Content = input.Content
|
|
translation.Description = input.Description
|
|
translation.Language = input.Language
|
|
translation.Status = input.Status
|
|
err = c.repo.Update(ctx, translation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return translation, nil
|
|
}
|
|
|
|
// DeleteTranslation deletes a translation by ID.
|
|
func (c *TranslationCommands) DeleteTranslation(ctx context.Context, id uint) error {
|
|
return c.repo.Delete(ctx, id)
|
|
}
|