diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java index 4d1582b..65ab5c8 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java @@ -14,7 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** - * Service of GroupService which can find(optional), get(By Course, Groups Ammount, Group By Id, find Not Existing Group), save, delete group. + * Service of GroupService which can find(optional), get(By Course, Groups + * Ammount, Group By Id, find Not Existing Group), save, delete group. */ @Service @@ -68,6 +69,10 @@ public class GroupService { public HashMap getTakenPlaces(List groups) { HashMap response = new HashMap<>(); + if (groups.size() == 0) { + return response; + } + List respoonses = this.repo .getAssignedAmounts(groups.stream().filter(Objects::nonNull).map(new Function() { @Override diff --git a/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java b/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java index 5e9243d..18e0f48 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java @@ -1,5 +1,7 @@ package com.plannaplan.controllers; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import com.plannaplan.App; @@ -7,7 +9,10 @@ import com.plannaplan.entities.Course; import com.plannaplan.responses.mappers.CoursesResponseMappers; import com.plannaplan.responses.models.CoursesDefaultResponse; import com.plannaplan.responses.models.CoursesWithGroupsResponse; +import com.plannaplan.responses.models.GroupDefaultResponse; import com.plannaplan.services.CourseService; +import com.plannaplan.services.GroupService; +import com.plannaplan.types.GroupType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -33,12 +38,40 @@ public class CoursesController { @Autowired private CourseService courseService; + @Autowired + private GroupService groupService; + @GetMapping("/all") @ApiOperation(value = "Return all courses") public ResponseEntity> getMethodName( - @RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if you want to have resopnse with associated groups or without") Boolean groups) { + @RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if you want to have resopnse with associated groups or without") Boolean groups, + @RequestParam(name = "takenPlaces", defaultValue = "false") @ApiParam(value = "Boolean if we want to have respoonse with information about taken places by other students. Needs to be set groups true first") Boolean takenPlaces) { List courses = this.courseService.getAllCourses(); if (groups) { + if (takenPlaces) { + + final List response = new ArrayList<>(); + + courses.forEach(course -> { + final List lectures = new ArrayList<>(); + final List classes = new ArrayList<>(); + + final HashMap ammounts = this.groupService.getTakenPlaces(course.getGroups()); + + course.getGroups().stream().forEach(group -> { + if (group.getType() == GroupType.CLASS) { + classes.add(new GroupDefaultResponse(group, ammounts.get(group.getId()))); + } else { + lectures.add(new GroupDefaultResponse(group, ammounts.get(group.getId()))); + } + }); + + response.add(new CoursesWithGroupsResponse(course, lectures, classes)); + }); + + return new ResponseEntity<>(response, HttpStatus.OK); + } + final List response = CoursesResponseMappers .mapToGetCoursesWithGroupsResponse(courses); return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java index 188565a..864618a 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java @@ -26,6 +26,13 @@ public class CoursesWithGroupsResponse extends CoursesResponse { }); } + public CoursesWithGroupsResponse(Course course, List lectures, + List classes) { + super(course); + this.lectures = lectures; + this.classes = classes; + } + public List getClasses() { return this.classes; }