generated from VLADIMIR/template
fix
This commit is contained in:
+16
-9
@@ -2,8 +2,10 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"evening_detective_server/internal/modules/roles"
|
||||
"evening_detective_server/internal/services/team_service"
|
||||
proto "evening_detective_server/proto"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -27,9 +29,7 @@ func (s *server) AddTeam(ctx context.Context, req *proto.AddTeamReq) (*proto.Add
|
||||
req.CaptainEmail,
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.AddTeamRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
return nil, teamErrorStatus(err, "не удалось добавить команду")
|
||||
}
|
||||
|
||||
return &proto.AddTeamRsp{
|
||||
@@ -53,9 +53,7 @@ func (s *server) UpdateTeam(ctx context.Context, req *proto.UpdateTeamReq) (*pro
|
||||
req.Name,
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.UpdateTeamRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
return nil, teamErrorStatus(err, "не удалось изменить команду")
|
||||
}
|
||||
|
||||
return &proto.UpdateTeamRsp{}, nil
|
||||
@@ -75,14 +73,23 @@ func (s *server) DeleteTeam(ctx context.Context, req *proto.DeleteTeamReq) (*pro
|
||||
int(req.ID),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.DeleteTeamRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
return nil, teamErrorStatus(err, "не удалось удалить команду")
|
||||
}
|
||||
|
||||
return &proto.DeleteTeamRsp{}, nil
|
||||
}
|
||||
|
||||
func teamErrorStatus(err error, internalMessage string) error {
|
||||
switch {
|
||||
case errors.Is(err, team_service.ErrGameNotFound), errors.Is(err, team_service.ErrTeamNotFound):
|
||||
return status.Error(codes.NotFound, err.Error())
|
||||
case errors.Is(err, team_service.ErrInvalidCaptainEmail):
|
||||
return status.Error(codes.InvalidArgument, err.Error())
|
||||
default:
|
||||
return status.Error(codes.Internal, internalMessage)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *server) GiveTeamApplications(ctx context.Context, req *proto.GiveTeamApplicationsReq) (*proto.GiveTeamApplicationsRsp, error) {
|
||||
claims, claimsErr := claimsFromContext(ctx)
|
||||
if claimsErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user