mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
- Core Go application with GraphQL API using gqlgen - Comprehensive data models for literary works, authors, translations - Repository pattern with caching layer - Authentication and authorization system - Linguistics analysis capabilities with multiple adapters - Vector search integration with Weaviate - Docker containerization support - Python data migration and analysis scripts - Clean architecture with proper separation of concerns - Production-ready configuration and middleware - Proper .gitignore excluding vendor/, database files, and build artifacts
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
"tercul/models"
|
|
)
|
|
|
|
// CountryRepository defines CRUD methods specific to Country.
|
|
type CountryRepository interface {
|
|
BaseRepository[models.Country]
|
|
GetByCode(ctx context.Context, code string) (*models.Country, error)
|
|
ListByContinent(ctx context.Context, continent string) ([]models.Country, error)
|
|
}
|
|
|
|
type countryRepository struct {
|
|
BaseRepository[models.Country]
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewCountryRepository creates a new CountryRepository.
|
|
func NewCountryRepository(db *gorm.DB) CountryRepository {
|
|
return &countryRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[models.Country](db),
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
// GetByCode finds a country by code
|
|
func (r *countryRepository) GetByCode(ctx context.Context, code string) (*models.Country, error) {
|
|
var country models.Country
|
|
if err := r.db.WithContext(ctx).Where("code = ?", code).First(&country).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, ErrEntityNotFound
|
|
}
|
|
return nil, err
|
|
}
|
|
return &country, nil
|
|
}
|
|
|
|
// ListByContinent finds countries by continent
|
|
func (r *countryRepository) ListByContinent(ctx context.Context, continent string) ([]models.Country, error) {
|
|
var countries []models.Country
|
|
if err := r.db.WithContext(ctx).Where("continent = ?", continent).Find(&countries).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return countries, nil
|
|
}
|