mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
Some checks failed
- Updated database models and repositories to replace uint IDs with UUIDs. - Modified test fixtures to generate and use UUIDs for authors, translations, users, and works. - Adjusted mock implementations to align with the new UUID structure. - Ensured all relevant functions and methods are updated to handle UUIDs correctly. - Added necessary imports for UUID handling in various files.
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package sql
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/platform/config"
|
|
|
|
"github.com/google/uuid"
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type userProfileRepository struct {
|
|
*BaseRepositoryImpl[domain.UserProfile]
|
|
db *gorm.DB
|
|
tracer trace.Tracer
|
|
}
|
|
|
|
// NewUserProfileRepository creates a new UserProfileRepository.
|
|
func NewUserProfileRepository(db *gorm.DB, cfg *config.Config) domain.UserProfileRepository {
|
|
return &userProfileRepository{
|
|
BaseRepositoryImpl: NewBaseRepositoryImpl[domain.UserProfile](db, cfg),
|
|
db: db,
|
|
tracer: otel.Tracer("user_profile.repository"),
|
|
}
|
|
}
|
|
|
|
// GetByUserID finds a user profile by user ID
|
|
func (r *userProfileRepository) GetByUserID(ctx context.Context, userID uuid.UUID) (*domain.UserProfile, error) {
|
|
ctx, span := r.tracer.Start(ctx, "GetByUserID")
|
|
defer span.End()
|
|
var profile domain.UserProfile
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).First(&profile).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, domain.ErrEntityNotFound
|
|
}
|
|
return nil, err
|
|
}
|
|
return &profile, nil
|
|
}
|