From d3fa6fa0cda8ca41e10865a7a009bacdc93326ae Mon Sep 17 00:00:00 2001 From: soljjang777 Date: Mon, 2 Dec 2024 16:48:13 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#143=20-=20=EB=A9=94=EC=9D=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94=20=EC=A7=80?= =?UTF-8?q?=ED=98=9C=20=EB=82=98=EB=88=94=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WbUserKnowhowController.java | 7 +++++++ .../api/individual/facade/WBUserKnowhowFacade.java | 5 +++++ .../domain/knowhow/KnowhowRepository.java | 4 ++++ .../knowhow/service/WbUserKnowhowService.java | 2 ++ .../knowhow/service/WbUserKnowhowServiceImpl.java | 13 +++++++++++++ 5 files changed, 31 insertions(+) diff --git a/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java b/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java index 4e7bd87..da06e13 100644 --- a/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java +++ b/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java @@ -19,6 +19,13 @@ public class WbUserKnowhowController { private final WBUserKnowhowFacade wbUserKnowhowFacade; + @Operation(summary = "지혜 나눔 전체 목록 조회(메인)", description = "지혜 나눔 전체 목록 조회(메인)") + @GetMapping("/main/share") + public ResponseEntity getFirst5ShareKnowhows() + { + return ResponseEntity.ok().body(wbUserKnowhowFacade.getLatest4ShareKnowhows()); + } + @Operation(summary = "지혜 나눔 전체 목록 조회", description = "지혜 나눔 전체 목록 조회") @GetMapping("/share") public ResponseEntity getAllShareKnowhows(Authentication authentication, diff --git a/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java b/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java index f26d2e1..1b00e81 100644 --- a/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java +++ b/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java @@ -19,6 +19,11 @@ public class WBUserKnowhowFacade { private final WbUserKnowhowService wbUserKnowhowService; private final KnowhowReportedService knowhowReportedService; + @Transactional(readOnly = true) + public List getLatest4ShareKnowhows() { + return wbUserKnowhowService.getLatest4ShareKnowhows(); + } + @Transactional(readOnly = true) public List getAllShareKnowhows(Authentication authentication, String knowhowTitle, String knowhowJob) { String userId = authenticateUtil.CheckWbUserAuthAndGetUserId(authentication); diff --git a/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java b/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java index 4acdb60..f1bc034 100644 --- a/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java +++ b/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java @@ -2,6 +2,7 @@ import com.wooribound.domain.knowhow.dto.AdminKnowhowDetailProjection; import com.wooribound.domain.knowhow.dto.AdminKnowhowProjection; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -77,4 +78,7 @@ List findByUserIdAndTermAndFilter(@Param("userId") String userId, @Query("SELECT MAX(k.knowhowId) FROM Knowhow k") Optional getMaxKnowhowId(); + + + List findAllByOrderByUploadDateDesc(Pageable pageable); } diff --git a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java index a06c207..1c9b92b 100644 --- a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java +++ b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java @@ -6,6 +6,8 @@ public interface WbUserKnowhowService { + List getLatest4ShareKnowhows(); + List getAllShareKnowhows(String userId, String knowhowTitle, String knowhowJob); String deleteShareKnowhow (String userId, Long knowhowId); diff --git a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java index 1e77641..1b0eb4b 100644 --- a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java +++ b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java @@ -10,6 +10,9 @@ import com.wooribound.global.exception.NotEntityException; import com.wooribound.global.exception.UnauthorizedAccessException; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.util.Date; @@ -24,6 +27,16 @@ public class WbUserKnowhowServiceImpl implements WbUserKnowhowService{ private final KnowhowRepository knowhowRepository; private final WbUserRepository wbUserRepository; + @Override + public List getLatest4ShareKnowhows() { + Pageable pageable = PageRequest.of(0, 4); + List knowhows = knowhowRepository.findAllByOrderByUploadDateDesc(pageable); + + return knowhows.stream() + .map(this::convertToDTO) + .collect(Collectors.toList()); + } + @Override public List getAllShareKnowhows(String userId, String knowhowTitle, String knowhowJob) { List knowhows = knowhowRepository.findByUserIdAndTermAndFilter(userId, knowhowTitle, knowhowJob);