Skip to content

Commit 6eaf71f

Browse files
authored
Hotfix : 파티 생성, 조회시 거리 계산 로직 반영 (#60)
* hotfix : 파티 생성, 조회 시, 거리 계산 로직 반영
1 parent 3c4c879 commit 6eaf71f

File tree

6 files changed

+47
-34
lines changed

6 files changed

+47
-34
lines changed

src/main/java/ita/tinybite/domain/party/controller/PartyController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ita.tinybite.domain.chat.entity.ChatRoom;
1212
import ita.tinybite.domain.party.dto.request.PartyCreateRequest;
1313
import ita.tinybite.domain.party.dto.request.PartyUpdateRequest;
14+
import ita.tinybite.domain.party.dto.request.UserLocation;
1415
import ita.tinybite.domain.party.dto.response.ChatRoomResponse;
1516
import ita.tinybite.domain.party.dto.response.PartyDetailResponse;
1617
import ita.tinybite.domain.party.dto.response.PartyListResponse;
@@ -319,11 +320,12 @@ public ResponseEntity<PartyListResponse> getPartyList(
319320
@GetMapping("/{partyId}")
320321
public ResponseEntity<PartyDetailResponse> getPartyDetail(
321322
@PathVariable Long partyId,
322-
@RequestHeader("Authorization") String token
323+
@RequestHeader("Authorization") String token,
324+
@RequestBody UserLocation userLocation
323325
) {
324326
Long userId = jwtTokenProvider.getUserId(token);
325327

326-
PartyDetailResponse response = partyService.getPartyDetail(partyId, userId);
328+
PartyDetailResponse response = partyService.getPartyDetail(partyId, userId,userLocation);
327329
return ResponseEntity.ok(response);
328330
}
329331

src/main/java/ita/tinybite/domain/party/dto/request/PartyCreateRequest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ public class PartyCreateRequest {
3434
@NotNull(message = "수령 장소 정보는 필수입니다")
3535
private PickupLocation pickupLocation;
3636

37-
// @NotNull(message = "위도는 필수입니다")
38-
// private Double latitude;
39-
//
40-
// @NotNull(message = "경도는 필수입니다")
41-
// private Double longitude;
42-
4337
@Size(max = 5, message = "이미지는 최대 5장까지 업로드 가능합니다")
4438
private List<String> images;
4539

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ita.tinybite.domain.party.dto.request;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
@Getter
8+
@AllArgsConstructor
9+
@NoArgsConstructor
10+
public class UserLocation {
11+
Double latitude;
12+
Double longitude;
13+
}

src/main/java/ita/tinybite/domain/party/entity/Party.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ public class Party {
6262
@Column(nullable = false)
6363
private PartyStatus status;
6464

65-
// @Column(nullable = false)
66-
// private Double latitude; // 위도 (거리 계산용)
67-
//
68-
// @Column(nullable = false)
69-
// private Double longitude; // 경도 (거리 계산용)
70-
7165
@Column(nullable = false)
7266
private Boolean isClosed; // 마감 여부
7367

@@ -144,8 +138,6 @@ public void updateAllFields(String title, Integer price, Integer maxParticipants
144138
this.price = price != null ? price : this.price;
145139
this.maxParticipants = maxParticipants != null ? maxParticipants : this.maxParticipants;
146140
this.pickupLocation = pickupLocation != null ? pickupLocation : this.pickupLocation;
147-
// this.latitude = latitude != null ? latitude : this.latitude;
148-
// this.longitude = longitude != null ? longitude : this.longitude;
149141

150142
// 상품 링크 검증
151143
if (productLink != null) {

src/main/java/ita/tinybite/domain/party/entity/PickupLocation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class PickupLocation {
1717
private String place;
1818

1919
// @NotNull(message = "위도는 필수입니다")
20-
// private Double pickupLatitude;
20+
private Double pickupLatitude;
2121
//
2222
// @NotNull(message = "경도는 필수입니다")
23-
// private Double pickupLongitude;
23+
private Double pickupLongitude;
2424
}

src/main/java/ita/tinybite/domain/party/service/PartyService.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ita.tinybite.domain.chat.repository.ChatRoomRepository;
66
import ita.tinybite.domain.party.dto.request.PartyCreateRequest;
77
import ita.tinybite.domain.party.dto.request.PartyUpdateRequest;
8+
import ita.tinybite.domain.party.dto.request.UserLocation;
89
import ita.tinybite.domain.party.dto.response.*;
910
import ita.tinybite.domain.party.entity.Party;
1011
import 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

Comments
 (0)