generated from VLADIMIR/template
up
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"evening_detective_server/internal/services/screen_plan_service"
|
||||
proto "evening_detective_server/proto"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *server) GetScreenPlan(ctx context.Context, req *proto.GetScreenPlanReq) (*proto.GetScreenPlanRsp, error) {
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
plan, err := s.screenPlanService.Get(ctx, int(req.GameID))
|
||||
if errors.Is(err, screen_plan_service.ErrPlanNotFound) {
|
||||
return &proto.GetScreenPlanRsp{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "не удалось получить план экранов")
|
||||
}
|
||||
return &proto.GetScreenPlanRsp{Plan: mapScreenPlan(plan)}, nil
|
||||
}
|
||||
|
||||
func (s *server) SaveScreenPlan(ctx context.Context, req *proto.SaveScreenPlanReq) (*proto.SaveScreenPlanRsp, error) {
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameID <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
plan, err := s.screenPlanService.Save(ctx, int(req.GameID), mapScreenPlanSteps(req.Steps), int(req.CurrentStep))
|
||||
if err != nil {
|
||||
return nil, screenPlanStatus(err, "не удалось сохранить план экранов")
|
||||
}
|
||||
return &proto.SaveScreenPlanRsp{Plan: mapScreenPlan(plan)}, nil
|
||||
}
|
||||
|
||||
func (s *server) SetScreenPlanStep(ctx context.Context, req *proto.SetScreenPlanStepReq) (*proto.SetScreenPlanStepRsp, error) {
|
||||
if !canManageScreens(ctx) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameID <= 0 || req.CurrentStep < 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный шаг плана экранов")
|
||||
}
|
||||
if _, err := s.gameService.GetGame(ctx, int(req.GameID)); err != nil {
|
||||
return nil, status.Error(codes.NotFound, "игра не найдена")
|
||||
}
|
||||
plan, err := s.screenPlanService.SetStep(ctx, int(req.GameID), int(req.CurrentStep))
|
||||
if err != nil {
|
||||
return nil, screenPlanStatus(err, "не удалось применить шаг плана экранов")
|
||||
}
|
||||
return &proto.SetScreenPlanStepRsp{Plan: mapScreenPlan(plan)}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user