Group default response places overload
This commit is contained in:
parent
13eb8dae77
commit
593084aeba
@ -1,8 +1,10 @@
|
||||
package com.plannaplan.responses.mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
@ -12,8 +14,21 @@ import com.plannaplan.responses.models.GroupWithCapacityResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class GroupsMappers {
|
||||
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupDefaultResponse>() {
|
||||
@Override
|
||||
public GroupDefaultResponse apply(Groups p) {
|
||||
if (taken != null) {
|
||||
return new GroupDefaultResponse(p, taken.get(p.getId()));
|
||||
} else {
|
||||
return new GroupDefaultResponse(p);
|
||||
}
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(GroupDefaultResponse::new).collect(Collectors.toList());
|
||||
return GroupsMappers.mapToDefaultResponse(groups, null);
|
||||
}
|
||||
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups) {
|
||||
|
@ -2,7 +2,9 @@ package com.plannaplan.responses.mappers;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
@ -37,16 +39,43 @@ public class GroupsMappersTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToGetCourseGroupsResponse(){
|
||||
public void shouldMapToGetCourseGroupsResponse() {
|
||||
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")));
|
||||
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")));
|
||||
|
||||
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups);
|
||||
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
|
||||
.mapToGetCourseGroupsDefaultResponse(groups);
|
||||
|
||||
assertTrue(response.getClasses().size() == 1);
|
||||
assertTrue(response.getLectures().size() == 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToDefaultResponseWithTakenPlace()
|
||||
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<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(List.of(group1, group2),
|
||||
placeMap);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0).getTakenPlaces() == 5);
|
||||
assertTrue(response.get(1).getTakenPlaces() == 56);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user