backend/restservice/src/main/java/com/plannaplan/responses/mappers/GroupsMappers.java

59 lines
2.1 KiB
Java
Raw Normal View History

package com.plannaplan.responses.mappers;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.plannaplan.entities.Groups;
import com.plannaplan.responses.models.GroupDefaultResponse;
import com.plannaplan.responses.models.CourseWithGroupsResponse;
import com.plannaplan.responses.models.GroupWithCapacityResponse;
import com.plannaplan.types.GroupType;
public class GroupsMappers {
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups) {
return groups.stream().filter(Objects::nonNull).map(GroupDefaultResponse::new).collect(Collectors.toList());
}
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups) {
return groups.stream().filter(Objects::nonNull).map(GroupWithCapacityResponse::new)
.collect(Collectors.toList());
}
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
List<Groups> groups) {
List<GroupDefaultResponse> lectures = new ArrayList<>();
List<GroupDefaultResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
classes.add(new GroupDefaultResponse(group));
} else {
lectures.add(new GroupDefaultResponse(group));
}
});
return new CourseWithGroupsResponse<>(classes, lectures);
}
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
List<Groups> groups) {
List<GroupWithCapacityResponse> lectures = new ArrayList<>();
List<GroupWithCapacityResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
classes.add(new GroupWithCapacityResponse(group));
} else {
lectures.add(new GroupWithCapacityResponse(group));
}
});
return new CourseWithGroupsResponse<>(classes, lectures);
}
}