tercul-backend/repositories/user_profile_repository.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- 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
2025-08-13 07:42:32 +02:00

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
}