endpointsd refactore

This commit is contained in:
Filip Izydorczyk 2020-12-10 16:34:42 +01:00
parent 7c457ce232
commit dfe534a835
2 changed files with 38 additions and 1 deletions

View File

@ -29,7 +29,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
@CrossOrigin @CrossOrigin
@RequestMapping("/api/" + App.API_VERSION + "/assignments") @RequestMapping("/api/" + App.API_VERSION + "/assignments")
@Api(tags = { @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 { public class AssignmentsController extends TokenBasedController {
@Autowired @Autowired
@ -40,6 +41,7 @@ public class AssignmentsController extends TokenBasedController {
@GetMapping("/user") @GetMapping("/user")
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.") @ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.")
@Deprecated
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception { public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
Optional<Commision> com = this.commisionService.getNewestCommision(user); Optional<Commision> com = this.commisionService.getNewestCommision(user);

View File

@ -35,6 +35,11 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList;
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
import com.plannaplan.responses.models.AssignmentResponse;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/api/" + App.API_VERSION + "/commisions") @RequestMapping("/api/" + App.API_VERSION + "/commisions")
@ -114,6 +119,20 @@ public class CommisionController extends TokenBasedController {
return new ResponseEntity<>(result, HttpStatus.OK); 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<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
Optional<Commision> com = this.commisionService.getNewestCommision(user);
if (com.isPresent()) {
List<Assignment> 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')") @PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping("/user/{id}") @GetMapping("/user/{id}")
@ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token") @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); 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<List<AssignmentResponse>> getCurrentAssignmentsDeanery(
@PathVariable(name = "id") Long userId) throws Exception {
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
Optional<Commision> com = this.commisionService.getNewestCommision(user);
if (com.isPresent()) {
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK);
}
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
}
} }