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); }