commision controller not deleting fix

This commit is contained in:
Filip Izydorczyk 2021-01-19 09:32:57 +01:00
parent 5ec41fa5d0
commit 06fb41b5dd
2 changed files with 16 additions and 3 deletions

View File

@ -106,4 +106,12 @@ public class AssignmentService {
this.emailService.sendAcceptationResult(e, new EmailAcceptedData(accepted, removed));
});
}
/**
* @param toSave list of entites to save to db
* @return list of assignments entities with ids from db
*/
public List<Assignment> saveAll(List<Assignment> toSave) {
return this.repo.saveAll(toSave);
}
}

View File

@ -110,14 +110,16 @@ public class CommisionController extends TokenBasedController {
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<>();
final List<Assignment> addedAssignments = 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);
addedAssignments.add(a);
// this.assignmentService.save(a);
addedGroups.add(groupId);
});
@ -127,7 +129,7 @@ public class CommisionController extends TokenBasedController {
while (it.hasNext() && !isBad) {
final Assignment a = it.next();
if (a.isAccepted() && !addedGroups.contains(a.getId())) {
if (a.isAccepted() && !addedGroups.contains(a.getGroup().getId())) {
isBad = true;
}
}
@ -139,6 +141,9 @@ public class CommisionController extends TokenBasedController {
HttpStatus.BAD_REQUEST);
}
this.commisionService.save(com);
this.assignmentService.saveAll(addedAssignments);
return new ResponseEntity<>("Succes", HttpStatus.OK);
} catch (UserNotFoundException exception) {
return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND);