Skip to content

Commit

Permalink
Merge pull request #37 from MAKAR-iOS/chore/#36
Browse files Browse the repository at this point in the history
[Chore/#36] Station, Route Request, Response 수정
  • Loading branch information
daeun084 authored Jul 27, 2024
2 parents f6ac786 + 0f4014b commit d1b933e
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/main/java/makar/dev/controller/RouteController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class RouteController {
description = "출발역과 도착역을 파라미터로 받아 역 간의 경로 리스트를 검색합니다."
)
@GetMapping()
public ApiResponse searchRoute(@RequestParam(value = "fromStationName") String fromStationName, @RequestParam(value = "fromLineNum") int fromLineNum,
@RequestParam(value = "toStationName") String toStationName, @RequestParam(value = "toLineNum") int toLineNum) {
public ApiResponse searchRoute(@RequestParam(value = "fromStationName") String fromStationName, @RequestParam(value = "fromLineNum") String fromLineNum,
@RequestParam(value = "toStationName") String toStationName, @RequestParam(value = "toLineNum") String toLineNum) {
return ApiResponse.SuccessResponse(SuccessStatus._ROUTE_LIST_GET, routeService.searchRoute(fromStationName, fromLineNum, toStationName, toLineNum));
}

Expand Down
43 changes: 19 additions & 24 deletions src/main/java/makar/dev/converter/RouteConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public static RouteResponse.RouteDto toRouteDto(Route route) {
return RouteResponse.RouteDto.builder()
.routeId(route.getRouteId())
.sourceStationName(route.getSourceStation().getStationName())
.sourceLineNum(route.getSourceStation().getOdsayLaneType())
.sourceLineNum(route.getSourceStation().getLineNum())
.destinationStationName(route.getDestinationStation().getStationName())
.destinationLineNum(route.getDestinationStation().getOdsayLaneType())
.destinationLineNum(route.getDestinationStation().getLineNum())
.sourceTime(route.getSchedule().getSourceTime())
.destinationTime(route.getSchedule().getDestinationTime())
.totalTime(route.getSchedule().getTotalTime())
Expand All @@ -46,9 +46,9 @@ public static RouteResponse.RouteDetailDto toRouteDetailDto(Route route) {
return RouteResponse.RouteDetailDto.builder()
.routeId(route.getRouteId())
.sourceStationName(route.getSourceStation().getStationName())
.sourceLineNum(route.getSourceStation().getOdsayLaneType())
.sourceLineNum(route.getSourceStation().getLineNum())
.destinationStationName(route.getDestinationStation().getStationName())
.destinationLineNum(route.getDestinationStation().getOdsayLaneType())
.destinationLineNum(route.getDestinationStation().getLineNum())
.sourceTime(route.getSchedule().getSourceTime())
.destinationTime(route.getSchedule().getDestinationTime())
.totalTime(route.getSchedule().getTotalTime())
Expand Down Expand Up @@ -81,20 +81,22 @@ public static SubRoute toSubRoute(RouteSearchResponse.SubPath subPath) {
}

public static RouteResponse.SubRouteDto toSubRouteDto(SubRoute subRoute) {
String lineNum = mapOdsayStationTypeToLineNum(subRoute.getLineNum());
return RouteResponse.SubRouteDto.builder()
.fromStationName(subRoute.getFromStationName())
.toStationName(subRoute.getToStationName())
.lineNum(subRoute.getLineNum())
.lineNum(lineNum)
.sectionTime(subRoute.getSectionTime())
.transferTime(subRoute.getTransferTime())
.build();
}

public static RouteResponse.SubRouteDetailDto toSubRouteDetailDto(SubRoute subRoute) {
String lineNum = mapOdsayStationTypeToLineNum(subRoute.getLineNum());
return RouteResponse.SubRouteDetailDto.builder()
.fromStationName(subRoute.getFromStationName())
.toStationName(subRoute.getToStationName())
.lineNum(subRoute.getLineNum())
.lineNum(lineNum)
.sectionTime(subRoute.getSectionTime())
.transferTime(subRoute.getTransferTime())
.path(subRoute.getPath())
Expand All @@ -111,23 +113,16 @@ public static RouteResponse.SearchRouteDto toSearchRouteDto(List<Route> routeLis
.build();
}

public static RouteResponse.SetRouteDto toSetRouteDto(Route route, Noti makarNoti, Noti getOffNoti){
List<RouteResponse.SubRouteDto> subRouteDtoList = route.getSubRouteList().stream()
.map(RouteConverter::toSubRouteDto)
.toList();
return RouteResponse.SetRouteDto.builder()
.routeId(route.getRouteId())
.sourceStationName(route.getSourceStation().getStationName())
.sourceLineNum(route.getSourceStation().getOdsayLaneType())
.destinationStationName(route.getDestinationStation().getStationName())
.destinationLineNum(route.getDestinationStation().getOdsayLaneType())
.sourceTime(route.getSchedule().getSourceTime())
.destinationTime(route.getSchedule().getDestinationTime())
.totalTime(route.getSchedule().getTotalTime())
.subRouteDtoList(subRouteDtoList)
.getOffMinute(makarNoti.getNoti_minute())
.getOffMinute(getOffNoti.getNoti_minute())
.build();
private static String mapOdsayStationTypeToLineNum(int stationType) {
if (stationType >= 1 && stationType <= 9) {
return stationType + "호선";
}
if (stationType == 101) {
return "공항철도";
}
if (stationType == 104) {
return "경의중앙";
}
return null;
}

}
2 changes: 1 addition & 1 deletion src/main/java/makar/dev/converter/StationConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Station toStation(String stationName, String stationCode, String l
public static StationResponse.StationDto toStationDto(Station station){
return StationResponse.StationDto.builder()
.stationName(station.getStationName())
.lineNum(station.getOdsayLaneType())
.lineNum(station.getLineNum())
.build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/makar/dev/dto/request/StationRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class StationRequest {
@AllArgsConstructor
public static class FavoriteStationDto {
public String stationName;
public int lineNum;
public String lineNum;
}
}
30 changes: 6 additions & 24 deletions src/main/java/makar/dev/dto/response/RouteResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class RouteResponse {
public static class RouteDto {
private Long routeId;
private String sourceStationName;
private int sourceLineNum;
private String sourceLineNum;
private String destinationStationName;
private int destinationLineNum;
private String destinationLineNum;
private String sourceTime; // 출발 시각
private String destinationTime; // 도착 시각
private int totalTime; // 총 소요 시간
Expand All @@ -32,9 +32,9 @@ public static class RouteDto {
public static class RouteDetailDto {
private Long routeId;
private String sourceStationName;
private int sourceLineNum;
private String sourceLineNum;
private String destinationStationName;
private int destinationLineNum;
private String destinationLineNum;
private String sourceTime; // 출발 시각
private String destinationTime; // 도착 시각
private int totalTime; // 총 소요 시간
Expand All @@ -49,7 +49,7 @@ public static class RouteDetailDto {
public static class SubRouteDto {
private String fromStationName;
private String toStationName;
private int lineNum;
private String lineNum;
private int sectionTime;
private int transferTime;
}
Expand All @@ -61,7 +61,7 @@ public static class SubRouteDto {
public static class SubRouteDetailDto {
private String fromStationName;
private String toStationName;
private int lineNum;
private String lineNum;
private int sectionTime;
private int transferTime;
private List<String> path;
Expand All @@ -73,22 +73,4 @@ public static class SubRouteDetailDto {
public static class SearchRouteDto {
private List<RouteDto> routeDtoList;
}

@Data @Builder
@NoArgsConstructor
@AllArgsConstructor
public static class SetRouteDto {
private Long routeId;
private String sourceStationName;
private int sourceLineNum;
private String destinationStationName;
private int destinationLineNum;
private String sourceTime; // 출발 시각
private String destinationTime; // 도착 시각
private int totalTime; // 총 소요 시간
private List<SubRouteDto> subRouteDtoList; // 환승 정보
private int makarMinute;
private int getOffMinute;
}

}
2 changes: 1 addition & 1 deletion src/main/java/makar/dev/dto/response/StationResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class StationResponse {
@AllArgsConstructor
public static class StationDto {
private String stationName;
private int lineNum;
private String lineNum;
}

@Data
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/makar/dev/manager/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,9 @@ private void updateOdsayStationData(List<OdsayStation.Station> stations) {
continue;
}

List<Station> dbStations = stationRepository.findByStationNameAndLineNum(stationName, lineNum);

if (dbStations.size() != 1) {
continue;
}

for (Station dbStation : dbStations) {
updateOdsayStationDataInEntity(dbStation, odsayStation);
stationRepository.save(dbStation);
}
Station dbStation = findStationByStationNameAndLineNum(stationName, lineNum);
updateOdsayStationDataInEntity(dbStation, odsayStation);
stationRepository.save(dbStation);
}
}

Expand Down Expand Up @@ -215,14 +208,13 @@ private List<String> extractStationNamesNot(String input) {
return stationNames;
}

private List<LineStation> mapOdsayStationNameWithLine(List<String> list, int code) {
private List<LineStation> mapOdsayStationNameWithLine(List<String> list, int odsayLineType) {
List<LineStation> orderedStations = new ArrayList<>();

for (int i = 0; i < list.size(); i++) {
// odsay 역 이름 리스트 검색
String stationName = doubleCheckStationName(list.get(i));
Station station = stationRepository.findByStationNameAndOdsayLaneType(stationName, code)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_STATION));
Station station = findStationByStationNameAndOdsayLaneType(stationName, odsayLineType);

// TODO: get odsayStationName, put data in line station entity
// ""호선의 ""역의 odsay 역 이름, odsayStationId 저장
Expand Down Expand Up @@ -315,8 +307,7 @@ private int getOdsayStationId(String stationName, int odsayLaneType){
if (stationName.equals("총신대입구") && odsayLaneType == 7)
stationName = "이수";

Station station = stationRepository.findByStationNameAndOdsayLaneType(stationName, odsayLaneType)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_STATION));
Station station = findStationByStationNameAndOdsayLaneType(stationName, odsayLaneType);
return station.getOdsayStationID();
}

Expand Down Expand Up @@ -350,4 +341,14 @@ private Sheet readExcelFile(String path) {
throw new GeneralException(ErrorStatus.FAILURE_READ_EXCEL_FILE);
}
}

private Station findStationByStationNameAndOdsayLaneType(String stationName, int odsayLaneType){
return stationRepository.findByStationNameAndOdsayLaneType(stationName, odsayLaneType)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_STATION));
}

private Station findStationByStationNameAndLineNum(String stationName, String lineNum){
return stationRepository.findByStationNameAndLineNum(stationName, lineNum)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_STATION));
}
}
2 changes: 1 addition & 1 deletion src/main/java/makar/dev/repository/StationRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Optional;

public interface StationRepository extends JpaRepository<Station, Long> {
List<Station> findByStationNameAndLineNum(String stationName, String lineNum);
Optional<Station> findByStationNameAndLineNum(String stationName, String lineNum);
Optional<Station> findByStationNameAndOdsayLaneType(String stationName, int code);

List<Station> findByStationNameContaining(String stationName);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/makar/dev/service/RouteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import makar.dev.converter.ScheduleConverter;
import makar.dev.domain.*;
import makar.dev.domain.data.RouteSearchResponse;
import makar.dev.dto.request.RouteRequest;
import makar.dev.dto.response.RouteResponse;
import makar.dev.manager.APIManager;
import makar.dev.manager.MakarManager;
Expand All @@ -36,7 +35,7 @@ public class RouteService {
private final TransferService transferService;

// 경로 리스트 검색
public RouteResponse.SearchRouteDto searchRoute(String fromStationName, int fromLineNum, String toStationName, int toLineNum) {
public RouteResponse.SearchRouteDto searchRoute(String fromStationName, String fromLineNum, String toStationName, String toLineNum) {
Station sourceStation = findStation(fromStationName, fromLineNum);
Station destinationStation = findStation(toStationName, toLineNum);

Expand All @@ -47,7 +46,7 @@ public RouteResponse.SearchRouteDto searchRoute(String fromStationName, int from

// 경로 설정
@Transactional
public RouteResponse.SetRouteDto setRoute(Long userId, Long routeId){
public RouteResponse.RouteDto setRoute(Long userId, Long routeId){
User user = findUserById(userId);
Route route = findRouteById(routeId);

Expand All @@ -66,7 +65,7 @@ public RouteResponse.SetRouteDto setRoute(Long userId, Long routeId){

user.addNotiList(makarNoti);
user.addNotiList(getOffNoti);
return RouteConverter.toSetRouteDto(route, makarNoti, getOffNoti);
return RouteConverter.toRouteDto(route);
}

// 경로 삭제
Expand Down Expand Up @@ -96,8 +95,8 @@ public RouteResponse.RouteDetailDto getSetRoute(Long userId){
return RouteConverter.toRouteDetailDto(route);
}

private Station findStation(String name, int num){
return stationRepository.findByStationNameAndOdsayLaneType(name, num)
private Station findStation(String stationName, String lineNum){
return stationRepository.findByStationNameAndLineNum(stationName, lineNum)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_STATION));
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/makar/dev/service/StationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public StationResponse.SearchDto searchStation(String param){

// 역 세부 정보 조회
public StationResponse.StationDetailDto getStationDetail(String stationName, String lineNum) {
List<Station> station = stationRepository.findByStationNameAndLineNum(stationName, lineNum);
return StationConverter.toStationDetailDto(station.get(0));
Station station = findByStationNameAndLineNum(stationName, lineNum);
return StationConverter.toStationDetailDto(station);
}

// 역 세부 정보 수정
@Transactional
public StationResponse.StationDetailDto updateStationDetail(String stationName, String lineNum) {
Station station = stationRepository.findByStationNameAndLineNum(stationName, lineNum).get(0);
Station station = findByStationNameAndLineNum(stationName, lineNum);

// 대중교통 정류장 검색 API 호출
List<OdsayStation.Station> stations = apiManager.searchStation(stationName);
Expand Down Expand Up @@ -88,7 +88,7 @@ private void updateOdsayStationDataInEntity(Station station, OdsayStation.Statio
@Transactional
public StationResponse.StationDto updateFavoriteHomeStation(StationRequest.FavoriteStationDto favoriteStationDto, Long userId){
User user = findById(userId);
Station station = findByStationNameAndOdsayLaneType(favoriteStationDto.getStationName(), favoriteStationDto.getLineNum());
Station station = findByStationNameAndLineNum(favoriteStationDto.getStationName(), favoriteStationDto.getLineNum());
user.updateFavoriteHomeStation(station);
return StationConverter.toStationDto(station);
}
Expand All @@ -97,7 +97,7 @@ public StationResponse.StationDto updateFavoriteHomeStation(StationRequest.Favor
@Transactional
public StationResponse.StationDto updateFavoriteSchoolStation(StationRequest.FavoriteStationDto favoriteStationDto, Long userId){
User user = findById(userId);
Station station = findByStationNameAndOdsayLaneType(favoriteStationDto.getStationName(), favoriteStationDto.getLineNum());
Station station = findByStationNameAndLineNum(favoriteStationDto.getStationName(), favoriteStationDto.getLineNum());
user.updateFavoriteSchoolStation(station);
return StationConverter.toStationDto(station);
}
Expand Down Expand Up @@ -129,8 +129,8 @@ private User findById(Long userId){
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_USER));
}

private Station findByStationNameAndOdsayLaneType(String stationName, int odsayLaneType){
return stationRepository.findByStationNameAndOdsayLaneType(stationName, odsayLaneType)
private Station findByStationNameAndLineNum(String stationName, String lineNum){
return stationRepository.findByStationNameAndLineNum(stationName, lineNum)
.orElseThrow(() -> new GeneralException(ErrorStatus.NOT_FOUND_STATION));
}

Expand Down

0 comments on commit d1b933e

Please sign in to comment.