Skip to content

Commit

Permalink
Merge pull request #87 from Team-Going/feature/86
Browse files Browse the repository at this point in the history
[fix] 여행 My TODO 개수 조회 쿼리 오류 수정
  • Loading branch information
SunwoongH authored Jan 14, 2024
2 parents 928cbbd + ff23129 commit 47c9b2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public ResponseEntity<ApiResponse<?>> entryTrip(@PathVariable final Long tripId,
}

@GetMapping("/{tripId}/my")
public ResponseEntity<ApiResponse<?>> getMyTodoDetail(@PathVariable final Long tripId) {
final MyTodoResponse response = tripDetailService.getMyTodoDetail(tripId);
public ResponseEntity<ApiResponse<?>> getMyTodoDetail(@UserId final Long userId,
@PathVariable final Long tripId) {
final MyTodoResponse response = tripDetailService.getMyTodoDetail(userId, tripId);
return ApiResponseUtil.success(SuccessMessage.OK, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class TripDetailService {
private final TripRepository tripRepository;
private final TodoRepository todoRepository;

public MyTodoResponse getMyTodoDetail(Long tripId) {
public MyTodoResponse getMyTodoDetail(Long userId, Long tripId) {
Trip findTrip = getTrip(tripId);
int count = getIncompleteTodoCount(tripId);
int count = getIncompleteTodoCount(userId, tripId);
return MyTodoResponse.of(findTrip.getTitle(), count);
}

Expand Down Expand Up @@ -61,8 +61,8 @@ private Map<String, Integer> createDefaultPropensity() {
};
}

private int getIncompleteTodoCount(Long tripId) {
return todoRepository.countTodoByTripIdAndProgress(tripId, Progress.INCOMPLETE);
private int getIncompleteTodoCount(Long userId, Long tripId) {
return todoRepository.countTodoByTripIdAndUserIdAndProgress(tripId, userId, Progress.INCOMPLETE);
}

private boolean judgeTrip(Trip trip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ public interface TodoRepository extends JpaRepository<Todo, Long> {
List<Todo> findMyTodoByTripId(@Param("tripId") Long tripId, @Param("userId") Long userId, @Param("progress") Progress progress);

int countTodoByTripIdAndProgress(Long tripId, Progress progress);

@Query("select count(*) " +
"from Todo d " +
"join Trip i " +
"on d.trip = i " +
"join Allocator a " +
"on a.todo = d " +
"join Participant p " +
"on a.participant = p " +
"join User u " +
"on p.user = u " +
"where i.id = :tripId " +
"and u.id = :userId " +
"and d.progress = :progress")
int countTodoByTripIdAndUserIdAndProgress(@Param("tripId") Long tripId, @Param("userId") Long userId, @Param("progress") Progress progress);
}

0 comments on commit 47c9b2e

Please sign in to comment.