Bloc A - Code mort: - Suppression Studio (components, views, features) - Suppression gamification + services mock (projectService, storageService, gamificationService) - Mise à jour Sidebar, Navbar, locales Bloc B - Frontend: - Suppression modal.tsx deprecated, Modal.stories (doublon Dialog) - Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true - Suppression 19 tests orphelins, retrait exclusions vitest.config Bloc C - Backend: - Extraction routes_auth.go depuis router.go Bloc D - Rust: - Suppression security_legacy.rs (code mort, patterns déjà dans security/)
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
|
|
"veza-backend-api/internal/models"
|
|
)
|
|
|
|
// GearRepository defines the interface for gear item operations
|
|
type GearRepository interface {
|
|
Create(ctx context.Context, item *models.GearItem) error
|
|
GetByID(ctx context.Context, id uuid.UUID) (*models.GearItem, error)
|
|
ListByUserID(ctx context.Context, userID uuid.UUID) ([]*models.GearItem, error)
|
|
Update(ctx context.Context, item *models.GearItem) error
|
|
Delete(ctx context.Context, id uuid.UUID) error
|
|
}
|
|
|
|
type gearRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewGearRepository creates a new GearRepository
|
|
func NewGearRepository(db *gorm.DB) GearRepository {
|
|
return &gearRepository{db: db}
|
|
}
|
|
|
|
func (r *gearRepository) Create(ctx context.Context, item *models.GearItem) error {
|
|
return r.db.WithContext(ctx).Create(item).Error
|
|
}
|
|
|
|
func (r *gearRepository) GetByID(ctx context.Context, id uuid.UUID) (*models.GearItem, error) {
|
|
var item models.GearItem
|
|
if err := r.db.WithContext(ctx).First(&item, "id = ?", id).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &item, nil
|
|
}
|
|
|
|
func (r *gearRepository) ListByUserID(ctx context.Context, userID uuid.UUID) ([]*models.GearItem, error) {
|
|
var items []*models.GearItem
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).Find(&items).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
func (r *gearRepository) Update(ctx context.Context, item *models.GearItem) error {
|
|
return r.db.WithContext(ctx).Save(item).Error
|
|
}
|
|
|
|
func (r *gearRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
|
return r.db.WithContext(ctx).Delete(&models.GearItem{}, "id = ?", id).Error
|
|
}
|