54 lines
2.1 KiB
Java
Executable File
54 lines
2.1 KiB
Java
Executable File
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;
|
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
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;
|
|
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
|
|
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
|
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")
|
|
@Api(tags = {
|
|
"Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)")
|
|
public class AssignmentsController extends TokenBasedController {
|
|
|
|
@Autowired
|
|
private CommisionService commisionService;
|
|
|
|
@Autowired
|
|
private AssignmentService assignmentService;
|
|
|
|
@GetMapping("/user")
|
|
@ApiOperation(value = "Retrun user current assignemts (from newest commision). STUDENT Token needs to be provided.")
|
|
public ResponseEntity<List<GetCurrentAssignmentsResponse>> 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<>(null, HttpStatus.OK);
|
|
}
|
|
}
|