From ab0ed07a5e016536d5ded886097814d7e80a43db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= <67510260+LEEJaeHyeok97@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:43:13 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[REFACTOR]:=20refresh=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=A7=A4=ED=95=91,=20eduContentBookmark=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20deprecated=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C,=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20code=20=EB=B0=9C?= =?UTF-8?q?=EA=B8=89=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC=20(#68)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FEAT]#9 즐겨찾기 API 구현 * [FIX]#9 ApiResponse 수정 * [FEAT]#10 마이페이지 즐겨찾기 내역 조회 API 구현 * [REFACTOR]: refresh 메소드매핑, eduContentBookmark 관련 deprecated 코드 삭제, 카카오 code 발급 주석처리 --- .../auth/presentation/AuthController.java | 19 ++-- .../EduContentBookmarkServiceImpl.java | 88 ------------------- .../FinancialProductBookmarkServiceImpl.java | 14 ++- .../EduContentBookmarkRepository.java | 16 ---- .../domain/bookmark/dto/BookmarkRes.java | 15 ---- .../bookmark/dto/EduContentBookmarkRes.java | 33 ------- .../presentation/BookmarkController.java | 2 - .../user/presentation/UserController.java | 6 -- 8 files changed, 15 insertions(+), 178 deletions(-) delete mode 100644 src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java delete mode 100644 src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java delete mode 100644 src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java delete mode 100644 src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java diff --git a/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java b/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java index d18b716..c285c65 100644 --- a/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/finfellows/domain/auth/presentation/AuthController.java @@ -36,15 +36,15 @@ public class AuthController { private final KakaoService kakaoService; - @Operation(summary = "카카오 code 발급", description = "카카오 API 서버에 접근 권한을 인가하는 code를 발급받습니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "code 발급 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = AuthRes.class))}), - @ApiResponse(responseCode = "400", description = "code 발급 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), - }) - @GetMapping(value = "/login") - public void socialLoginRedirect() throws IOException { - kakaoService.accessRequest(); - } +// @Operation(summary = "카카오 code 발급", description = "카카오 API 서버에 접근 권한을 인가하는 code를 발급받습니다.") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "200", description = "code 발급 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = AuthRes.class))}), +// @ApiResponse(responseCode = "400", description = "code 발급 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), +// }) +// @GetMapping(value = "/login") +// public void socialLoginRedirect() throws IOException { +// kakaoService.accessRequest(); +// } @Operation(summary = "유저 정보 확인", description = "현재 접속 중인 유저의 정보를 확인합니다.") @ApiResponses(value = { @@ -123,6 +123,7 @@ public ResponseCustom deleteAccount( @ApiResponse(responseCode = "200", description = "토큰 갱신 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AuthRes.class) ) } ), @ApiResponse(responseCode = "400", description = "토큰 갱신 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), }) + @PostMapping("/refresh") public ResponseEntity refresh( @Parameter(description = "Schemas의 RefreshTokenReq를 참고해주세요.", required = true) @Valid @RequestBody RefreshTokenReq refreshTokenReq ) { diff --git a/src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java deleted file mode 100644 index b47138f..0000000 --- a/src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.finfellows.domain.bookmark.application; - -import com.finfellows.domain.bookmark.domain.EduContentBookmark; -import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; -import com.finfellows.domain.bookmark.dto.EduContentBookmarkRes; -import com.finfellows.domain.educontent.domain.EduContent; -import com.finfellows.domain.educontent.domain.repository.EduContentRepository; -import com.finfellows.domain.post.domain.Post; -import com.finfellows.domain.post.domain.repository.PostRepository; -import com.finfellows.domain.user.domain.User; -import com.finfellows.domain.user.domain.repository.UserRepository; -import com.finfellows.global.config.security.token.UserPrincipal; -import com.finfellows.global.payload.Message; -import com.finfellows.global.payload.ResponseCustom; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; - -@Service -@RequiredArgsConstructor -public class EduContentBookmarkServiceImpl implements BookmarkService{ - private final EduContentBookmarkRepository eduContentBookmarkRepository; - private final UserRepository userRepository; - private final EduContentRepository eduContentRepository; - private final PostRepository postRepository; - - @Transactional - @Override - public Message insert(UserPrincipal userPrincipal, Long id) { - Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); - Optional optionalEduContent = eduContentRepository.findById(id); - - User user = optionalUser.get(); - EduContent eduContent = optionalEduContent.get(); - - - - EduContentBookmark eduContentBookmark = EduContentBookmark.builder() - .user(user) - .eduContent(eduContent) - .build(); - - eduContentBookmarkRepository.save(eduContentBookmark); - - return Message.builder() - .message("즐겨찾기 추가에 성공했습니다.") - .build(); - - } - - @Transactional - @Override - public Message delete(UserPrincipal userPrincipal, Long id) { - - Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); - Optional optionalEduContent = eduContentRepository.findById(id); - - User user = optionalUser.get(); - EduContent eduContent = optionalEduContent.get(); - - EduContentBookmark eduContentBookmark = eduContentBookmarkRepository.findByUserAndEduContent(user, eduContent).get(); - - eduContentBookmarkRepository.delete(eduContentBookmark); - - - return Message.builder() - .message("즐겨찾기 삭제에 성공했습니다.") - .build(); - } - - public ResponseCustom> findBookmarks(UserPrincipal userPrincipal) { - Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); - - User user = optionalUser.get(); - - List bookmarks = eduContentBookmarkRepository.findAllByUser(user); - - - List eduContentBookmarkResList = EduContentBookmarkRes.toDto(bookmarks); - - - return ResponseCustom.OK(eduContentBookmarkResList); - } -} diff --git a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java index 9e9c493..5d43e6c 100644 --- a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java +++ b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java @@ -1,10 +1,8 @@ package com.finfellows.domain.bookmark.application; -import com.finfellows.domain.bookmark.domain.EduContentBookmark; import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; -import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; import com.finfellows.domain.bookmark.domain.repository.FinancialProductBookmarkRepository; -import com.finfellows.domain.bookmark.dto.EduContentBookmarkRes; +import com.finfellows.domain.bookmark.dto.FinancialProductBookmarkRes; import com.finfellows.domain.product.domain.FinancialProduct; import com.finfellows.domain.product.domain.repository.FinancialProductRepository; import com.finfellows.domain.user.domain.User; @@ -13,7 +11,6 @@ import com.finfellows.global.payload.Message; import com.finfellows.global.payload.ResponseCustom; import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,7 +23,6 @@ public class FinancialProductBookmarkServiceImpl implements BookmarkService{ private final FinancialProductBookmarkRepository financialProductBookmarkRepository; private final UserRepository userRepository; private final FinancialProductRepository financialProductRepository; - private final EduContentBookmarkRepository eduContentBookmarkRepository; @Transactional @@ -70,18 +66,18 @@ public Message delete(UserPrincipal userPrincipal, Long id) { .build(); } - public ResponseCustom> findBookmarks(UserPrincipal userPrincipal) { + public ResponseCustom> findBookmarks(UserPrincipal userPrincipal) { Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); User user = optionalUser.get(); - List bookmarks = eduContentBookmarkRepository.findAllByUser(user); + List bookmarks = financialProductBookmarkRepository.findAllByUser(user); - List eduContentBookmarkResList = EduContentBookmarkRes.toDto(bookmarks); + List financialProductBookmarkResList = FinancialProductBookmarkRes.toDto(bookmarks); - return ResponseCustom.OK(eduContentBookmarkResList); + return ResponseCustom.OK(financialProductBookmarkResList); } } \ No newline at end of file diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java b/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java deleted file mode 100644 index 8d147e8..0000000 --- a/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.finfellows.domain.bookmark.domain.repository; - -import com.finfellows.domain.bookmark.domain.EduContentBookmark; -import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; -import com.finfellows.domain.educontent.domain.EduContent; -import com.finfellows.domain.user.domain.User; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; -import java.util.Optional; - -public interface EduContentBookmarkRepository extends JpaRepository { - Optional findByUserAndEduContent(User user, EduContent eduContent); - - List findAllByUser(User user); -} diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java deleted file mode 100644 index cc8c5ec..0000000 --- a/src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.finfellows.domain.bookmark.dto; - -import lombok.Builder; -import lombok.Data; - -@Data -public class BookmarkRes { - private int id; - - - @Builder - public BookmarkRes(int id) { - this.id = id; - } -} diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java deleted file mode 100644 index 336f2b0..0000000 --- a/src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.finfellows.domain.bookmark.dto; - -import com.finfellows.domain.bookmark.domain.EduContentBookmark; -import com.finfellows.domain.educontent.domain.EduContent; -import com.finfellows.domain.product.domain.FinancialProductType; -import lombok.Builder; -import lombok.Data; - -import java.util.List; -import java.util.stream.Collectors; - -@Data -public class EduContentBookmarkRes { - private Long id; - private String content; - - - @Builder - public EduContentBookmarkRes(Long id, String content) { - this.id = id; - this.content = content; - } - - public static List toDto(List bookmarks) { - return bookmarks.stream() - .map(bookmark -> EduContentBookmarkRes.builder() - .id(bookmark.getEduContent().getId()) - .content(bookmark.getEduContent().getContent()) - .build()) - .collect(Collectors.toList()); - } - -} diff --git a/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java b/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java index a6562fc..0050eb7 100644 --- a/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java +++ b/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java @@ -1,6 +1,5 @@ package com.finfellows.domain.bookmark.presentation; -import com.finfellows.domain.bookmark.application.EduContentBookmarkServiceImpl; import com.finfellows.domain.bookmark.application.FinancialProductBookmarkServiceImpl; import com.finfellows.domain.bookmark.application.PolicyInfoBookmarkServiceImpl; import com.finfellows.domain.bookmark.application.PostBookmarkServiceImpl; @@ -28,7 +27,6 @@ @RestController @RequestMapping("/bookmarks") public class BookmarkController { - private final EduContentBookmarkServiceImpl eduContentBookmarkService; private final FinancialProductBookmarkServiceImpl financialProductBookmarkService; private final PolicyInfoBookmarkServiceImpl policyInfoBookmarkService; private final PostBookmarkServiceImpl postBookmarkService; diff --git a/src/main/java/com/finfellows/domain/user/presentation/UserController.java b/src/main/java/com/finfellows/domain/user/presentation/UserController.java index 5f5011d..d91e78c 100644 --- a/src/main/java/com/finfellows/domain/user/presentation/UserController.java +++ b/src/main/java/com/finfellows/domain/user/presentation/UserController.java @@ -1,11 +1,8 @@ package com.finfellows.domain.user.presentation; -import com.finfellows.domain.bookmark.application.EduContentBookmarkServiceImpl; import com.finfellows.domain.bookmark.application.FinancialProductBookmarkServiceImpl; import com.finfellows.domain.bookmark.application.PolicyInfoBookmarkServiceImpl; import com.finfellows.domain.bookmark.application.PostBookmarkServiceImpl; -import com.finfellows.domain.user.application.UserService; -import com.finfellows.domain.user.domain.User; import com.finfellows.global.config.security.token.CurrentUser; import com.finfellows.global.config.security.token.UserPrincipal; import com.finfellows.global.payload.ErrorResponse; @@ -19,8 +16,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -30,7 +25,6 @@ @RequiredArgsConstructor @RequestMapping("/users") public class UserController { - private final EduContentBookmarkServiceImpl eduContentBookmarkService; private final FinancialProductBookmarkServiceImpl financialProductBookmarkService; private final PolicyInfoBookmarkServiceImpl policyInfoBookmarkService; private final PostBookmarkServiceImpl postBookmarkService; From d25e22fb130a2dee8d09765c3e53b5c85c06e55b Mon Sep 17 00:00:00 2001 From: Eunbeen Noh <101248968+EunbeenDev@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:48:17 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]:=20NewContent,=20EduContnet=20reponse?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FEAT] #3 ChatGPT 응답 단답 확인 과정 테스트 * [FIX] #3 SecurityConfig permitAll 추가 * [FEAT] #3 ChatgptRequest 추가 GPT Request DTO format * [FIX] #3 Chatgpt dependencies 추가 * [FEAT] #14 EduContent DTO 생성 * [FIX] #14 Post AccessLevel 수정 * [FEAT] #14 educontent 저장 api 구현 * [FEAT] #14 educontent 조회/상세조회/수정/삭제 api 구현 * [FEAT] #15 newscontent 저장/조회/상세조회/수정/삭제 api 구현 * [FEAT] #19 content 저장/조회/상세조회/수정/삭제 api 구현 * [FEAT] #19 swagger 설정 추가 * [FEAT] #19 readOnly를 위한 Transactional 어노테이션 추가 * [FEAT] #39 chatbot, comment 파일 추가 * fix: chat gpt 수정 * [FIX] #19 Transactional annotation readOnly default 수정 * Revert "[FIX] #19 Transactional annotation readOnly default 수정" This reverts commit 4a18b0ebce60ff41bdacac044fd6c365adf49ca4. * [FIX] #19 Transactional annotation readOnly default 수정 * [FEAT] #39 챗봇 질의응답 기능 개발 인사말 추가, 질의응답, 조회 기능 * [FEAT] educontent created_at 요청/응답 필드 추가 * [FIX] #39 챗봇 요청/응답값 UserId 부분 수정 * [FIX] #39 챗봇 요청/응답값 UserId 부분 수정 * [FIX] #39 swagger 코드 추가 * [FIX] #52 Post Entity enum type 추가 * [FIX] #54 금융 배우자 북마크 여부 Response 추가 --------- Co-authored-by: 박세진 Co-authored-by: Sejin Park <95167215+sejineer@users.noreply.github.com> --- .../EduContentBookmarkRepository.java | 18 ++++++++++++++++++ .../application/EduContentService.java | 10 +++++++++- .../dto/response/EduContentResponse.java | 1 + .../presentation/EduContentController.java | 6 ++++-- .../application/NewsContentService.java | 12 +++++++++++- .../dto/response/NewsContentResponse.java | 1 + .../presentation/NewsContentController.java | 6 ++++-- 7 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java b/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java new file mode 100644 index 0000000..e64fb22 --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java @@ -0,0 +1,18 @@ +package com.finfellows.domain.bookmark.domain.repository; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; +import com.finfellows.domain.educontent.domain.EduContent; +import com.finfellows.domain.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface EduContentBookmarkRepository extends JpaRepository { + Optional findByUserAndEduContent(User user, EduContent eduContent); + + List findAllByUser(User user); + + boolean existsByUser_IdAndEduContent_Id(Long userId, Long id); +} 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 437605e..1b31cf0 100644 --- a/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java +++ b/src/main/java/com/finfellows/domain/educontent/application/EduContentService.java @@ -1,5 +1,6 @@ package com.finfellows.domain.educontent.application; +import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; import com.finfellows.domain.educontent.domain.EduContent; import com.finfellows.domain.educontent.domain.repository.EduContentRepository; import com.finfellows.domain.educontent.dto.request.EduContentRequest; @@ -20,6 +21,7 @@ public class EduContentService { private final EduContentRepository eduContentRepository; private final PostRepository postRepository; + private final EduContentBookmarkRepository eduContentBookmarkRepository; @Transactional public EduContent createEduContent(EduContentResponse request) { @@ -38,13 +40,14 @@ public EduContent createEduContent(EduContentResponse request) { return savedContent; } - public List getAllEduContents() { + public List getAllEduContents(Long userId) { List eduContents = eduContentRepository.findAll(); return eduContents.stream() .map(eduContent -> EduContentResponse.builder() .id(eduContent.getId()) .title(eduContent.getTitle()) .content(eduContent.getContent()) + .bookmarked(checkBookmarked(userId, eduContent.getId())) .build()) .collect(Collectors.toList()); } @@ -83,4 +86,9 @@ public EduContentResponse updateEduContent(Long id, EduContentRequest request) { .content(updatedContent.getContent()) .build(); } + + + private boolean checkBookmarked(Long userId, Long eduContentId) { + return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, eduContentId); + } } diff --git a/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java b/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java index a2231c6..d8fbe32 100644 --- a/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java +++ b/src/main/java/com/finfellows/domain/educontent/dto/response/EduContentResponse.java @@ -16,4 +16,5 @@ public class EduContentResponse { private LocalDateTime created_at; private String title; private String content; + private boolean bookmarked; } 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 c9fa017..2ba981b 100644 --- a/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java +++ b/src/main/java/com/finfellows/domain/educontent/presentation/EduContentController.java @@ -4,6 +4,8 @@ import com.finfellows.domain.educontent.domain.EduContent; import com.finfellows.domain.educontent.dto.request.EduContentRequest; import com.finfellows.domain.educontent.dto.response.EduContentResponse; +import com.finfellows.global.config.security.token.CurrentUser; +import com.finfellows.global.config.security.token.UserPrincipal; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -39,8 +41,8 @@ public ResponseEntity saveEduContent(@RequestBody EduContentResponse @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = EduContentResponse.class))) }) @GetMapping - public ResponseEntity> getAllEduContents() { - List responseList = eduContentService.getAllEduContents(); + public ResponseEntity> getAllEduContents(@CurrentUser UserPrincipal userPrincipal) { + List responseList = eduContentService.getAllEduContents(userPrincipal.getId()); return new ResponseEntity<>(responseList, HttpStatus.OK); } diff --git a/src/main/java/com/finfellows/domain/newscontent/application/NewsContentService.java b/src/main/java/com/finfellows/domain/newscontent/application/NewsContentService.java index c6e0891..182861b 100644 --- a/src/main/java/com/finfellows/domain/newscontent/application/NewsContentService.java +++ b/src/main/java/com/finfellows/domain/newscontent/application/NewsContentService.java @@ -1,11 +1,14 @@ package com.finfellows.domain.newscontent.application; +import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; +import com.finfellows.domain.educontent.domain.EduContent; import com.finfellows.domain.newscontent.domain.NewsContent; import com.finfellows.domain.newscontent.domain.repository.NewsContentRepository; import com.finfellows.domain.newscontent.dto.request.NewsContentRequest; import com.finfellows.domain.newscontent.dto.response.NewsContentResponse; import com.finfellows.domain.post.domain.Post; import com.finfellows.domain.post.domain.repository.PostRepository; +import com.finfellows.domain.user.domain.repository.UserRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,6 +23,7 @@ public class NewsContentService { private final NewsContentRepository newsContentRepository; private final PostRepository postRepository; + private final EduContentBookmarkRepository eduContentBookmarkRepository; @Transactional public NewsContent createNewsContent(NewsContentResponse request) { @@ -38,13 +42,14 @@ public NewsContent createNewsContent(NewsContentResponse request) { return savedContent; } - public List getAllNewsContents() { + public List getAllNewsContents(Long userId) { List newsContents = newsContentRepository.findAll(); return newsContents.stream() .map(newsContent -> NewsContentResponse.builder() .id(newsContent.getId()) .title(newsContent.getTitle()) .content(newsContent.getContent()) + .bookmarked(checkBookmarked(userId, newsContent.getId())) // 북마크 여부 확인 .build()) .collect(Collectors.toList()); } @@ -83,4 +88,9 @@ public NewsContentResponse updateNewsContent(Long id, NewsContentRequest request .content(updatedContent.getContent()) .build(); } + + // 특정 뉴스 콘텐츠에 대한 북마크 여부 확인 + private boolean checkBookmarked(Long userId, Long newsContentId) { + return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, newsContentId); + } } diff --git a/src/main/java/com/finfellows/domain/newscontent/dto/response/NewsContentResponse.java b/src/main/java/com/finfellows/domain/newscontent/dto/response/NewsContentResponse.java index 584e34c..aa3b6e7 100644 --- a/src/main/java/com/finfellows/domain/newscontent/dto/response/NewsContentResponse.java +++ b/src/main/java/com/finfellows/domain/newscontent/dto/response/NewsContentResponse.java @@ -13,4 +13,5 @@ public class NewsContentResponse { private Long id; private String title; private String content; + private boolean bookmarked; } diff --git a/src/main/java/com/finfellows/domain/newscontent/presentation/NewsContentController.java b/src/main/java/com/finfellows/domain/newscontent/presentation/NewsContentController.java index db28bc3..16903a5 100644 --- a/src/main/java/com/finfellows/domain/newscontent/presentation/NewsContentController.java +++ b/src/main/java/com/finfellows/domain/newscontent/presentation/NewsContentController.java @@ -4,6 +4,8 @@ import com.finfellows.domain.newscontent.domain.NewsContent; import com.finfellows.domain.newscontent.dto.request.NewsContentRequest; import com.finfellows.domain.newscontent.dto.response.NewsContentResponse; +import com.finfellows.global.config.security.token.CurrentUser; +import com.finfellows.global.config.security.token.UserPrincipal; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -39,8 +41,8 @@ public ResponseEntity saveNewsContent(@RequestBody NewsContentRespo @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = NewsContentResponse.class))) }) @GetMapping - public ResponseEntity> getAllNewsContents() { - List responseList = newsContentService.getAllNewsContents(); + public ResponseEntity> getAllNewsContents(@CurrentUser UserPrincipal userPrincipal) { + List responseList = newsContentService.getAllNewsContents(userPrincipal.getId()); return new ResponseEntity<>(responseList, HttpStatus.OK); }