2020-09-30 19:15:32 +02:00
|
|
|
package com.plannaplan.controllers;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2020-11-04 16:40:02 +01:00
|
|
|
import io.swagger.annotations.Api;
|
2020-11-04 16:58:26 +01:00
|
|
|
import io.swagger.annotations.ApiOperation;
|
2020-11-04 16:40:02 +01:00
|
|
|
|
2020-11-05 16:14:50 +01:00
|
|
|
import java.util.ArrayList;
|
2020-09-30 19:15:32 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import com.plannaplan.App;
|
|
|
|
import com.plannaplan.entities.Assignment;
|
|
|
|
import com.plannaplan.entities.Commision;
|
|
|
|
import com.plannaplan.entities.User;
|
2020-10-08 16:41:13 +02:00
|
|
|
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
|
2020-10-13 17:07:04 +02:00
|
|
|
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
2020-09-30 19:15:32 +02:00
|
|
|
import com.plannaplan.services.AssignmentService;
|
|
|
|
import com.plannaplan.services.CommisionService;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
2020-11-04 16:40:02 +01:00
|
|
|
@Api(tags = {
|
|
|
|
"Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)")
|
2020-09-30 19:15:32 +02:00
|
|
|
public class AssignmentsController extends TokenBasedController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CommisionService commisionService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private AssignmentService assignmentService;
|
|
|
|
|
2020-10-30 16:42:57 +01:00
|
|
|
@GetMapping("/user")
|
2020-11-05 16:14:50 +01:00
|
|
|
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.")
|
2020-10-13 17:07:04 +02:00
|
|
|
public ResponseEntity<List<GetCurrentAssignmentsResponse>> getCurrentAssignments() throws Exception {
|
2020-10-08 16:41:13 +02:00
|
|
|
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
|
2020-09-30 19:15:32 +02:00
|
|
|
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
2020-10-08 16:41:13 +02:00
|
|
|
|
2020-09-30 19:15:32 +02:00
|
|
|
if (com.isPresent()) {
|
|
|
|
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
|
2020-10-13 17:13:43 +02:00
|
|
|
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK);
|
2020-09-30 19:15:32 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 16:14:50 +01:00
|
|
|
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
2020-09-30 19:15:32 +02:00
|
|
|
}
|
|
|
|
}
|