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.
39 lines
1020 B
Go
39 lines
1020 B
Go
package sql
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain/localization"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type localizationRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewLocalizationRepository(db *gorm.DB) localization.LocalizationRepository {
|
|
return &localizationRepository{db: db}
|
|
}
|
|
|
|
func (r *localizationRepository) GetTranslation(ctx context.Context, key string, language string) (string, error) {
|
|
var l localization.Localization
|
|
err := r.db.WithContext(ctx).Where("key = ? AND language = ?", key, language).First(&l).Error
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return l.Value, nil
|
|
}
|
|
|
|
func (r *localizationRepository) GetTranslations(ctx context.Context, keys []string, language string) (map[string]string, error) {
|
|
var localizations []localization.Localization
|
|
err := r.db.WithContext(ctx).Where("key IN ? AND language = ?", keys, language).Find(&localizations).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := make(map[string]string)
|
|
for _, l := range localizations {
|
|
result[l.Key] = l.Value
|
|
}
|
|
return result, nil
|
|
}
|