Skip to content

Commit

Permalink
fix: LEFT JOIN 사용하도록 쿼리 수정 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaewon-io committed Aug 23, 2024
1 parent da975ae commit a83e58d
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -15,11 +16,14 @@ public interface MissionRepository extends JpaRepository<Mission, Long> {

List<Mission> findAllByMeetingId(Long meetingId);

@Query("SELECT new com.dnd.snappy.domain.mission.dto.response.LeaderMeetingMissionDetailResponseDto(m.id, m.content, " +
"EXISTS (SELECT 1 FROM MissionParticipant mp WHERE mp.mission.id = m.id)) " +
"FROM Mission m " +
"JOIN Participant p ON p.meeting.id = m.meeting.id " +
"WHERE p.id = :participantId AND p.role = 'LEADER' AND m.meeting.id = :meetingId")
@Query("""
SELECT new com.dnd.snappy.domain.mission.dto.response.LeaderMeetingMissionDetailResponseDto(m.id, m.content,
CASE WHEN mp.id IS NOT NULL THEN TRUE ELSE FALSE END)
FROM Mission m
LEFT JOIN MissionParticipant mp ON mp.mission.id = m.id
JOIN Participant p ON p.meeting.id = m.meeting.id
WHERE p.id = :participantId AND p.role = 'LEADER' AND m.meeting.id = :meetingId
""")
List<LeaderMeetingMissionDetailResponseDto> findLeaderMeetingMissions(@Param("meetingId") Long meetingId, @Param("participantId") Long participantId);

}

0 comments on commit a83e58d

Please sign in to comment.