11package com .back .web7_9_codecrete_be .domain .plans .entity ;
22
3+ import com .back .web7_9_codecrete_be .domain .plans .dto .TransportRoute ;
4+ import com .fasterxml .jackson .core .JsonProcessingException ;
5+ import com .fasterxml .jackson .databind .ObjectMapper ;
36import jakarta .persistence .*;
47import lombok .*;
58import org .hibernate .annotations .CreationTimestamp ;
@@ -74,6 +77,10 @@ public class Schedule {
7477 @ Column (name = "transport_type" )
7578 private TransportType transportType ;
7679
80+ // 교통 경로 상세 정보 (JSON 형태로 저장)
81+ @ Column (name = "transport_route" , columnDefinition = "TEXT" )
82+ private String transportRoute ;
83+
7784 @ CreationTimestamp
7885 @ Column (name = "created_date" , nullable = false , updatable = false )
7986 private LocalDateTime createdDate ;
@@ -100,7 +107,7 @@ public Schedule(Plan plan, ScheduleType scheduleType, String title,
100107 Double startPlaceLat , Double startPlaceLon ,
101108 Double endPlaceLat , Double endPlaceLon ,
102109 Integer distance , TransportType transportType ,
103- Boolean isMainEvent ) {
110+ String transportRoute , Boolean isMainEvent ) {
104111 this .plan = plan ;
105112 this .scheduleType = scheduleType ;
106113 this .title = title ;
@@ -117,6 +124,7 @@ public Schedule(Plan plan, ScheduleType scheduleType, String title,
117124 this .endPlaceLon = endPlaceLon ;
118125 this .distance = distance ;
119126 this .transportType = transportType ;
127+ this .transportRoute = transportRoute ;
120128 this .isMainEvent = isMainEvent != null ? isMainEvent : false ;
121129 }
122130
@@ -126,7 +134,8 @@ public void update(ScheduleType scheduleType, String title,
126134 Integer estimatedCost , String details ,
127135 Double startPlaceLat , Double startPlaceLon ,
128136 Double endPlaceLat , Double endPlaceLon ,
129- Integer distance , TransportType transportType ) {
137+ Integer distance , TransportType transportType ,
138+ String transportRoute ) {
130139 this .scheduleType = scheduleType ;
131140 this .title = title ;
132141 this .startAt = startAt ;
@@ -142,6 +151,38 @@ public void update(ScheduleType scheduleType, String title,
142151 this .endPlaceLon = endPlaceLon ;
143152 this .distance = distance ;
144153 this .transportType = transportType ;
154+ this .transportRoute = transportRoute ;
155+ }
156+
157+ /**
158+ * TransportRoute 객체를 JSON 문자열로 변환하여 저장
159+ */
160+ public void setTransportRoute (TransportRoute transportRoute ) {
161+ if (transportRoute == null ) {
162+ this .transportRoute = null ;
163+ return ;
164+ }
165+ try {
166+ ObjectMapper objectMapper = new ObjectMapper ();
167+ this .transportRoute = objectMapper .writeValueAsString (transportRoute );
168+ } catch (JsonProcessingException e ) {
169+ throw new RuntimeException ("Failed to serialize transportRoute" , e );
170+ }
171+ }
172+
173+ /**
174+ * JSON 문자열을 TransportRoute 객체로 변환하여 반환
175+ */
176+ public TransportRoute getTransportRouteAsObject () {
177+ if (transportRoute == null || transportRoute .isEmpty ()) {
178+ return null ;
179+ }
180+ try {
181+ ObjectMapper objectMapper = new ObjectMapper ();
182+ return objectMapper .readValue (transportRoute , TransportRoute .class );
183+ } catch (JsonProcessingException e ) {
184+ throw new RuntimeException ("Failed to deserialize transportRoute" , e );
185+ }
145186 }
146187
147188 public enum ScheduleType {
0 commit comments