From c263cff91aaefa0943d0a428ca5b1b1770541dda Mon Sep 17 00:00:00 2001 From: Jan Tymel <410388@mail.muni.cz> Date: Sat, 26 Dec 2020 18:12:21 +0100 Subject: [PATCH] Revert "Remove trainingDefinitionId parameter from LevelOperationsController" This reverts commit 446806888173a4b2fac7b5bce54b4232a77ba781. --- .../demo/controller/LevelOperationsController.java | 12 ++++++++---- .../example/demo/service/LevelOperationsService.java | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/controller/LevelOperationsController.java b/src/main/java/com/example/demo/controller/LevelOperationsController.java index 078b4cbd..792cd34d 100644 --- a/src/main/java/com/example/demo/controller/LevelOperationsController.java +++ b/src/main/java/com/example/demo/controller/LevelOperationsController.java @@ -18,10 +18,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/levels") +@RequestMapping("/{definitionId}/levels") @CrossOrigin(origins = "*", allowCredentials = "true", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) -@Api(value = "/levels", tags = {"Level operations"}) +@Api(value = "/{definitionId}/levels", tags = {"Level operations"}) public class LevelOperationsController { private final LevelOperationsService levelOperationsService; @@ -36,10 +36,12 @@ public class LevelOperationsController { @ApiResponses(value = {@ApiResponse(code = 200, message = "Level orders changed"), @ApiResponse(code = 500, message = "Unexpected application error")}) public void createInfoLevel( + @ApiParam(value = "Training definition ID", required = true) @PathVariable(name = "definitionId") + Long definitionId, @ApiParam(value = "Level ID - from", required = true) @PathVariable(name = "levelIdFrom") Long levelIdFrom, @ApiParam(value = "Level ID - to", required = true) @PathVariable(name = "levelIdTo") Long levelIdTo) { - levelOperationsService.swapLevelsOrder(levelIdFrom, levelIdTo); + levelOperationsService.swapLevelsOrder(definitionId, levelIdFrom, levelIdTo); } @DeleteMapping(value = "/{levelId}", produces = MediaType.APPLICATION_JSON_VALUE) @@ -47,7 +49,9 @@ public class LevelOperationsController { @ApiResponses(value = {@ApiResponse(code = 200, message = "Level deleted"), @ApiResponse(code = 500, message = "Unexpected application error")}) public void deleteLevel( + @ApiParam(value = "Training definition ID", required = true) @PathVariable(name = "definitionId") + Long definitionId, @ApiParam(value = "Level ID - from", required = true) @PathVariable(name = "levelId") Long levelId) { - levelOperationsService.deleteLevel(levelId); + levelOperationsService.deleteLevel(definitionId, levelId); } } diff --git a/src/main/java/com/example/demo/service/LevelOperationsService.java b/src/main/java/com/example/demo/service/LevelOperationsService.java index 6f8547ca..584c67d7 100644 --- a/src/main/java/com/example/demo/service/LevelOperationsService.java +++ b/src/main/java/com/example/demo/service/LevelOperationsService.java @@ -13,7 +13,7 @@ public class LevelOperationsService { @Autowired private BaseLevelRepository baseLevelRepository; - public void swapLevelsOrder(Long levelIdFrom, Long levelIdTo) { + public void swapLevelsOrder(Long trainingDefinitionId, Long levelIdFrom, Long levelIdTo) { Optional<BaseLevel> levelFrom = baseLevelRepository.findById(levelIdFrom); Optional<BaseLevel> levelTo = baseLevelRepository.findById(levelIdTo); @@ -32,7 +32,7 @@ public class LevelOperationsService { baseLevelRepository.save(levelTo.get()); } - public void deleteLevel(Long levelId) { + public void deleteLevel(Long trainingDefinitionId, Long levelId) { Optional<BaseLevel> levelEntity = baseLevelRepository.findById(levelId); if (levelEntity.isEmpty()) { -- GitLab