Group capacity response places overload
This commit is contained in:
parent
593084aeba
commit
25e9571a06
@ -31,9 +31,25 @@ public class GroupsMappers {
|
||||
return GroupsMappers.mapToDefaultResponse(groups, null);
|
||||
}
|
||||
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups,
|
||||
HashMap<Long, Integer> taken) {
|
||||
// return
|
||||
// groups.stream().filter(Objects::nonNull).map(GroupWithCapacityResponse::new)
|
||||
// .collect(Collectors.toList());
|
||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupWithCapacityResponse>() {
|
||||
@Override
|
||||
public GroupWithCapacityResponse apply(Groups p) {
|
||||
if (taken != null) {
|
||||
return new GroupWithCapacityResponse(p, taken.get(p.getId()));
|
||||
} else {
|
||||
return new GroupWithCapacityResponse(p);
|
||||
}
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(GroupWithCapacityResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
return GroupsMappers.mapToCapacityResponse(groups, null);
|
||||
}
|
||||
|
||||
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||
|
@ -23,6 +23,10 @@ public class GroupWithCapacityResponse extends GroupDefaultResponse {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) {
|
||||
this(assignment.getGroup(), takenPlaces);
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
@ -78,4 +78,32 @@ public class GroupsMappersTest {
|
||||
assertTrue(response.get(1).getTakenPlaces() == 56);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToCapacityResponseWithTakenPlace()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
final Field reader = Groups.class.getDeclaredField("id");
|
||||
reader.setAccessible(true);
|
||||
|
||||
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
reader.set(group1, Long.valueOf(0));
|
||||
reader.set(group2, Long.valueOf(1));
|
||||
|
||||
final HashMap<Long, Integer> placeMap = new HashMap<>();
|
||||
placeMap.put(Long.valueOf(0), 5);
|
||||
placeMap.put(Long.valueOf(1), 56);
|
||||
|
||||
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(List.of(group1, group2),
|
||||
placeMap);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0).getTakenPlaces() == 5);
|
||||
assertTrue(response.get(0).getCapacity() == 150);
|
||||
assertTrue(response.get(1).getTakenPlaces() == 56);
|
||||
assertTrue(response.get(1).getCapacity() == 24);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user