generated from VLADIMIR/template
fix
This commit is contained in:
@@ -3,6 +3,7 @@ package map_service
|
||||
|
||||
import "evening_detective_server/internal/repos/game_map_repo"
|
||||
|
||||
// MapItem describes an item placed on a game map.
|
||||
type MapItem struct {
|
||||
GameID int
|
||||
Kind string
|
||||
|
||||
@@ -7,20 +7,25 @@ import (
|
||||
"evening_detective_server/internal/repos/game_map_repo"
|
||||
)
|
||||
|
||||
// ErrItemNotFound indicates that a map item was not found.
|
||||
var ErrItemNotFound = errors.New("объект карты не найден")
|
||||
|
||||
// MapService handles game map items.
|
||||
type MapService struct {
|
||||
repo *game_map_repo.Repo
|
||||
}
|
||||
|
||||
// NewMapService creates a map service.
|
||||
func NewMapService(repo *game_map_repo.Repo) *MapService {
|
||||
return &MapService{repo: repo}
|
||||
}
|
||||
|
||||
// Ensure creates a map item if it does not exist.
|
||||
func (s *MapService) Ensure(ctx context.Context, gameID int, kind string, itemID int) error {
|
||||
return s.repo.Ensure(ctx, gameID, kind, itemID)
|
||||
}
|
||||
|
||||
// List returns map items for a game.
|
||||
func (s *MapService) List(ctx context.Context, gameID int) ([]*MapItem, error) {
|
||||
items, err := s.repo.List(ctx, gameID)
|
||||
if err != nil {
|
||||
@@ -33,6 +38,7 @@ func (s *MapService) List(ctx context.Context, gameID int) ([]*MapItem, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Update changes a map item's position and visibility.
|
||||
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) {
|
||||
@@ -43,6 +49,7 @@ func (s *MapService) Update(ctx context.Context, item *MapItem) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete removes a map item.
|
||||
func (s *MapService) Delete(ctx context.Context, item *MapItem) error {
|
||||
return s.repo.Delete(ctx, toRepoItem(item))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user