Vhevkpoint implemented but stiull some errors

This commit is contained in:
BuildTools 2020-11-30 13:22:53 +01:00
parent 082b30133c
commit 78ed2f75f3
3 changed files with 53 additions and 5 deletions

View File

@ -41,10 +41,15 @@ public class GroupController {
@RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity, @RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity,
@RequestParam(name = "takenPlaces", defaultValue = "false") @ApiParam(value = "Boolean if we want to have respoonse with information about taken places by other students") Boolean takenPlaces) { @RequestParam(name = "takenPlaces", defaultValue = "false") @ApiParam(value = "Boolean if we want to have respoonse with information about taken places by other students") Boolean takenPlaces) {
List<Groups> groups = this.groupService.getGroupsByCourse(id); List<Groups> groups = this.groupService.getGroupsByCourse(id);
HashMap<Long, Integer> ammounts;
if (takenPlaces) { if (takenPlaces) {
ammounts = this.groupService.getTakenPlaces(groups); HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(groups);
if (capacity) {
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups, ammounts),
HttpStatus.OK);
}
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups, ammounts),
HttpStatus.OK);
} }
if (capacity) { if (capacity) {

View File

@ -80,20 +80,34 @@ public class GroupsMappers {
} }
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse( public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
List<Groups> groups) { List<Groups> groups, HashMap<Long, Integer> taken) {
List<GroupWithCapacityResponse> lectures = new ArrayList<>(); List<GroupWithCapacityResponse> lectures = new ArrayList<>();
List<GroupWithCapacityResponse> classes = new ArrayList<>(); List<GroupWithCapacityResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> { groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) { if (group.getType() == GroupType.CLASS) {
classes.add(new GroupWithCapacityResponse(group)); if (taken != null) {
classes.add(new GroupWithCapacityResponse(group, taken.get(group.getId())));
} else {
classes.add(new GroupWithCapacityResponse(group));
}
} else { } else {
lectures.add(new GroupWithCapacityResponse(group)); if (taken != null) {
lectures.add(new GroupWithCapacityResponse(group, taken.get(group.getId())));
} else {
lectures.add(new GroupWithCapacityResponse(group));
}
} }
}); });
return new CourseWithGroupsResponse<>(classes, lectures); return new CourseWithGroupsResponse<>(classes, lectures);
} }
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
List<Groups> groups) {
return GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups, null);
}
} }

View File

@ -81,6 +81,35 @@ public class GroupsMappersTest {
assertTrue(response.getClasses().get(0).getTakenPlaces() == 21); assertTrue(response.getClasses().get(0).getTakenPlaces() == 21);
} }
@Test
public void shouldMapToGetCourseCapacityGroupsResponseWithTakenPlaces() throws NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException {
final Field reader = Groups.class.getDeclaredField("id");
reader.setAccessible(true);
final List<Groups> groups = Arrays.asList(
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki")),
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki")));
reader.set(groups.get(0), Long.valueOf(0));
reader.set(groups.get(1), Long.valueOf(1));
final HashMap<Long, Integer> placeMap = new HashMap<>();
placeMap.put(Long.valueOf(0), 0);
placeMap.put(Long.valueOf(1), 21);
final CourseWithGroupsResponse<GroupWithCapacityResponse> response = GroupsMappers
.mapToGetCourseGroupsWithCapacityResponse(groups, placeMap);
assertTrue(response.getClasses().size() == 1);
assertTrue(response.getLectures().size() == 1);
assertTrue(response.getLectures().get(0).getTakenPlaces() == 0);
assertTrue(response.getLectures().get(0).getCapacity() == 150);
assertTrue(response.getClasses().get(0).getTakenPlaces() == 21);
assertTrue(response.getClasses().get(0).getCapacity() == 24);
}
@Test @Test
public void shouldMapToDefaultResponseWithTakenPlace() throws NoSuchFieldException, SecurityException, public void shouldMapToDefaultResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException { IllegalArgumentException, IllegalAccessException {