-
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.
Browse files
Browse the repository at this point in the history
…-115 ✨ [feature] #86 - 스터디 댓글 작성, 삭제, 조회 API
- Loading branch information
Showing
23 changed files
with
325 additions
and
104 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
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
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
1 change: 0 additions & 1 deletion
1
src/main/java/gaji/service/domain/recruit/repository/RecruitPostBookmarkRepository.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
11 changes: 11 additions & 0 deletions
11
src/main/java/gaji/service/domain/recruit/repository/StudyCommentCustomRepository.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package gaji.service.domain.recruit.repository; | ||
|
||
import gaji.service.domain.recruit.entity.StudyComment; | ||
import gaji.service.domain.room.entity.Room; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
|
||
public interface StudyCommentCustomRepository { | ||
Slice<StudyComment> findByRoomFetchJoinWithUser( | ||
Integer lastCommentOrder, Integer lastDepth, Long lastCommentId, Room room, Pageable pageable); | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/gaji/service/domain/recruit/repository/StudyCommentCustomRepositoryImpl.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package gaji.service.domain.recruit.repository; | ||
|
||
import com.querydsl.core.types.OrderSpecifier; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import gaji.service.domain.recruit.entity.StudyComment; | ||
import gaji.service.domain.room.entity.Room; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.domain.SliceImpl; | ||
import org.springframework.stereotype.Repository; | ||
import java.util.List; | ||
|
||
import static gaji.service.domain.recruit.entity.QStudyComment.studyComment; | ||
import static gaji.service.domain.user.entity.QUser.user; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class StudyCommentCustomRepositoryImpl implements StudyCommentCustomRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Slice<StudyComment> findByRoomFetchJoinWithUser( | ||
Integer lastCommentOrder, Integer lastDepth, Long lastCommentId, Room room, Pageable pageable) { | ||
List<StudyComment> commentList = jpaQueryFactory | ||
.select(studyComment) | ||
.from(studyComment) | ||
.leftJoin(studyComment.user, user) | ||
.fetchJoin() | ||
.where( | ||
studyComment.room.eq(room), | ||
gtCommentOrderDepthAndCommentId(lastCommentOrder, lastDepth, lastCommentId) | ||
) | ||
.orderBy( | ||
orderByCommentOrderAndDepth() | ||
) | ||
.limit(pageable.getPageSize() + 1) | ||
.fetch(); | ||
return checkLastPage(pageable, commentList); | ||
} | ||
|
||
private BooleanExpression gtCommentOrderDepthAndCommentId( | ||
Integer lastCommentOrder, Integer lastDepth, Long lastId) { | ||
if (lastCommentOrder == null || lastDepth == null || lastId == null) { | ||
return null; | ||
} | ||
|
||
return studyComment.commentOrder.gt(lastCommentOrder) // 다음 commentOrder로 넘어가는 경우 | ||
.or( | ||
studyComment.commentOrder.eq(lastCommentOrder) | ||
.and( | ||
studyComment.depth.gt(lastDepth) // 동일한 commentOrder 내에서 depth가 더 큰 경우 | ||
.or( | ||
studyComment.depth.eq(lastDepth) | ||
.and( | ||
studyComment.id.gt(lastId)) // 동일한 depth 내에서 createdAt이 더 큰 경우 | ||
) | ||
) | ||
); | ||
} | ||
|
||
private Slice<StudyComment> checkLastPage(Pageable pageable, List<StudyComment> commentList) { | ||
boolean hasNext = false; | ||
|
||
if (commentList.size() > pageable.getPageSize()) { | ||
hasNext = true; | ||
commentList.remove(pageable.getPageSize()); | ||
} | ||
|
||
return new SliceImpl<>(commentList, pageable, hasNext); | ||
} | ||
|
||
private OrderSpecifier[] orderByCommentOrderAndDepth() { | ||
return new OrderSpecifier[] { | ||
studyComment.commentOrder.asc(), | ||
studyComment.depth.asc(), | ||
studyComment.createdAt.asc() | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.