From dfe534a8359a91e768c5074629ffb68d1428a864 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 10 Dec 2020 16:34:42 +0100 Subject: [PATCH] endpointsd refactore --- .../controllers/AssignmentsController.java | 4 ++- .../controllers/CommisionController.java | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java b/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java index 2f07c2a..06313e8 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/AssignmentsController.java @@ -29,7 +29,8 @@ import org.springframework.web.bind.annotation.RequestMapping; @CrossOrigin @RequestMapping("/api/" + App.API_VERSION + "/assignments") @Api(tags = { - "Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)") + "Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss). This comtroller is depreaceted. Use commission instead") +@Deprecated public class AssignmentsController extends TokenBasedController { @Autowired @@ -40,6 +41,7 @@ public class AssignmentsController extends TokenBasedController { @GetMapping("/user") @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") + @Deprecated public ResponseEntity> getCurrentAssignments() throws Exception { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); Optional com = this.commisionService.getNewestCommision(user); diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index b009fea..7ef71e2 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -35,6 +35,11 @@ import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import java.util.ArrayList; + +import com.plannaplan.responses.mappers.AssignmentResponseMappers; +import com.plannaplan.responses.models.AssignmentResponse; + @RestController @CrossOrigin @RequestMapping("/api/" + App.API_VERSION + "/commisions") @@ -114,6 +119,20 @@ public class CommisionController extends TokenBasedController { return new ResponseEntity<>(result, HttpStatus.OK); } + @GetMapping("/user/shedule") + @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") + public ResponseEntity> getCurrentAssignments() throws Exception { + User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); + Optional com = this.commisionService.getNewestCommision(user); + + if (com.isPresent()) { + List respone = this.assignmentService.getCommisionAssignments(com.get()); + return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK); + } + + return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); + } + @PreAuthorize("hasRole('ROLE_DEANERY')") @GetMapping("/user/{id}") @ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token") @@ -133,4 +152,20 @@ public class CommisionController extends TokenBasedController { return new ResponseEntity<>(result, HttpStatus.OK); } + @PreAuthorize("hasRole('ROLE_DEANERY')") + @GetMapping("/user/{id}/shedule") + @ApiOperation(value = "Return given user current assignemts (from newest commision). DEANERY Token needs to be provided.") + public ResponseEntity> getCurrentAssignmentsDeanery( + @PathVariable(name = "id") Long userId) throws Exception { + User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException()); + Optional com = this.commisionService.getNewestCommision(user); + + if (com.isPresent()) { + List respone = this.assignmentService.getCommisionAssignments(com.get()); + return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK); + } + + return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); + } + }