mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +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
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
"tercul/models"
|
|
)
|
|
|
|
// UserProfileRepository defines CRUD methods specific to UserProfile.
|
|
type UserProfileRepository interface {
|
|
BaseRepository[models.UserProfile]
|
|
GetByUserID(ctx context.Context, userID uint) (*models.UserProfile, error)
|
|
}
|
|
|
|
type userProfileRepository struct {
|
|
BaseRepository[models.UserProfile]
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewUserProfileRepository creates a new UserProfileRepository.
|
|
func NewUserProfileRepository(db *gorm.DB) UserProfileRepository {
|
|
return &userProfileRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[models.UserProfile](db),
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
// GetByUserID finds a user profile by user ID
|
|
func (r *userProfileRepository) GetByUserID(ctx context.Context, userID uint) (*models.UserProfile, error) {
|
|
var profile models.UserProfile
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).First(&profile).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, ErrEntityNotFound
|
|
}
|
|
return nil, err
|
|
}
|
|
return &profile, nil
|
|
}
|