55import ita .tinybite .domain .chat .repository .ChatRoomRepository ;
66import ita .tinybite .domain .party .dto .request .PartyCreateRequest ;
77import ita .tinybite .domain .party .dto .request .PartyUpdateRequest ;
8+ import ita .tinybite .domain .party .dto .request .UserLocation ;
89import ita .tinybite .domain .party .dto .response .*;
910import ita .tinybite .domain .party .entity .Party ;
1011import ita .tinybite .domain .party .entity .PartyParticipant ;
@@ -51,16 +52,15 @@ public Long createParty(Long userId, PartyCreateRequest request) {
5152 // 카테고리별 유효성 검증
5253 validateProductLink (request .getCategory (), request .getProductLink ());
5354
54- // 첫 번째 이미지를 썸네일로 사용, 없으면 기본 이미지
55- String thumbnailImage = getDefaultImageIfEmpty (request .getImages (), request .getCategory ());
56-
5755 Party party = Party .builder ()
5856 .title (request .getTitle ())
5957 .category (request .getCategory ())
6058 .price (request .getTotalPrice ())
6159 .maxParticipants (request .getMaxParticipants ())
6260 .pickupLocation (PickupLocation .builder ()
6361 .place (request .getPickupLocation ().getPlace ())
62+ .pickupLatitude (request .getPickupLocation ().getPickupLatitude ())
63+ .pickupLongitude (request .getPickupLocation ().getPickupLongitude ())
6464 .build ())
6565 .image (getImageIfPresent (request .getImages ()))
6666 .thumbnailImage (getThumbnailIfPresent (request .getImages (), request .getCategory ()))
@@ -182,7 +182,7 @@ public PartyListResponse getPartyList(Long userId, PartyCategory category) {
182182 /**
183183 * 파티 상세 조회
184184 */
185- public PartyDetailResponse getPartyDetail (Long partyId , Long userId ) {
185+ public PartyDetailResponse getPartyDetail (Long partyId , Long userId , UserLocation userLocation ) {
186186 Party party = partyRepository .findById (partyId )
187187 .orElseThrow (() -> new IllegalArgumentException ("파티를 찾을 수 없습니다" ));
188188
@@ -200,18 +200,26 @@ public PartyDetailResponse getPartyDetail(Long partyId, Long userId) {
200200
201201 // 거리 계산 (사용자 위치 필요)
202202 double distance = 0.0 ;
203- // if (user != null ) {
204- // distance = DistanceCalculator.calculateDistance(
205- // userLat ,
206- // userLon ,
207- // party.getLatitude (),
208- // party.getLongitude ()
209- // );
210- // }
203+ if (validateLocation ( user , userLocation , party ) ) {
204+ distance = DistanceCalculator .calculateDistance (
205+ userLocation . getLatitude () ,
206+ userLocation . getLongitude () ,
207+ party .getPickupLocation (). getPickupLatitude (),
208+ party .getPickupLocation (). getPickupLongitude ()
209+ );
210+ }
211211
212212 return convertToDetailResponse (party , distance , isParticipating );
213213 }
214214
215+ private boolean validateLocation (User user , UserLocation userLocation , Party party ) {
216+ return (user != null
217+ && userLocation .getLatitude () != null
218+ && userLocation .getLongitude ()!= null
219+ && party .getPickupLocation ().getPickupLatitude ()!= null
220+ && party .getPickupLocation ().getPickupLongitude ()!=null );
221+ }
222+
215223 /**
216224 * 파티 참여
217225 */
@@ -293,7 +301,7 @@ private PartyDetailResponse convertToDetailResponse(Party party, double distance
293301 // 이미지 파싱
294302 List <String > images = new ArrayList <>();
295303 if (party .getImage () != null && !party .getImage ().isEmpty ()) {
296- images = List .of (party .getImage (). toString () );
304+ images = List .of (party .getImage ());
297305 }
298306
299307 return PartyDetailResponse .builder ()
@@ -307,7 +315,7 @@ private PartyDetailResponse convertToDetailResponse(Party party, double distance
307315 .profileImage (party .getHost ().getProfileImage ())
308316 .build ())
309317 .pickupLocation (party .getPickupLocation ())
310- // .distance(DistanceCalculator.formatDistance (distance))
318+ .distance (formatDistanceIfExists (distance ))
311319 .currentParticipants (currentCount )
312320 .maxParticipants (party .getMaxParticipants ())
313321 .remainingSlots (party .getMaxParticipants () - currentCount )
@@ -349,8 +357,8 @@ public void updateParty(Long partyId, Long userId, PartyUpdateRequest request) {
349357 request .getTitle (),
350358 request .getTotalPrice (),
351359 request .getMaxParticipants (),
352- // new PickupLocation(request.getPickupLocation(), request.getLatitude(), request.getLongitude()),
353- new PickupLocation (request .getPickupLocation ()),
360+ new PickupLocation (request .getPickupLocation (), request .getLatitude (), request .getLongitude ()),
361+ // new PickupLocation(request.getPickupLocation()),
354362 request .getLatitude (),
355363 request .getLongitude (),
356364 request .getProductLink (),
@@ -631,5 +639,9 @@ private String getLinkIfValid(String link, PartyCategory category) {
631639 private String getDescriptionIfPresent (String description ) {
632640 return (description != null && !description .isBlank ()) ? description : null ;
633641 }
642+
643+ private String formatDistanceIfExists (Double distance ) {
644+ return distance != null ? DistanceCalculator .formatDistance (distance ):null ;
645+ }
634646}
635647
0 commit comments