generated from VLADIMIR/template
up
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"evening_detective_server/internal/services/map_service"
|
||||
proto "evening_detective_server/proto"
|
||||
@@ -22,7 +23,7 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
if err := s.mapService.Ensure(ctx, int(req.GameID), "organizer_desk", 1); err != nil {
|
||||
if err := s.mapService.Ensure(ctx, int(req.GameID), "organizer_desk", "1"); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось сохранить карту")
|
||||
}
|
||||
for _, team := range game.Teams {
|
||||
@@ -38,7 +39,7 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
return nil, status.Error(codes.Internal, "не удалось получить экраны")
|
||||
}
|
||||
for _, screen := range screens {
|
||||
if err := s.mapService.Ensure(ctx, int(req.GameID), "screen", screen.ID); err != nil {
|
||||
if err := s.mapService.Ensure(ctx, int(req.GameID), "screen", strconv.Itoa(screen.ID)); err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось сохранить карту")
|
||||
}
|
||||
}
|
||||
@@ -46,16 +47,16 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось получить карту")
|
||||
}
|
||||
teamNames := map[int]string{}
|
||||
teamNames := map[string]string{}
|
||||
for _, team := range game.Teams {
|
||||
if team.ParticipationStatus == "cancelled" {
|
||||
continue
|
||||
}
|
||||
teamNames[team.ID] = team.Name
|
||||
}
|
||||
screenStates := map[int]*proto.ScreenState{}
|
||||
screenStates := map[string]*proto.ScreenState{}
|
||||
for _, screen := range screens {
|
||||
screenStates[screen.ID] = screenState(screen)
|
||||
screenStates[strconv.Itoa(screen.ID)] = screenState(screen)
|
||||
}
|
||||
result := make([]*proto.MapItem, 0, len(items))
|
||||
for _, item := range items {
|
||||
@@ -66,7 +67,7 @@ func (s *server) GetGameMap(ctx context.Context, req *proto.GetGameMapReq) (*pro
|
||||
}
|
||||
continue
|
||||
}
|
||||
mapped := &proto.MapItem{Kind: item.Kind, ItemID: int32(item.ItemID), X: int32(item.X), Y: int32(item.Y), Hidden: item.Hidden}
|
||||
mapped := &proto.MapItem{Kind: item.Kind, ItemID: item.ItemID, X: int32(item.X), Y: int32(item.Y), Hidden: item.Hidden}
|
||||
if item.Kind == "team" {
|
||||
mapped.Label = teamNames[item.ItemID]
|
||||
}
|
||||
@@ -87,13 +88,13 @@ func (s *server) UpdateGameMapItem(ctx context.Context, req *proto.UpdateGameMap
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameID <= 0 || req.ItemID <= 0 || (req.Kind != "team" && req.Kind != "screen" && req.Kind != "organizer_desk") {
|
||||
if req == nil || req.GameID <= 0 || req.ItemID == "" || (req.Kind != "team" && req.Kind != "screen" && req.Kind != "organizer_desk") {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный объект карты")
|
||||
}
|
||||
if err := s.mapService.Update(ctx, &map_service.MapItem{
|
||||
GameID: int(req.GameID),
|
||||
Kind: req.Kind,
|
||||
ItemID: int(req.ItemID),
|
||||
ItemID: req.ItemID,
|
||||
X: int(req.X),
|
||||
Y: int(req.Y),
|
||||
Hidden: req.Hidden,
|
||||
|
||||
Reference in New Issue
Block a user