Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface StudyPostQueryService {
StudyPostResDTO.PostListDTO getAllPosts(PageRequest pageRequest, Long studyId, ThemeQuery themeQuery);

// 스터디 게시글 불러오기
StudyPostResDTO.PostDetailDTO getPost(Long studyId, Long postId);
StudyPostResDTO.PostDetailDTO getPost(Long studyId, Long postId, Boolean likeOrScrap);

// 스터디 게시글 댓글 목록 불러오기
StudyPostCommentResponseDTO.CommentReplyListDTO getAllComments(Long studyId, Long postId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ public StudyPostResDTO.PostListDTO getAllPosts(PageRequest pageRequest, Long stu

/**
* 스터디 게시판의 특정 게시글을 조회하는 메서드입니다.
* @param studyId 게시글을 조회할 타겟 스터디의 아이디를 입력 받습니다.
* @param postId 조회할 타겟 게시글의 아이디를 입력 받습니다.
*
* @param studyId 게시글을 조회할 타겟 스터디의 아이디를 입력 받습니다.
* @param postId 조회할 타겟 게시글의 아이디를 입력 받습니다.
* @param likeOrScrap
* @return 스터디 게시글의 정보를 반환합니다.
*/
@Override
@Transactional(readOnly = false)
public StudyPostResDTO.PostDetailDTO getPost(Long studyId, Long postId) {
public StudyPostResDTO.PostDetailDTO getPost(Long studyId, Long postId, Boolean likeOrScrap) {

//=== Exception ===//
Long memberId = SecurityUtils.getCurrentUserId();
Expand All @@ -121,7 +123,12 @@ public StudyPostResDTO.PostDetailDTO getPost(Long studyId, Long postId) {
.orElseThrow(() -> new StudyHandler(ErrorStatus._STUDY_MEMBER_NOT_FOUND));

//=== Feature ===//
studyPost.plusHitNum();

// 조회수 증가는 일반 조회 시에만 실행
if (!likeOrScrap) {
studyPost.plusHitNum();
}

studyPost = studyPostRepository.save(studyPost);
memberRepository.save(member);
studyRepository.save(study);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public ApiResponse<StudyPostResDTO.PostListDTO> getAllPosts(
@GetMapping("/studies/{studyId}/posts/{postId}")
public ApiResponse<StudyPostResDTO.PostDetailDTO> getPost(
@PathVariable @ExistStudy Long studyId,
@PathVariable @ExistStudyPost Long postId) {
StudyPostResDTO.PostDetailDTO postDetailDTO = studyPostQueryService.getPost(studyId, postId);
@PathVariable @ExistStudyPost Long postId,
@RequestParam Boolean likeOrScrap) {
StudyPostResDTO.PostDetailDTO postDetailDTO = studyPostQueryService.getPost(studyId, postId, likeOrScrap);
return ApiResponse.onSuccess(SuccessStatus._STUDY_POST_FOUND, postDetailDTO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ void getAllPosts_NotCategorized_Fail() {
/*-------------------------------------------------------- 게시글 조회 ------------------------------------------------------------------------*/

@Test
@DisplayName("스터디 게시글 단건 조회 - (성공)")
void getPost_Success() {
@DisplayName("스터디 게시글 단건 조회 - 일반 조회 (성공)")
void getPost_Common_Success() {

// given
Long studyId = 1L;
Expand All @@ -280,7 +280,7 @@ void getPost_Success() {
.thenReturn(false);

// when
StudyPostResDTO.PostDetailDTO result = studyPostQueryService.getPost(studyId, postId);
StudyPostResDTO.PostDetailDTO result = studyPostQueryService.getPost(studyId, postId, false);

// then
assertNotNull(result);
Expand All @@ -289,11 +289,43 @@ void getPost_Success() {
assertThat(result.getTitle()).isEqualTo("잡담");
assertThat(result.getCommentNum()).isEqualTo(2);
assertThat(result.getIsLiked()).isEqualTo(false);
}

@Test
@DisplayName("스터디 게시글 단건 조회 - 스크랩 혹은 좋아요 후 업데이트 (성공)")
void getPost_LikeOrScrap_Success() {

// given
Long studyId = 1L;
Long memberId = 1L;
Long postId = 1L;

getAuthentication(memberId);

when(studyPostRepository.findByIdAndStudyId(postId, studyId))
.thenReturn(Optional.of(studyPost1));
when(studyPostRepository.save(studyPost1)).thenReturn(studyPost1);
when(memberRepository.save(member1)).thenReturn(member1);
when(studyRepository.save(study)).thenReturn(study);
when(studyPostCommentRepository.findAllByStudyPostId(postId))
.thenReturn(List.of(studyPost1Comment1, studyPost1Comment2));
when(studyLikedPostRepository.existsByMemberIdAndStudyPostId(memberId, postId))
.thenReturn(false);

// when
StudyPostResDTO.PostDetailDTO result = studyPostQueryService.getPost(studyId, postId, true);

// then
assertNotNull(result);
assertThat(result.getPostId()).isEqualTo(1L);
assertThat(result.getHitNum()).isEqualTo(10);
assertThat(result.getTitle()).isEqualTo("잡담");
assertThat(result.getCommentNum()).isEqualTo(2);
assertThat(result.getIsLiked()).isEqualTo(false);
}

@Test
@DisplayName("스터디 게시글 단건 조회 - 스터디 회원이 아닌 경우(실패)")
@DisplayName("스터디 게시글 단건 조회 - 스터디 회원이 아닌 경우 (실패)")
void getPost_NotStudyMember_Fail() {

// given
Expand All @@ -314,7 +346,7 @@ void getPost_NotStudyMember_Fail() {
.thenReturn(false);

// when & then
assertThrows(StudyHandler.class, () ->studyPostQueryService.getPost(studyId, postId));
assertThrows(StudyHandler.class, () ->studyPostQueryService.getPost(studyId, postId, false));
}

@Test
Expand All @@ -334,7 +366,7 @@ void getPost_NotStudyPost_Fail() {
.thenReturn(List.of());

// when & then
assertThrows(StudyHandler.class, () ->studyPostQueryService.getPost(studyId, postId));
assertThrows(StudyHandler.class, () ->studyPostQueryService.getPost(studyId, postId, false));
}

/*-------------------------------------------------------- 댓글 목록 조회 ------------------------------------------------------------------------*/
Expand Down