generated from VLADIMIR/template
updates
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package map_service
|
||||
|
||||
import "evening_detective_server/internal/repos/game_map_repo"
|
||||
|
||||
type MapItem struct {
|
||||
GameID int
|
||||
Kind string
|
||||
ItemID int
|
||||
X int
|
||||
Y int
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
func mapItem(item game_map_repo.Item) *MapItem {
|
||||
return &MapItem{
|
||||
GameID: item.GameID,
|
||||
Kind: item.Kind,
|
||||
ItemID: item.ItemID,
|
||||
X: item.X,
|
||||
Y: item.Y,
|
||||
Hidden: item.Hidden,
|
||||
}
|
||||
}
|
||||
|
||||
func toRepoItem(item *MapItem) game_map_repo.Item {
|
||||
return game_map_repo.Item{
|
||||
GameID: item.GameID,
|
||||
Kind: item.Kind,
|
||||
ItemID: item.ItemID,
|
||||
X: item.X,
|
||||
Y: item.Y,
|
||||
Hidden: item.Hidden,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user