Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
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/)
2026-02-14 16:23:32 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
|
|
"veza-backend-api/internal/models"
|
|
|
|
|
"veza-backend-api/internal/repositories"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GearService handles gear inventory business logic
|
|
|
|
|
type GearService struct {
|
|
|
|
|
repo repositories.GearRepository
|
|
|
|
|
logger *zap.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewGearService creates a new GearService
|
|
|
|
|
func NewGearService(repo repositories.GearRepository, logger *zap.Logger) *GearService {
|
|
|
|
|
return &GearService{repo: repo, logger: logger}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List returns all gear items for a user
|
|
|
|
|
func (s *GearService) List(ctx context.Context, userID uuid.UUID) ([]*models.GearItem, error) {
|
|
|
|
|
return s.repo.ListByUserID(ctx, userID)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 17:30:49 +00:00
|
|
|
// ListPublicGearByUsername returns public gear items for a given username
|
|
|
|
|
func (s *GearService) ListPublicGearByUsername(ctx context.Context, username string) ([]*models.GearItem, error) {
|
|
|
|
|
return s.repo.ListPublicByUsername(ctx, username)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Search returns gear items matching a query for a user
|
|
|
|
|
func (s *GearService) Search(ctx context.Context, userID uuid.UUID, query string) ([]*models.GearItem, error) {
|
|
|
|
|
return s.repo.SearchByUserID(ctx, userID, query)
|
|
|
|
|
}
|
|
|
|
|
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
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/)
2026-02-14 16:23:32 +00:00
|
|
|
// Get returns a single gear item by ID (with ownership check)
|
|
|
|
|
func (s *GearService) Get(ctx context.Context, id, userID uuid.UUID) (*models.GearItem, error) {
|
|
|
|
|
item, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if item.UserID != userID {
|
|
|
|
|
return nil, errors.New("gear item not found")
|
|
|
|
|
}
|
|
|
|
|
return item, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create creates a new gear item for a user
|
|
|
|
|
func (s *GearService) Create(ctx context.Context, userID uuid.UUID, item *models.GearItem) (*models.GearItem, error) {
|
|
|
|
|
if item.Name == "" {
|
|
|
|
|
return nil, errors.New("name is required")
|
|
|
|
|
}
|
|
|
|
|
item.UserID = userID
|
|
|
|
|
if err := s.repo.Create(ctx, item); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to create gear item: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return item, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update updates an existing gear item (with ownership check)
|
|
|
|
|
func (s *GearService) Update(ctx context.Context, id, userID uuid.UUID, item *models.GearItem) (*models.GearItem, error) {
|
|
|
|
|
existing, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if existing.UserID != userID {
|
|
|
|
|
return nil, errors.New("gear item not found")
|
|
|
|
|
}
|
|
|
|
|
item.ID = id
|
|
|
|
|
item.UserID = userID
|
|
|
|
|
if err := s.repo.Update(ctx, item); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to update gear item: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return item, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete deletes a gear item (with ownership check)
|
|
|
|
|
func (s *GearService) Delete(ctx context.Context, id, userID uuid.UUID) error {
|
|
|
|
|
existing, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if existing.UserID != userID {
|
|
|
|
|
return errors.New("gear item not found")
|
|
|
|
|
}
|
|
|
|
|
return s.repo.Delete(ctx, id)
|
|
|
|
|
}
|