Added capacioty to course/all

This commit is contained in:
Filip Izydorczyk 2020-12-29 15:32:09 +01:00
parent 389e934035
commit eecb1a6d36
2 changed files with 13 additions and 13 deletions

View File

@ -9,7 +9,7 @@ import com.plannaplan.entities.Course;
import com.plannaplan.responses.mappers.CoursesResponseMappers; import com.plannaplan.responses.mappers.CoursesResponseMappers;
import com.plannaplan.responses.models.CoursesDefaultResponse; import com.plannaplan.responses.models.CoursesDefaultResponse;
import com.plannaplan.responses.models.CoursesWithGroupsResponse; import com.plannaplan.responses.models.CoursesWithGroupsResponse;
import com.plannaplan.responses.models.GroupDefaultResponse; import com.plannaplan.responses.models.GroupWithCapacityResponse;
import com.plannaplan.services.CourseService; import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService; import com.plannaplan.services.GroupService;
import com.plannaplan.types.GroupType; import com.plannaplan.types.GroupType;
@ -53,16 +53,16 @@ public class CoursesController {
final List<CoursesWithGroupsResponse> response = new ArrayList<>(); final List<CoursesWithGroupsResponse> response = new ArrayList<>();
courses.forEach(course -> { courses.forEach(course -> {
final List<GroupDefaultResponse> lectures = new ArrayList<>(); final List<GroupWithCapacityResponse> lectures = new ArrayList<>();
final List<GroupDefaultResponse> classes = new ArrayList<>(); final List<GroupWithCapacityResponse> classes = new ArrayList<>();
final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups()); final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups());
course.getGroups().stream().forEach(group -> { course.getGroups().stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) { if (group.getType() == GroupType.CLASS) {
classes.add(new GroupDefaultResponse(group, ammounts.get(group.getId()))); classes.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
} else { } else {
lectures.add(new GroupDefaultResponse(group, ammounts.get(group.getId()))); lectures.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
} }
}); });

View File

@ -12,32 +12,32 @@ import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse") @ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse")
public class CoursesWithGroupsResponse extends CoursesResponse { public class CoursesWithGroupsResponse extends CoursesResponse {
private List<GroupDefaultResponse> lectures = new ArrayList<>(); private List<GroupWithCapacityResponse> lectures = new ArrayList<>();
private List<GroupDefaultResponse> classes = new ArrayList<>(); private List<GroupWithCapacityResponse> classes = new ArrayList<>();
public CoursesWithGroupsResponse(Course course) { public CoursesWithGroupsResponse(Course course) {
super(course); super(course);
course.getGroups().stream().forEach(group -> { course.getGroups().stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) { if (group.getType() == GroupType.CLASS) {
this.classes.add(new GroupDefaultResponse(group)); this.classes.add(new GroupWithCapacityResponse(group));
} else { } else {
this.lectures.add(new GroupDefaultResponse(group)); this.lectures.add(new GroupWithCapacityResponse(group));
} }
}); });
} }
public CoursesWithGroupsResponse(Course course, List<GroupDefaultResponse> lectures, public CoursesWithGroupsResponse(Course course, List<GroupWithCapacityResponse> lectures,
List<GroupDefaultResponse> classes) { List<GroupWithCapacityResponse> classes) {
super(course); super(course);
this.lectures = lectures; this.lectures = lectures;
this.classes = classes; this.classes = classes;
} }
public List<GroupDefaultResponse> getClasses() { public List<GroupWithCapacityResponse> getClasses() {
return this.classes; return this.classes;
} }
public List<GroupDefaultResponse> getLectures() { public List<GroupWithCapacityResponse> getLectures() {
return this.lectures; return this.lectures;
} }