generated from VLADIMIR/template
up
This commit is contained in:
@@ -51,6 +51,20 @@ func (s *server) GetGameExport(ctx context.Context, req *proto.GetGameExportReq)
|
||||
return &proto.GameExportRsp{Export: mapGameExport(result)}, nil
|
||||
}
|
||||
|
||||
func (s *server) ResetGameLocalMode(ctx context.Context, req *proto.ResetGameLocalModeReq) (*proto.ResetGameLocalModeRsp, error) {
|
||||
claims, err := claimsFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !canExportGame(claims) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if err := s.gameExportService.ResetLocalMode(ctx, int(req.GetID()), req.GetExportID()); err != nil {
|
||||
return nil, gameExportErrorStatus(err)
|
||||
}
|
||||
return &proto.ResetGameLocalModeRsp{}, nil
|
||||
}
|
||||
|
||||
// GameExportDownloadHandler authenticates with the existing JWT processor and streams private ZIPs.
|
||||
func GameExportDownloadHandler(jwt processor_jwt.IProcessorJWT, exports *game_export_service.GameExportService) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -19,10 +19,12 @@ func gameExportErrorStatus(err error) error {
|
||||
return status.Error(codes.FailedPrecondition, game_export_service.ErrVenueMode.Error())
|
||||
case errors.Is(err, game_export_service.ErrNotReady):
|
||||
return status.Error(codes.FailedPrecondition, game_export_service.ErrNotReady.Error())
|
||||
case errors.Is(err, game_export_service.ErrNotExportable):
|
||||
return status.Error(codes.FailedPrecondition, game_export_service.ErrNotExportable.Error())
|
||||
case errors.Is(err, game_export_service.ErrExportChanged):
|
||||
return status.Error(codes.Aborted, game_export_service.ErrExportChanged.Error())
|
||||
case errors.Is(err, game_export_service.ErrInvalidGameID):
|
||||
return status.Error(codes.InvalidArgument, game_export_service.ErrInvalidGameID.Error())
|
||||
case errors.Is(err, game_export_service.ErrInvalidExportID):
|
||||
return status.Error(codes.InvalidArgument, game_export_service.ErrInvalidExportID.Error())
|
||||
default:
|
||||
log.Printf("game export API: %v", err)
|
||||
return status.Error(codes.Internal, "Не удалось выполнить операцию экспорта игры")
|
||||
|
||||
@@ -45,6 +45,10 @@ func TestExportRolesAndVenueMode(t *testing.T) {
|
||||
if status.Code(err) != tc.code {
|
||||
t.Fatalf("status access: %v", err)
|
||||
}
|
||||
_, err = server.ResetGameLocalMode(ctx, &proto.ResetGameLocalModeReq{ID: 1, ExportID: "export"})
|
||||
if status.Code(err) != tc.code {
|
||||
t.Fatalf("reset access: %v", err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodGet, "/api/games/1/export/download", nil)
|
||||
request.SetPathValue("id", "1")
|
||||
if tc.role != "" {
|
||||
@@ -71,7 +75,8 @@ func TestExportErrorsAreSafe(t *testing.T) {
|
||||
}{
|
||||
{"game missing", game_export_service.ErrGameNotFound, codes.NotFound},
|
||||
{"export missing", game_export_service.ErrExportNotFound, codes.NotFound},
|
||||
{"progress", game_export_service.ErrNotExportable, codes.FailedPrecondition},
|
||||
{"changed export", game_export_service.ErrExportChanged, codes.Aborted},
|
||||
{"invalid export", game_export_service.ErrInvalidExportID, codes.InvalidArgument},
|
||||
{"not ready", game_export_service.ErrNotReady, codes.FailedPrecondition},
|
||||
{"venue", game_export_service.ErrVenueMode, codes.FailedPrecondition},
|
||||
{"invalid game", game_export_service.ErrInvalidGameID, codes.InvalidArgument},
|
||||
|
||||
Reference in New Issue
Block a user