Skip to content

Commit

Permalink
#6 fix: count 메소드 재정의
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim committed Sep 19, 2023
1 parent ff52a88 commit 08c93fa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface AnswerRepository extends JpaRepository<Answer, Long> {
Long countByAnswerer_UserIdxAndStatusEquals(Long userIdx, String status);
Page<Answer> findByAnswerer_UserIdxAndPost_IsJuicyAndStatusEquals(Long userIdx, Boolean isJuicy, String status, Pageable pageable);
Long countByPost_PostIdxAndStatusEquals(Long postIdx, String status);
int countByPostAndIsJuicyFalse(Post post);
Long countByPost(Post post);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void addAnswer(Long userIdx, PostAnswerReq postAnswerReq) throws BaseExce
try {
User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER));
Post post = postRepository.findById(postAnswerReq.getPostIdx()).orElseThrow(() -> new BaseException(INVALID_POST_IDX));
int currentAnswerCount = answerRepository.countByPostAndIsJuicyFalse(post);
Long currentAnswerCount = answerRepository.countByPost(post);
if (user.getRole().equals(SINY)) {
if (currentAnswerCount < 3) { // 크론잡 주기 사이에 답변이 등록되어 isJuicy 컬럼값에 아직 반영이 안된 경우를 위해 예외처리
Answer answer = Answer.builder()
Expand All @@ -36,7 +36,7 @@ public void addAnswer(Long userIdx, PostAnswerReq postAnswerReq) throws BaseExce
.build();
answerRepository.save(answer);

currentAnswerCount = answerRepository.countByPostAndIsJuicyFalse(post); //currentAnswerCount 최신화
currentAnswerCount = answerRepository.countByPost(post); //currentAnswerCount 최신화
// 3번째 답변이면 쥬시글로 전환
if (currentAnswerCount == 3) {
post.setIsJuicy(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public GetPostRes getPost(Long postIdx, Long userIdx) throws BaseException {
User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER));
return new GetPostRes(post.getCategory().toString(), getCardList(post), post.getLastModifiedDate(),
post.getCommentCount(), post.getScrapCount(), isScrap(user, post), getCommentList(post, user));

} catch (BaseException e) {
throw e;
} catch (Exception e) {
Expand Down

0 comments on commit 08c93fa

Please sign in to comment.