mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11: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.4 KiB
Go
50 lines
1.4 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 bookmarkRepository struct {
|
|
domain.BaseRepository[domain.Bookmark]
|
|
db *gorm.DB
|
|
tracer trace.Tracer
|
|
}
|
|
|
|
// NewBookmarkRepository creates a new BookmarkRepository.
|
|
func NewBookmarkRepository(db *gorm.DB, cfg *config.Config) domain.BookmarkRepository {
|
|
return &bookmarkRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[domain.Bookmark](db, cfg),
|
|
db: db,
|
|
tracer: otel.Tracer("bookmark.repository"),
|
|
}
|
|
}
|
|
|
|
// ListByUserID finds bookmarks by user ID
|
|
func (r *bookmarkRepository) ListByUserID(ctx context.Context, userID uuid.UUID) ([]domain.Bookmark, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByUserID")
|
|
defer span.End()
|
|
var bookmarks []domain.Bookmark
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).Find(&bookmarks).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return bookmarks, nil
|
|
}
|
|
|
|
// ListByWorkID finds bookmarks by work ID
|
|
func (r *bookmarkRepository) ListByWorkID(ctx context.Context, workID uuid.UUID) ([]domain.Bookmark, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByWorkID")
|
|
defer span.End()
|
|
var bookmarks []domain.Bookmark
|
|
if err := r.db.WithContext(ctx).Where("work_id = ?", workID).Find(&bookmarks).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return bookmarks, nil
|
|
}
|