-
Notifications
You must be signed in to change notification settings - Fork 0
Feat : 마이페이지 참여중인 파티 조회 #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package ita.tinybite.domain.user.dto.res; | ||
|
|
||
| import ita.tinybite.domain.party.entity.Party; | ||
| import ita.tinybite.domain.party.enums.ParticipantStatus; | ||
| import ita.tinybite.domain.party.enums.PartyStatus; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class PartyResponse { | ||
| private Long id; | ||
| private String title; | ||
| private String description; | ||
| private Integer maxParticipants; | ||
| private Integer currentParticipants; | ||
| private PartyStatus status; | ||
| private String hostUsername; | ||
| private LocalDateTime startDate; | ||
| private LocalDateTime endDate; | ||
| private LocalDateTime createdAt; | ||
| private boolean isHost; | ||
| private ParticipantStatus participantStatus; | ||
|
|
||
| public static PartyResponse from(Party party, int currentParticipants, boolean isHost, ParticipantStatus participantStatus) { | ||
| return PartyResponse.builder() | ||
| .id(party.getId()) | ||
| .title(party.getTitle()) | ||
| .description(party.getDescription()) | ||
| .maxParticipants(party.getMaxParticipants()) | ||
| .currentParticipants(currentParticipants) | ||
| .status(party.getStatus()) | ||
| .hostUsername(party.getHost().getNickname()) | ||
| .startDate(party.getCreatedAt()) | ||
| .endDate(party.getClosedAt()) | ||
| .createdAt(party.getCreatedAt()) | ||
|
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, locate and read the PartyResponse.java file
find . -name "PartyResponse.java" -type fRepository: tinybite-2025/tinybite-server Length of output: 140 🏁 Script executed: # Also locate the Party entity
find . -name "Party.java" -type fRepository: tinybite-2025/tinybite-server Length of output: 132 🏁 Script executed: # Check file sizes before reading
wc -l ./src/main/java/ita/tinybite/domain/user/dto/res/PartyResponse.java
wc -l ./src/main/java/ita/tinybite/domain/party/entity/Party.javaRepository: tinybite-2025/tinybite-server Length of output: 207 🏁 Script executed: # Read PartyResponse.java entirely
cat -n ./src/main/java/ita/tinybite/domain/user/dto/res/PartyResponse.javaRepository: tinybite-2025/tinybite-server Length of output: 1960 🏁 Script executed: # Read Party.java to check fields
cat -n ./src/main/java/ita/tinybite/domain/party/entity/Party.javaRepository: tinybite-2025/tinybite-server Length of output: 6650 🏁 Script executed: # Check if there are any null safety patterns for host field
rg "host.*null|host.*Optional" ./src/main/java/ita/tinybite/domain/party/entity/Party.java ./src/main/java/ita/tinybite/domain/user/dto/res/PartyResponse.javaRepository: tinybite-2025/tinybite-server Length of output: 184 🏁 Script executed: # Search for other usages of party.getHost() to see if null checks are done elsewhere
rg "getHost\(\)" --type java -A 2 -B 2 | head -50Repository: tinybite-2025/tinybite-server Length of output: 4923
🔎 NPE 방지를 위한 수정 제안- .hostUsername(party.getHost().getNickname())
+ .hostUsername(party.getHost() != null ? party.getHost().getNickname() : null)🤖 Prompt for AI Agents |
||
| .isHost(isHost) | ||
| .participantStatus(participantStatus) | ||
| .build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| package ita.tinybite.domain.user.service; | ||
|
|
||
| import ita.tinybite.domain.auth.service.SecurityProvider; | ||
| import ita.tinybite.domain.party.entity.Party; | ||
| import ita.tinybite.domain.party.entity.PartyParticipant; | ||
| import ita.tinybite.domain.party.enums.ParticipantStatus; | ||
| import ita.tinybite.domain.party.enums.PartyStatus; | ||
| import ita.tinybite.domain.party.repository.PartyParticipantRepository; | ||
| import ita.tinybite.domain.user.constant.UserStatus; | ||
| import ita.tinybite.domain.user.dto.req.UpdateUserReqDto; | ||
| import ita.tinybite.domain.user.dto.res.PartyResponse; | ||
| import ita.tinybite.domain.user.dto.res.UserResDto; | ||
| import ita.tinybite.domain.user.entity.User; | ||
| import ita.tinybite.domain.user.repository.UserRepository; | ||
|
|
@@ -11,19 +17,25 @@ | |
| import ita.tinybite.global.location.LocationService; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Service | ||
| public class UserService { | ||
|
|
||
| private final SecurityProvider securityProvider; | ||
| private final UserRepository userRepository; | ||
| private final LocationService locationService; | ||
| private final PartyParticipantRepository participantRepository; | ||
|
|
||
| public UserService(SecurityProvider securityProvider, | ||
| UserRepository userRepository, | ||
| LocationService locationService) { | ||
| LocationService locationService, | ||
| PartyParticipantRepository participantRepository) { | ||
| this.securityProvider = securityProvider; | ||
| this.userRepository = userRepository; | ||
| this.locationService = locationService; | ||
| this.participantRepository = participantRepository; | ||
| } | ||
|
|
||
| public UserResDto getUser() { | ||
|
|
@@ -50,4 +62,23 @@ public void validateNickname(String nickname) { | |
| if(userRepository.existsByNickname(nickname)) | ||
| throw BusinessException.of(AuthErrorCode.DUPLICATED_NICKNAME); | ||
| } | ||
|
|
||
| public List<PartyResponse> getActiveParties(Long userId) { | ||
| List<PartyParticipant> participants = participantRepository | ||
| .findActivePartiesByUserId( | ||
| userId, | ||
| PartyStatus.RECRUITING, | ||
| ParticipantStatus.APPROVED | ||
| ); | ||
|
|
||
| return participants.stream() | ||
| .map(pp -> { | ||
| Party party = pp.getParty(); | ||
| int currentParticipants = participantRepository | ||
| .countByPartyIdAndStatus(party.getId(), ParticipantStatus.APPROVED); | ||
| boolean isHost = party.getHost().getUserId().equals(userId); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
호스트가 탈퇴하거나 삭제된 경우 🔎 수정 제안- boolean isHost = party.getHost().getUserId().equals(userId);
+ boolean isHost = party.getHost() != null && party.getHost().getUserId().equals(userId);🤖 Prompt for AI Agents |
||
| return PartyResponse.from(party, currentParticipants, isHost,pp.getStatus()); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
Comment on lines
+74
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. N+1 쿼리 문제가 있습니다. 각 🔎 개선 방안하나의 쿼리로 파티별 참여자 수를 미리 조회하는 방법을 고려해보세요: // Repository에 추가
@Query("SELECT pp.party.id, COUNT(pp) FROM PartyParticipant pp " +
"WHERE pp.party.id IN :partyIds AND pp.status = :status " +
"GROUP BY pp.party.id")
List<Object[]> countByPartyIdsAndStatus(
@Param("partyIds") List<Long> partyIds,
@Param("status") ParticipantStatus status
);또는 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| package ita.tinybite.domain.user.service; | ||
|
|
||
| import ita.tinybite.domain.auth.service.AuthService; | ||
| import ita.tinybite.domain.party.entity.Party; | ||
| import ita.tinybite.domain.party.repository.PartyParticipantRepository; | ||
| import ita.tinybite.domain.user.constant.LoginType; | ||
| import ita.tinybite.domain.user.constant.UserStatus; | ||
| import ita.tinybite.domain.user.dto.req.UpdateUserReqDto; | ||
|
|
@@ -23,6 +25,8 @@ class UserServiceTest { | |
| @Autowired | ||
| private UserRepository userRepository; | ||
|
|
||
| private PartyParticipantRepository participantRepository; | ||
|
|
||
|
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🔎 수정 제안 @Autowired
private UserRepository userRepository;
- private PartyParticipantRepository participantRepository;
+ @Autowired
+ private PartyParticipantRepository participantRepository;또는 Also applies to: 44-44 |
||
| @Autowired | ||
| private AuthService authService; | ||
|
|
||
|
|
@@ -37,7 +41,7 @@ class UserServiceTest { | |
| void setUp() { | ||
| securityProvider = new FakeSecurityProvider(userRepository); | ||
| locationService = new FakeLocationService(); | ||
| userService = new UserService(securityProvider, userRepository, locationService); | ||
| userService = new UserService(securityProvider, userRepository, locationService,participantRepository); | ||
|
|
||
| User user = User.builder() | ||
| .email("yyytir777@gmail.com") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: tinybite-2025/tinybite-server
Length of output: 128
🏁 Script executed:
Repository: tinybite-2025/tinybite-server
Length of output: 141
🏁 Script executed:
# Also search in the repository file itself to understand the context better cat -n src/main/java/ita/tinybite/domain/party/repository/PartyParticipantRepository.javaRepository: tinybite-2025/tinybite-server
Length of output: 2246
🏁 Script executed:
Repository: tinybite-2025/tinybite-server
Length of output: 1653
🏁 Script executed:
Repository: tinybite-2025/tinybite-server
Length of output: 2306
JPQL 파라미터 바인딩 및 필드명 불일치로 런타임 오류가 발생합니다.
@Param("partyStatuses")는 복수형이지만 JPQL에서:partyStatus(단수형)를 사용하여 바인딩이 실패합니다.userId이므로 JPQL에서pp.user.id대신pp.user.userId를 사용해야 합니다.io.lettuce.core.dynamic.annotation.Param을 import하고 있는데, Spring Data JPA 쿼리에는org.springframework.data.jpa.repository.Param을 사용해야 합니다.🔎 수정 제안
🤖 Prompt for AI Agents