From 0fd4f92bcbd2815817767215329c4d86b76fd919 Mon Sep 17 00:00:00 2001 From: LeeJaeHyeok97 Date: Fri, 19 Jan 2024 10:15:27 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]:=20=EA=B5=90=EC=9C=A1=20=EC=BB=A8?= =?UTF-8?q?=ED=85=90=EC=B8=A0=20=EC=83=81=EC=84=B8=EC=A1=B0=ED=9A=8C=20boo?= =?UTF-8?q?kmark=20=EC=B6=9C=EB=A0=A5=20=EC=97=90=EB=9F=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../educontent/application/EduContentService.java | 10 +++++++++- .../educontent/presentation/EduContentController.java | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java b/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java index d001dbe..891030d 100644 --- a/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java +++ b/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java @@ -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; @@ -58,14 +59,21 @@ public Page 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(); } diff --git a/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java b/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java index 06f2367..cd1a6d1 100644 --- a/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java +++ b/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java @@ -64,8 +64,8 @@ public ResponseEntity> getAllEduContents(@CurrentUser U @Content(mediaType = "application/json", schema = @Schema(implementation = EduContentResponse.class)) }) @GetMapping("/{id}") - public ResponseEntity getEduContent(@PathVariable Long id) { - EduContentResponse response = eduContentService.getEduContent(id); + public ResponseEntity getEduContent(@CurrentUser UserPrincipal userPrincipal, @PathVariable Long id) { + EduContentResponse response = eduContentService.getEduContent(userPrincipal, id); return new ResponseEntity<>(response, HttpStatus.OK); }