Skip to content

Commit

Permalink
Merge pull request #131 from moidot/feat/add-walk-path
Browse files Browse the repository at this point in the history
feat: 대중교통 길찾기 실패 시 도보 경로 추천할 수 있도록 개선
  • Loading branch information
yujung7768903 authored Nov 2, 2024
2 parents 15ce122 + a561f72 commit c5a26d7
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 299 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.moim.backend.domain.space.config;

import com.moim.backend.domain.space.entity.BestPlace;
import com.moim.backend.domain.space.entity.Participation;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
Expand All @@ -14,6 +16,7 @@ public class TmapProperties {

private String appKey;
private String searchPathUri;
private String walkSearchPathUri;

public Map<String, String> getRequestParameter(Double startX, Double startY, Double endX, Double endY) {
Map<String, String> parameters = new HashMap<>();
Expand All @@ -24,4 +27,17 @@ public Map<String, String> getRequestParameter(Double startX, Double startY, Dou
return parameters;
}

public Map<String, String> getWalkRequestParameter(
String startName, String endName, Double startX, Double startY, Double endX, Double endY
) {
Map<String, String> parameters = new HashMap<>();
parameters.put("startName", startName);
parameters.put("endName", endName);
parameters.put("startX", String.valueOf(startX));
parameters.put("startY", String.valueOf(startY));
parameters.put("endX", String.valueOf(endX));
parameters.put("endY", String.valueOf(endY));
return parameters;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

@Getter
public enum TransportationType {
PUBLIC, PERSONAL, NULL
PUBLIC, PERSONAL, WALK, NULL
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CarMoveInfo implements MoveInfoInterface, PathGraphicDataInterface {
public class CarPathResponse implements MoveInfoInterface, PathGraphicDataInterface {
private List<Route> routes;

private Route getBestRoute() {
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/com/moim/backend/domain/space/response/MoveUserInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.moim.backend.domain.space.response;

import com.moim.backend.domain.space.entity.BestPlace;
import com.moim.backend.domain.space.entity.Participation;
import com.moim.backend.domain.space.entity.Space;
import com.moim.backend.domain.space.entity.TransportationType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class MoveUserInfo {
@Schema(description = "모임장 여부")
private Boolean isAdmin;
@Schema(description = "사용자 아이디")
private Long userId;
@Schema(description = "사용자 닉네임")
private String userName;
@Schema(description = "이동 수단", allowableValues = {"PUBLIC", "PERSONAL", "WALK"})
private TransportationType transportationType;
@Schema(description = "총 환승 횟수")
private int transitCount;
@Schema(description = "이동 시간. 단위: 분")
private int totalTime;
@Schema(description = "총 이동 거리 단위: 미터")
private Double totalDistance;
@Schema(description = "예상 요금")
private int payment;
@Schema(description = "이동 경로에 따른 좌표 리스트. 경로를 찾을 수 없을 경우, 비어있는 리스트로 반환")
private List<PathDto> path = new ArrayList<>();

// 경로를 찾을 수 없는 사용자
public static MoveUserInfo createWithEmptyPath(
Space space,
Participation participation
) {
MoveUserInfo moveUserInfo = new MoveUserInfo();
moveUserInfo.isAdmin = (participation.getUserId() == space.getAdminId()) ? true : false;
moveUserInfo.userId = participation.getUserId();
moveUserInfo.transportationType = participation.getTransportation();
moveUserInfo.userName = participation.getUserName();
return moveUserInfo;
}

public static MoveUserInfo createWithPublicPath(
Space space,
Participation participation,
TmapPublicPathResponse tmapPublicPathResponse,
List<PathDto> path
) {
MoveUserInfo moveUserInfo = new MoveUserInfo();
moveUserInfo.isAdmin = (participation.getUserId() == space.getAdminId()) ? true : false;
moveUserInfo.userId = participation.getUserId();
moveUserInfo.userName = participation.getUserName();
moveUserInfo.transportationType = participation.getTransportation();
moveUserInfo.totalTime = tmapPublicPathResponse.getTotalTime();
moveUserInfo.totalDistance = tmapPublicPathResponse.getTotalDistance();
moveUserInfo.path = path;
moveUserInfo.payment = tmapPublicPathResponse.getPayment();
return moveUserInfo;
}

public static MoveUserInfo createWithCarPath(
Space space,
Participation participation,
CarPathResponse carPathResponse,
BestPlace bestPlace
) {
MoveUserInfo moveUserInfo = new MoveUserInfo();
moveUserInfo.isAdmin = (participation.getUserId() == space.getAdminId()) ? true : false;
moveUserInfo.userId = participation.getUserId();
moveUserInfo.userName = participation.getUserName();
moveUserInfo.transportationType = participation.getTransportation();
moveUserInfo.totalTime = carPathResponse.getTotalTime();
moveUserInfo.totalDistance = carPathResponse.getTotalDistance();
moveUserInfo.path = carPathResponse.getPathList(participation, bestPlace);
moveUserInfo.payment = carPathResponse.getPayment();
return moveUserInfo;
}

public static MoveUserInfo createWithWalkPath(
Space space,
Participation participation,
int totalTime,
double totalDistance,
List<PathDto>path
) {
MoveUserInfo moveUserInfo = new MoveUserInfo();
moveUserInfo.isAdmin = (participation.getUserId() == space.getAdminId()) ? true : false;
moveUserInfo.userId = participation.getUserId();
moveUserInfo.userName = participation.getUserName();
moveUserInfo.transportationType = participation.getTransportation();
moveUserInfo.totalTime = totalTime;
moveUserInfo.totalDistance = totalDistance;
moveUserInfo.path = path;
moveUserInfo.payment = 0;
return moveUserInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,4 @@ public PlaceRouteResponse(
this.longitude = bestPlace.getLongitude();
this.moveUserInfo = moveUserInfoList;
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class MoveUserInfo {
private Boolean isAdmin;
private Long userId;
private String userName;
private TransportationType transportationType;
private int transitCount; // 총 환승 횟수
private int totalTime; // 단위: 분(m)
private Double totalDistance;
private int payment;
private List<PathDto> path;

public MoveUserInfo(
Space group,
Participation participation,
BusGraphicDataResponse busGraphicDataResponse,
BusPathResponse busPathResponse,
BestPlace bestPlace
) {
this.isAdmin = (participation.getUserId() == group.getAdminId()) ? true : false;
this.userId = participation.getUserId();
this.userName = participation.getUserName();
this.transportationType = participation.getTransportation();
this.transitCount = busPathResponse.getTotalTransitCount();
this.totalTime = busPathResponse.getTotalTime();
this.totalDistance = busPathResponse.getTotalDistance();
this.path = busGraphicDataResponse.getPathList(participation, bestPlace);
this.payment = busPathResponse.getPayment();
}

public MoveUserInfo(
Space group,
Participation participation,
CarMoveInfo carMoveInfo,
BestPlace bestPlace
) {
this.isAdmin = (participation.getUserId() == group.getAdminId()) ? true : false;
this.userId = participation.getUserId();
this.userName = participation.getUserName();
this.transportationType = participation.getTransportation();
this.totalTime = carMoveInfo.getTotalTime();
this.totalDistance = carMoveInfo.getTotalDistance();
this.path = carMoveInfo.getPathList(participation, bestPlace);
this.payment = carMoveInfo.getPayment();
}

public MoveUserInfo(
Space group,
Participation participation,
TmapPublicPathResponse tmapPublicPathResponse,
BestPlace bestPlace,
List<PathDto> path
) {
this.isAdmin = (participation.getUserId() == group.getAdminId()) ? true : false;
this.userId = participation.getUserId();
this.userName = participation.getUserName();
this.transportationType = participation.getTransportation();
this.totalTime = tmapPublicPathResponse.getTotalTime();
this.totalDistance = tmapPublicPathResponse.getTotalDistance();
this.path = path;
this.payment = tmapPublicPathResponse.getPayment();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@AllArgsConstructor
public class TmapPublicPathResponse implements MoveInfoInterface {

private Result result;
private MetaData metaData;

@Override
Expand All @@ -38,6 +39,18 @@ private Itinerary getBestPath() {
return metaData.plan.itineraries.get(0);
}

public int getResultStatus() {
return result.status;
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
private static class Result {
private String message;
private int status;
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.moim.backend.domain.space.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class TmapWalkPathResponse {
public List<Feature> features;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class Feature {
public Geometry geometry;
public Properties properties;
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class Geometry {
public String type;
public String coordinates;
}

// Geometry 타입에 따라 시간이나 거리를 넘겨줄 때의 키 값이 달라짐
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class Properties {
private long totalDistance; // 단위: m. Geometry 타입이 "Point"일 때
private long totalTime; // 단위: 초. Geometry 타입이 "Point"일 때
private long distance; // 단위: m. Geometry 타입이 "LineString"일 때
private long time; // 단위: 초. Geometry 타입이 "LineString"일 때

public long getTotalTime() {
return totalTime + time;
}

public long getTotalDistance() {
return totalDistance + distance;
}
}
}
Loading

0 comments on commit c5a26d7

Please sign in to comment.