Worked blocking accepted assignment

This commit is contained in:
Filip Izydorczyk
2021-01-16 16:29:24 +01:00
parent 2cfe0e7551
commit 98d6faf555
2 changed files with 22 additions and 24 deletions

View File

@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
import com.plannaplan.responses.models.AssignmentResponse;
@ -99,16 +100,37 @@ public class CommisionController extends TokenBasedController {
Assert.isTrue(!notExistingGroup.isPresent(), "Group "
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist");
final Optional<Commision> comPrev = this.commisionService.getNewestCommision(user);
final Commision com = new Commision(user, asker);
this.commisionService.save(com);
final List<Long> addedGroups = new ArrayList<>();
groups.stream().forEach((groupId) -> {
Groups group = this.groupServcicxe.getGroupById(groupId)
.orElseThrow(() -> new NullPointerException());
Assignment a = new Assignment(group, com);
this.assignmentService.save(a);
addedGroups.add(groupId);
});
boolean isBad = false;
if (comPrev.isPresent()) {
final Iterator<Assignment> it = comPrev.get().getAssignments().iterator();
while (it.hasNext() && !isBad) {
final Assignment a = it.next();
if (a.isAccepted() && !addedGroups.contains(a.getId())) {
isBad = true;
}
}
}
if (isBad) {
return new ResponseEntity<>("Error. You can't delete accepted assignmet",
HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>("Succes", HttpStatus.OK);
} catch (UserNotFoundException exception) {
return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND);