diff --git a/src/main/java/in/koreatech/koin/domain/bus/dto/ShuttleBusRoutesResponse.java b/src/main/java/in/koreatech/koin/domain/bus/dto/ShuttleBusRoutesResponse.java index c6139141e..2665ecc3d 100644 --- a/src/main/java/in/koreatech/koin/domain/bus/dto/ShuttleBusRoutesResponse.java +++ b/src/main/java/in/koreatech/koin/domain/bus/dto/ShuttleBusRoutesResponse.java @@ -2,9 +2,7 @@ import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; -import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -16,34 +14,44 @@ @JsonNaming(SnakeCaseStrategy.class) @Schema(description = "셔틀버스 경로 응답") public record ShuttleBusRoutesResponse( - @Schema(description = "순환 노선 경로 목록") - List shuttleRoutes, - - @Schema(description = "주중 노선 경로 목록") - List commutingRoutes, - - @Schema(description = "주말 노선 경로 목록") - List weekendRoutes, + @Schema(description = "노선 지역 분류 목록") + List routeRegions, @Schema(description = "학기 정보") RouteSemester semesterInfo ) { @JsonNaming(SnakeCaseStrategy.class) - @Schema(description = "경로 지역 정보") + @Schema(description = "노선 지역 정보") private record RouteRegion( @Schema(description = "지역 이름", example = "천안") String region, @Schema(description = "해당 지역의 경로 목록") List routes ) { + + public static List mapCategories(List shuttleBusRoutes) { + return shuttleBusRoutes.stream() + .collect(Collectors.groupingBy(ShuttleBusRoute::getRegion)) + .entrySet().stream() + .map(entry -> new RouteRegion(entry.getKey(), RouteName.mapRouteNames(entry.getValue()))) + .toList(); + } } @JsonNaming(SnakeCaseStrategy.class) - @Schema(description = "경로 이름 정보") + @Schema(description = "노선 세부 정보") private record RouteName( - @Schema(description = "경로 ID", example = "675013f9465776d6265ddfdb") String id, - @Schema(description = "경로 이름", example = "대학원") String routeName, - @Schema(description = "경로 부가 이름", example = "토요일") String subName + @Schema(description = "노선 ID", example = "675013f9465776d6265ddfdb") String id, + @Schema(description = "노선 종류", example = "주말") String type, + @Schema(description = "노선 이름", example = "대학원") String routeName, + @Schema(description = "노선 부가 이름", example = "토요일") String subName ) { + + public static List mapRouteNames(List routes) { + return routes.stream() + .map(route -> new RouteName(route.getId(), route.getRouteType(), route.getRouteName(), + route.getSubName())) + .toList(); + } } @JsonNaming(SnakeCaseStrategy.class) @@ -52,30 +60,17 @@ private record RouteSemester( @Schema(description = "학기 이름", example = "정규학기") String name, @Schema(description = "학기 기간", example = "2024-09-02 ~ 2024-12-20") String term ) { + + public static RouteSemester from(VersionMessageResponse versionMessageResponse) { + return new RouteSemester(versionMessageResponse.title(), + versionMessageResponse.content()); + } } public static ShuttleBusRoutesResponse of(List shuttleBusRoutes, VersionMessageResponse versionMessageResponse) { - Map> groupedByRouteType = shuttleBusRoutes.stream() - .collect(Collectors.groupingBy(ShuttleBusRoute::getRouteType)); - List shuttleRoutes = mapRegions(groupedByRouteType.getOrDefault("순환", new ArrayList<>())); - List commutingRoutes = mapRegions(groupedByRouteType.getOrDefault("주중", new ArrayList<>())); - List weekendRoutes = mapRegions(groupedByRouteType.getOrDefault("주말", new ArrayList<>())); - RouteSemester routeSemester = new RouteSemester(versionMessageResponse.title(), versionMessageResponse.content()); - return new ShuttleBusRoutesResponse(shuttleRoutes, commutingRoutes, weekendRoutes, routeSemester); - } - - private static List mapRegions(List routes) { - return routes.stream() - .collect(Collectors.groupingBy(ShuttleBusRoute::getRegion)) - .entrySet().stream() - .map(entry -> new RouteRegion(entry.getKey(), mapRouteNames(entry.getValue()))) - .toList(); - } - - private static List mapRouteNames(List routes) { - return routes.stream() - .map(route -> new RouteName(route.getId(), route.getRouteName(), route.getSubName())) - .toList(); + List categories = RouteRegion.mapCategories(shuttleBusRoutes); + RouteSemester routeSemester = RouteSemester.from(versionMessageResponse); + return new ShuttleBusRoutesResponse(categories, routeSemester); } -} \ No newline at end of file +}