Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #214 from FinFellows/develop
Browse files Browse the repository at this point in the history
[FIX]: 교육 컨텐츠 상세조회 bookmark 출력 에러 수정
  • Loading branch information
LEEJaeHyeok97 authored Jan 19, 2024
2 parents 6c7883e + 0fd4f92 commit 71ff37d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.finfellows.domain.educontent.dto.response.EduContentResponse;
import com.finfellows.domain.post.domain.Post;
import com.finfellows.domain.post.domain.repository.PostRepository;
import com.finfellows.global.config.security.token.UserPrincipal;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -58,14 +59,21 @@ public Page<EduContentResponse> getAllEduContents(Long userId, Pageable pageable
return new PageImpl<>(eduContentResponses, pageable, eduContentPage.getTotalElements());
}

public EduContentResponse getEduContent(Long id) {
public EduContentResponse getEduContent(UserPrincipal userPrincipal, Long id) {
EduContent eduContent = eduContentRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id));

Boolean isBookmarked = false;
if (userPrincipal != null) {
isBookmarked = eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userPrincipal.getId(), id);
}


return EduContentResponse.builder()
.id(eduContent.getId())
.title(eduContent.getTitle())
.content(eduContent.getContent())
.bookmarked(isBookmarked)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public ResponseEntity<Page<EduContentResponse>> getAllEduContents(@CurrentUser U
@Content(mediaType = "application/json", schema = @Schema(implementation = EduContentResponse.class))
})
@GetMapping("/{id}")
public ResponseEntity<EduContentResponse> getEduContent(@PathVariable Long id) {
EduContentResponse response = eduContentService.getEduContent(id);
public ResponseEntity<EduContentResponse> getEduContent(@CurrentUser UserPrincipal userPrincipal, @PathVariable Long id) {
EduContentResponse response = eduContentService.getEduContent(userPrincipal, id);
return new ResponseEntity<>(response, HttpStatus.OK);
}

Expand Down

0 comments on commit 71ff37d

Please sign in to comment.