-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
무한 스크롤 방식으로 변경
- Loading branch information
Showing
6 changed files
with
72 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 25 additions & 7 deletions
32
src/main/java/gaji/service/domain/room/repository/RoomNoticeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
package gaji.service.domain.room.repository; | ||
|
||
import gaji.service.domain.room.entity.RoomNotice; | ||
import gaji.service.domain.room.web.dto.RoomResponseDto; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface RoomNoticeRepository extends JpaRepository<RoomNotice, Long> { | ||
@Modifying | ||
@Query("UPDATE RoomNotice rn SET rn.confirmCount = rn.confirmCount + 1 WHERE rn.id = :noticeId") | ||
void incrementConfirmCount(Long noticeId); | ||
@Query("SELECT NEW gaji.service.domain.room.web.dto.RoomResponseDto$NoticeDto(" + | ||
"rn.id, sm.user.name, rn.title, rn.body, CAST(COUNT(nc) AS Long), rn.createdAt, rn.viewCount) " + | ||
"FROM RoomNotice rn " + | ||
"JOIN rn.studyMate sm " + | ||
"LEFT JOIN NoticeConfirmation nc ON nc.roomNotice.id = rn.id " + | ||
"WHERE sm.room.id = :roomId AND rn.createdAt <= :lastCreatedAt " + | ||
"GROUP BY rn.id, sm.user.name, rn.title, rn.body, rn.createdAt, rn.viewCount " + | ||
"ORDER BY rn.createdAt DESC, rn.id DESC") | ||
List<RoomResponseDto.NoticeDto> findNoticeSummariesForInfiniteScroll( | ||
@Param("roomId") Long roomId, | ||
@Param("lastCreatedAt") LocalDateTime lastCreatedAt, | ||
Pageable pageable); | ||
|
||
@Modifying | ||
@Query("UPDATE RoomNotice rn SET rn.confirmCount = rn.confirmCount - 1 WHERE rn.id = :noticeId AND rn.confirmCount > 0") | ||
void decrementConfirmCount(Long noticeId); | ||
@Query("SELECT CASE " + | ||
"WHEN EXISTS (SELECT 1 FROM RoomNotice rn WHERE rn.studyMate.room.id = :roomId AND rn.id = :noticeId) " + | ||
"THEN (SELECT rn.createdAt FROM RoomNotice rn WHERE rn.studyMate.room.id = :roomId AND rn.id = :noticeId) " + | ||
"ELSE (SELECT MAX(rn.createdAt) FROM RoomNotice rn WHERE rn.studyMate.room.id = :roomId) " + | ||
"END") | ||
Optional<LocalDateTime> findCreatedAtByIdOrEarliest(@Param("roomId") Long roomId, @Param("noticeId") Long noticeId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters