Skip to content

Commit 3a75aa2

Browse files
authored
Hotfix : 참여중 파티 조회 반환값 통일 (#59)
* hotfix : 참여중 파티 조회 반환 형식 통일
1 parent 1ea8022 commit 3a75aa2

File tree

4 files changed

+96
-53
lines changed

4 files changed

+96
-53
lines changed

src/main/java/ita/tinybite/domain/party/dto/response/PartyCardResponse.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package ita.tinybite.domain.party.dto.response;
2+
import ita.tinybite.domain.party.entity.Party;
3+
import ita.tinybite.domain.party.enums.ParticipantStatus;
24
import ita.tinybite.domain.party.enums.PartyCategory;
5+
import ita.tinybite.domain.party.enums.PartyStatus;
36
import lombok.*;
47

8+
import java.time.Duration;
59
import java.time.LocalDateTime;
10+
import java.time.format.DateTimeFormatter;
611

712
@Getter
813
@NoArgsConstructor
@@ -20,4 +25,88 @@ public class PartyCardResponse {
2025
private Boolean isClosed; // 마감 여부
2126
private PartyCategory category;
2227
private LocalDateTime createdAt;
28+
29+
public static PartyCardResponse from(Party party, int currentParticipants, boolean isHost, ParticipantStatus status) {
30+
return PartyCardResponse.builder()
31+
.partyId(party.getId())
32+
.thumbnailImage(party.getThumbnailImage())
33+
.title(party.getTitle())
34+
.pricePerPerson(calculatePricePerPerson(party, currentParticipants))
35+
.participantStatus(formatParticipantStatus(currentParticipants, party.getMaxParticipants()))
36+
.distance(null) // 거리 계산은 별도 처리 필요
37+
.distanceKm(null) // 거리 계산은 별도 처리 필요
38+
.timeAgo(calculateTimeAgo(party.getCreatedAt()))
39+
.isClosed(checkIfClosed(party, currentParticipants))
40+
.category(party.getCategory())
41+
.createdAt(party.getCreatedAt())
42+
.build();
43+
}
44+
private static String getThumbnailImage(Party party) {
45+
if (party.getImage() != null && !party.getImage().isEmpty()) {
46+
return party.getImage();
47+
}
48+
return "/images/default-party-thumbnail.jpg"; // 기본 이미지
49+
}
50+
51+
/**
52+
* 1/N 가격 계산
53+
*/
54+
private static Integer calculatePricePerPerson(Party party, int currentParticipants) {
55+
if (party.getPrice() == null || currentParticipants == 0) {
56+
return null;
57+
}
58+
return party.getPrice() / currentParticipants;
59+
}
60+
61+
/**
62+
* 참가자 상태 포맷팅 "1/4명"
63+
*/
64+
private static String formatParticipantStatus(int current, int max) {
65+
return String.format("%d/%d명", current, max);
66+
}
67+
68+
/**
69+
* 시간 경과 계산 "10분 전", "3시간 전"
70+
*/
71+
private static String calculateTimeAgo(LocalDateTime createdAt) {
72+
if (createdAt == null) {
73+
return "";
74+
}
75+
76+
LocalDateTime now = LocalDateTime.now();
77+
Duration duration = Duration.between(createdAt, now);
78+
79+
long minutes = duration.toMinutes();
80+
long hours = duration.toHours();
81+
long days = duration.toDays();
82+
83+
if (minutes < 1) {
84+
return "방금 전";
85+
} else if (minutes < 60) {
86+
return minutes + "분 전";
87+
} else if (hours < 24) {
88+
return hours + "시간 전";
89+
} else if (days < 7) {
90+
return days + "일 전";
91+
} else {
92+
return createdAt.format(DateTimeFormatter.ofPattern("MM.dd"));
93+
}
94+
}
95+
96+
/**
97+
* 마감 여부 확인
98+
*/
99+
private static Boolean checkIfClosed(Party party, int currentParticipants) {
100+
// 1. 파티 상태가 CLOSED인 경우
101+
if (party.getStatus() == PartyStatus.CLOSED) {
102+
return true;
103+
}
104+
105+
// 2. 정원이 다 찬 경우
106+
if (currentParticipants >= party.getMaxParticipants()) {
107+
return true;
108+
}
109+
110+
return false;
111+
}
23112
}

src/main/java/ita/tinybite/domain/user/controller/UserController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import io.swagger.v3.oas.annotations.media.Schema;
77
import io.swagger.v3.oas.annotations.responses.ApiResponse;
88
import io.swagger.v3.oas.annotations.responses.ApiResponses;
9-
import ita.tinybite.domain.auth.dto.response.UserDto;
9+
import ita.tinybite.domain.party.dto.response.PartyCardResponse;
1010
import ita.tinybite.domain.user.dto.req.UpdateUserReqDto;
11-
import ita.tinybite.domain.user.dto.res.PartyResponse;
1211
import ita.tinybite.domain.user.dto.res.UserResDto;
1312
import ita.tinybite.domain.user.service.UserService;
1413
import ita.tinybite.global.response.APIResponse;
@@ -82,13 +81,13 @@ public APIResponse<?> deleteUser() {
8281
@Operation(summary = "활성 파티 목록 조회", description = "사용자가 참여 중인 활성 파티 목록을 조회합니다.")
8382
@ApiResponses({
8483
@ApiResponse(responseCode = "200", description = "조회 성공",
85-
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PartyResponse.class)))),
84+
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PartyCardResponse.class)))),
8685
@ApiResponse(responseCode = "401", description = "인증 실패")
8786
})
8887
@GetMapping("/parties/active")
89-
public ResponseEntity<List<PartyResponse>> getActiveParties(
88+
public ResponseEntity<List<PartyCardResponse>> getActiveParties(
9089
@AuthenticationPrincipal Long userId) {
91-
List<PartyResponse> response = userService.getActiveParties(userId);
90+
List<PartyCardResponse> response = userService.getActiveParties(userId);
9291
return ResponseEntity.ok(response);
9392
}
9493

src/main/java/ita/tinybite/domain/user/dto/res/PartyResponse.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/java/ita/tinybite/domain/user/service/UserService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package ita.tinybite.domain.user.service;
22

33
import ita.tinybite.domain.auth.service.SecurityProvider;
4+
import ita.tinybite.domain.party.dto.response.PartyCardResponse;
45
import ita.tinybite.domain.party.entity.Party;
56
import ita.tinybite.domain.party.entity.PartyParticipant;
67
import ita.tinybite.domain.party.enums.ParticipantStatus;
78
import ita.tinybite.domain.party.enums.PartyStatus;
89
import ita.tinybite.domain.party.repository.PartyParticipantRepository;
910
import ita.tinybite.domain.user.dto.req.UpdateUserReqDto;
10-
import ita.tinybite.domain.user.dto.res.PartyResponse;
1111
import ita.tinybite.domain.user.dto.res.UserResDto;
1212
import ita.tinybite.domain.user.entity.User;
1313
import ita.tinybite.domain.user.repository.UserRepository;
@@ -67,7 +67,7 @@ public void validateNickname(String nickname) {
6767
throw BusinessException.of(AuthErrorCode.DUPLICATED_NICKNAME);
6868
}
6969

70-
public List<PartyResponse> getActiveParties(Long userId) {
70+
public List<PartyCardResponse> getActiveParties(Long userId) {
7171
List<PartyParticipant> participants = participantRepository
7272
.findActivePartiesByUserId(
7373
userId,
@@ -81,7 +81,7 @@ public List<PartyResponse> getActiveParties(Long userId) {
8181
int currentParticipants = participantRepository
8282
.countByPartyIdAndStatus(party.getId(), ParticipantStatus.APPROVED);
8383
boolean isHost = party.getHost().getUserId().equals(userId);
84-
return PartyResponse.from(party, currentParticipants, isHost,pp.getStatus());
84+
return PartyCardResponse.from(party, currentParticipants, isHost,pp.getStatus());
8585
})
8686
.collect(Collectors.toList());
8787
}

0 commit comments

Comments
 (0)