Skip to content

Commit

Permalink
Merge pull request #150 from Team-Going/feature/138
Browse files Browse the repository at this point in the history
[fix] 여행 나가기 API 오류 수정
  • Loading branch information
SunwoongH authored Mar 9, 2024
2 parents a80c6f7 + fd7a21b commit 39c2b7d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TripParticipantGetResponse getParticipants(Long userId, Long tripId) {
public void leaveTrip(Long userId, Long tripId) {
User findUser = getUser(userId);
Trip findTrip = getTrip(tripId);
int size = calculateParticipantsCount(findTrip);
int size = participantRepository.countByTrip(findTrip);
Participant findParticipant = getParticipant(findUser, findTrip);
List<Todo> todos = todoRepository.findMyTodoByTripIdAndUserIdAndSecret(tripId, userId, Secret.MY);
todoRepository.deleteAll(todos);
Expand Down Expand Up @@ -130,10 +130,6 @@ private User getUser(Long userId) {
.orElseThrow(() -> new EntityNotFoundException(ErrorMessage.USER_NOT_FOUND));
}

private int calculateParticipantsCount(Trip findTrip) {
return findTrip.getParticipants().size();
}

private Participant getParticipant(User findUser, Trip findTrip) {
return participantRepository.findByUserAndTrip(findUser, findTrip)
.orElseThrow(() -> new EntityNotFoundException(ErrorMessage.PARTICIPANT_NOT_FOUND));
Expand Down Expand Up @@ -166,8 +162,7 @@ private boolean isEqualUserAndParticipantUser(User user, User participantUser) {
private int getValidatedResult(User user) {
if (user.getResult() == null) {
return -1;
}
else {
} else {
return user.getResult().getNumResult();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ParticipantRepository extends JpaRepository<Participant, Long>
boolean existsByUserAndTrip(User user, Trip trip);

Optional<Participant> findByUserAndTrip(User user, Trip trip);

int countByTrip(Trip trip);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public interface TodoRepository extends JpaRepository<Todo, Long> {
"from Todo d " +
"join Trip i " +
"on d.trip = i " +
"join Allocator a " +
"on a.todo = d " +
"join Participant p " +
"on p.trip = i " +
"on a.participant = p " +
"join User u " +
"on p.user = u " +
"where i.id = :tripId " +
Expand Down

0 comments on commit 39c2b7d

Please sign in to comment.