Functionality done
This commit is contained in:
@ -2,6 +2,7 @@ package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,6 +18,7 @@ import com.plannaplan.responses.models.CommisionResponse;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -42,11 +44,25 @@ public class CommisionController extends TokenBasedController {
|
||||
public CommisionController() {
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<String> addCommision(@RequestBody List<Long> groups) throws UserNotFoundException {
|
||||
@PostMapping(value = { "/add", "/add/{id}" })
|
||||
public ResponseEntity<String> addCommision(@RequestBody List<Long> groups,
|
||||
@PathVariable(name = "id", required = false) Long userId) throws UserNotFoundException {
|
||||
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
Commision com = new Commision(user);
|
||||
|
||||
if (userId != null && !((user.getId() == userId) || (user.getRole() == UserRoles.DEANERY))) {
|
||||
return new ResponseEntity<>("Forbidden access atempt", HttpStatus.FORBIDDEN);
|
||||
} else if (userId != null) {
|
||||
user = userService.getById(userId).orElseThrow(() -> new UserNotFoundException("Given user id not exist"));
|
||||
}
|
||||
|
||||
final Long notExistingGroup = this.groupServcicxe.findNotExistingGroup(groups);
|
||||
if (notExistingGroup != Long.MIN_VALUE) {
|
||||
return new ResponseEntity<>("Group " + notExistingGroup.toString() + " doesn't exist",
|
||||
HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
final Commision com = new Commision(user);
|
||||
this.commisionService.save(com);
|
||||
|
||||
groups.stream().forEach((groupId) -> {
|
||||
|
@ -29,7 +29,7 @@ public class ConfigController {
|
||||
private ConfiguratorService contrl;
|
||||
|
||||
@PostMapping("/config")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
// @PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
|
||||
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user