Merge pull request 'forntend-fixes' (#37) from forntend-fixes into master

Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/37
This commit is contained in:
Marcin Woźniak 2020-12-29 16:41:04 +01:00
commit 9f1e21a29f
6 changed files with 60 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.function.Function; import java.util.function.Function;
import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Groups; import com.plannaplan.entities.Groups;
import com.plannaplan.repositories.GroupRepository; import com.plannaplan.repositories.GroupRepository;
@ -30,7 +31,7 @@ public class GroupService {
return this.repo.find(time, room, capacity); return this.repo.find(time, room, capacity);
} }
public Optional<Groups> find(Integer zajCykId, Integer nrGr ) { public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
return this.repo.find(zajCykId, 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<Long, Integer> where Long is group id and Integer is how many
* places in gorup is already taken
*/
public HashMap<Long, Integer> getTakenPlacesOfAssignments(List<Assignment> assignments) {
return getTakenPlaces(assignments.stream().map(Assignment::getGroup).collect(Collectors.toList()));
}
/** /**
* *
* @param groups list of groups you want to get taken places ammount * @param groups list of groups you want to get taken places ammount

View File

@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import com.plannaplan.responses.mappers.AssignmentResponseMappers; import com.plannaplan.responses.mappers.AssignmentResponseMappers;
import com.plannaplan.responses.models.AssignmentResponse; import com.plannaplan.responses.models.AssignmentResponse;
@ -127,7 +128,10 @@ public class CommisionController extends TokenBasedController {
if (com.isPresent()) { if (com.isPresent()) {
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get()); List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK); final HashMap<Long, Integer> ammounts = this.groupServcicxe
.getTakenPlacesOfAssignments(respone);
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone, ammounts),
HttpStatus.OK);
} }
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);

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

@ -14,6 +14,11 @@ import com.plannaplan.types.GroupType;
public class AssignmentResponseMappers { public class AssignmentResponseMappers {
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) { public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) {
return mapToResponse(assignments, null);
}
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments,
HashMap<Long, Integer> ammounts) {
List<AssignmentResponse> response = new ArrayList<>(); List<AssignmentResponse> response = new ArrayList<>();
HashMap<Course, List<Groups>> courses = new HashMap<>(); HashMap<Course, List<Groups>> courses = new HashMap<>();
assignments.stream().forEach((Assignment assignment) -> { assignments.stream().forEach((Assignment assignment) -> {
@ -29,14 +34,23 @@ public class AssignmentResponseMappers {
final Course course = entry.getKey(); final Course course = entry.getKey();
final List<Groups> courseGroups = entry.getValue(); final List<Groups> courseGroups = entry.getValue();
if (courseGroups.size() == 1) { 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) { if (courseGroups.size() == 2) {
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst() final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
.get(); .get();
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst() final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
.get(); .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));
}
} }
} }

View File

@ -1,5 +1,7 @@
package com.plannaplan.responses.models; package com.plannaplan.responses.models;
import java.util.HashMap;
import com.plannaplan.entities.Course; import com.plannaplan.entities.Course;
import com.plannaplan.entities.Groups; import com.plannaplan.entities.Groups;
import com.plannaplan.types.GroupType; import com.plannaplan.types.GroupType;
@ -20,11 +22,23 @@ public class AssignmentResponse {
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes); this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
} }
public AssignmentResponse(Course course, Groups lecture, Groups classes, HashMap<Long, Integer> 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) { public AssignmentResponse(Course course, Groups group) {
this(course, group.getType() == GroupType.LECTURE ? group : null, this(course, group.getType() == GroupType.LECTURE ? group : null,
group.getType() == GroupType.CLASS ? group : null); group.getType() == GroupType.CLASS ? group : null);
} }
public AssignmentResponse(Course course, Groups group, HashMap<Long, Integer> ammounts) {
this(course, group.getType() == GroupType.LECTURE ? group : null,
group.getType() == GroupType.CLASS ? group : null, ammounts);
}
public GroupWithCapacityResponse getLecture() { public GroupWithCapacityResponse getLecture() {
return this.lecture; return this.lecture;
} }

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;
} }