package map_service import ( "context" "errors" "evening_detective_server/internal/repos/game_map_repo" ) var ErrItemNotFound = errors.New("объект карты не найден") type MapService struct { repo *game_map_repo.Repo } func NewMapService(repo *game_map_repo.Repo) *MapService { return &MapService{repo: repo} } func (s *MapService) Ensure(ctx context.Context, gameID int, kind string, itemID int) error { return s.repo.Ensure(ctx, gameID, kind, itemID) } func (s *MapService) List(ctx context.Context, gameID int) ([]*MapItem, error) { items, err := s.repo.List(ctx, gameID) if err != nil { return nil, err } result := make([]*MapItem, 0, len(items)) for _, item := range items { result = append(result, mapItem(item)) } return result, nil } func (s *MapService) Update(ctx context.Context, item *MapItem) error { if err := s.repo.Update(ctx, toRepoItem(item)); err != nil { if errors.Is(err, game_map_repo.ErrItemNotFound) { return ErrItemNotFound } return err } return nil } func (s *MapService) Delete(ctx context.Context, item *MapItem) error { return s.repo.Delete(ctx, toRepoItem(item)) }