Skip to content
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

[fix] 여행 나가기 API 오류 수정 #150

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading