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.
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package sql
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/platform/config"
|
|
|
|
"github.com/google/uuid"
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type copyrightClaimRepository struct {
|
|
domain.BaseRepository[domain.CopyrightClaim]
|
|
db *gorm.DB
|
|
tracer trace.Tracer
|
|
}
|
|
|
|
// NewCopyrightClaimRepository creates a new CopyrightClaimRepository.
|
|
func NewCopyrightClaimRepository(db *gorm.DB, cfg *config.Config) domain.CopyrightClaimRepository {
|
|
return ©rightClaimRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[domain.CopyrightClaim](db, cfg),
|
|
db: db,
|
|
tracer: otel.Tracer("copyright_claim.repository"),
|
|
}
|
|
}
|
|
|
|
// ListByWorkID finds claims by work ID
|
|
func (r *copyrightClaimRepository) ListByWorkID(ctx context.Context, workID uuid.UUID) ([]domain.CopyrightClaim, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByWorkID")
|
|
defer span.End()
|
|
var claims []domain.CopyrightClaim
|
|
if err := r.db.WithContext(ctx).Where("work_id = ?", workID).Find(&claims).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return claims, nil
|
|
}
|
|
|
|
// ListByUserID finds claims by user ID
|
|
func (r *copyrightClaimRepository) ListByUserID(ctx context.Context, userID uuid.UUID) ([]domain.CopyrightClaim, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByUserID")
|
|
defer span.End()
|
|
var claims []domain.CopyrightClaim
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).Find(&claims).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return claims, nil
|
|
}
|