Checkpoint: ownedGroups.contains(groupId) and tests

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2021-01-10 10:57:33 +01:00
parent e24938dfce
commit c7feb10997
2 changed files with 72 additions and 6 deletions

View File

@ -3,6 +3,8 @@ package com.plannaplan.controllers;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import com.plannaplan.App;
import com.plannaplan.entities.Assignment;
@ -36,12 +38,6 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping("/api/" + App.API_VERSION + "/exchanges")
@Api(tags = { "Exchange" }, value = "Exchange", description = "Endpoint to exchange with accepted assignments.")
public class ExchangeController extends TokenBasedController{
/*
* Endpoint do wylistowania exchangow użytkownika
* Endpoint do usuwania exchanga
*/
@Autowired
private GroupService groupService;
@ -61,6 +57,11 @@ public class ExchangeController extends TokenBasedController{
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
final Long assignmentId = exchangeRequest.get("assignment");
final Long groupId = exchangeRequest.get("group");
final List<Long> ownedGroups = asker.getStudentRegisteredGrups().stream().map(Groups::getId).collect(Collectors.toList());
if(ownedGroups.contains(groupId)){
return new ResponseEntity<>("User has already got this group.", HttpStatus.BAD_REQUEST);
}
if(assignmentId == null || groupId == null ){
return new ResponseEntity<>("Some of values are missing", HttpStatus.BAD_REQUEST);