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