From a0570a055f3552ba4e456a0d7165f98cd1acacd3 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 29 Dec 2020 16:36:12 +0100 Subject: [PATCH] Schedule taken places --- .../com/plannaplan/services/GroupService.java | 13 ++++++++++++- .../controllers/CommisionController.java | 6 +++++- .../mappers/AssignmentResponseMappers.java | 18 ++++++++++++++++-- .../responses/models/AssignmentResponse.java | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java index c3e40ca..3499880 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.function.Function; +import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Groups; import com.plannaplan.repositories.GroupRepository; @@ -30,7 +31,7 @@ public class GroupService { return this.repo.find(time, room, capacity); } - public Optional find(Integer zajCykId, Integer nrGr ) { + public Optional find(Integer zajCykId, Integer nrGr) { return this.repo.find(zajCykId, nrGr); } @@ -64,6 +65,16 @@ public class GroupService { } + /** + * + * @param assingemnts list of assingemnts you want to get taken places ammount + * @return HashMap where Long is group id and Integer is how many + * places in gorup is already taken + */ + public HashMap getTakenPlacesOfAssignments(List assignments) { + return getTakenPlaces(assignments.stream().map(Assignment::getGroup).collect(Collectors.toList())); + } + /** * * @param groups list of groups you want to get taken places ammount diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 2f1053a..d052c69 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.ArrayList; +import java.util.HashMap; import com.plannaplan.responses.mappers.AssignmentResponseMappers; import com.plannaplan.responses.models.AssignmentResponse; @@ -127,7 +128,10 @@ public class CommisionController extends TokenBasedController { if (com.isPresent()) { List respone = this.assignmentService.getCommisionAssignments(com.get()); - return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK); + final HashMap ammounts = this.groupServcicxe + .getTakenPlacesOfAssignments(respone); + return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone, ammounts), + HttpStatus.OK); } return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java index 8ce1745..b5e4920 100755 --- a/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java @@ -14,6 +14,11 @@ import com.plannaplan.types.GroupType; public class AssignmentResponseMappers { public static final List mapToResponse(List assignments) { + return mapToResponse(assignments, null); + } + + public static final List mapToResponse(List assignments, + HashMap ammounts) { List response = new ArrayList<>(); HashMap> courses = new HashMap<>(); assignments.stream().forEach((Assignment assignment) -> { @@ -29,14 +34,23 @@ public class AssignmentResponseMappers { final Course course = entry.getKey(); final List courseGroups = entry.getValue(); if (courseGroups.size() == 1) { - response.add(new AssignmentResponse(course, courseGroups.get(0))); + if (ammounts != null) { + response.add(new AssignmentResponse(course, courseGroups.get(0), ammounts)); + } else { + response.add(new AssignmentResponse(course, courseGroups.get(0))); + } } if (courseGroups.size() == 2) { final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst() .get(); final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst() .get(); - response.add(new AssignmentResponse(course, lecture, classes)); + + if (ammounts != null) { + response.add(new AssignmentResponse(course, lecture, classes, ammounts)); + } else { + response.add(new AssignmentResponse(course, lecture, classes)); + } } } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java index e78b55d..313d6d7 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java @@ -1,5 +1,7 @@ package com.plannaplan.responses.models; +import java.util.HashMap; + import com.plannaplan.entities.Course; import com.plannaplan.entities.Groups; import com.plannaplan.types.GroupType; @@ -20,11 +22,23 @@ public class AssignmentResponse { this.classes = classes == null ? null : new GroupWithCapacityResponse(classes); } + public AssignmentResponse(Course course, Groups lecture, Groups classes, HashMap ammounts) { + this.id = course.getId(); + this.name = course.getName(); + this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getId())); + this.classes = classes == null ? null : new GroupWithCapacityResponse(classes, ammounts.get(classes.getId())); + } + public AssignmentResponse(Course course, Groups group) { this(course, group.getType() == GroupType.LECTURE ? group : null, group.getType() == GroupType.CLASS ? group : null); } + public AssignmentResponse(Course course, Groups group, HashMap ammounts) { + this(course, group.getType() == GroupType.LECTURE ? group : null, + group.getType() == GroupType.CLASS ? group : null, ammounts); + } + public GroupWithCapacityResponse getLecture() { return this.lecture; }