mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +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
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"tercul/models"
|
|
)
|
|
|
|
// BookmarkRepository defines CRUD methods specific to Bookmark.
|
|
type BookmarkRepository interface {
|
|
BaseRepository[models.Bookmark]
|
|
ListByUserID(ctx context.Context, userID uint) ([]models.Bookmark, error)
|
|
ListByWorkID(ctx context.Context, workID uint) ([]models.Bookmark, error)
|
|
}
|
|
|
|
type bookmarkRepository struct {
|
|
BaseRepository[models.Bookmark]
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewBookmarkRepository creates a new BookmarkRepository.
|
|
func NewBookmarkRepository(db *gorm.DB) BookmarkRepository {
|
|
return &bookmarkRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[models.Bookmark](db),
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
// ListByUserID finds bookmarks by user ID
|
|
func (r *bookmarkRepository) ListByUserID(ctx context.Context, userID uint) ([]models.Bookmark, error) {
|
|
var bookmarks []models.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 uint) ([]models.Bookmark, error) {
|
|
var bookmarks []models.Bookmark
|
|
if err := r.db.WithContext(ctx).Where("work_id = ?", workID).Find(&bookmarks).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return bookmarks, nil
|
|
}
|