Skip to content

Commit

Permalink
Merge pull request #162 from WooRibound/fix/#143-test
Browse files Browse the repository at this point in the history
[feat] #143 - 메인에서 사용하는 지혜 나눔 조회 API 추가
  • Loading branch information
haewoni authored Dec 2, 2024
2 parents a89e2bd + d3fa6fa commit 8f84e7a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class WBUserKnowhowFacade {
private final WbUserKnowhowService wbUserKnowhowService;
private final KnowhowReportedService knowhowReportedService;

@Transactional(readOnly = true)
public List<WbUserKnowhowDTO> getLatest4ShareKnowhows() {
return wbUserKnowhowService.getLatest4ShareKnowhows();
}

@Transactional(readOnly = true)
public List<WbUserKnowhowDTO> getAllShareKnowhows(Authentication authentication, String knowhowTitle, String knowhowJob) {
String userId = authenticateUtil.CheckWbUserAuthAndGetUserId(authentication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,4 +78,7 @@ List<Knowhow> findByUserIdAndTermAndFilter(@Param("userId") String userId,

@Query("SELECT MAX(k.knowhowId) FROM Knowhow k")
Optional<Long> getMaxKnowhowId();


List<Knowhow> findAllByOrderByUploadDateDesc(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public interface WbUserKnowhowService {

List<WbUserKnowhowDTO> getLatest4ShareKnowhows();

List<WbUserKnowhowDTO> getAllShareKnowhows(String userId, String knowhowTitle, String knowhowJob);

String deleteShareKnowhow (String userId, Long knowhowId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +27,16 @@ public class WbUserKnowhowServiceImpl implements WbUserKnowhowService{
private final KnowhowRepository knowhowRepository;
private final WbUserRepository wbUserRepository;

@Override
public List<WbUserKnowhowDTO> getLatest4ShareKnowhows() {
Pageable pageable = PageRequest.of(0, 4);
List<Knowhow> knowhows = knowhowRepository.findAllByOrderByUploadDateDesc(pageable);

return knowhows.stream()
.map(this::convertToDTO)
.collect(Collectors.toList());
}

@Override
public List<WbUserKnowhowDTO> getAllShareKnowhows(String userId, String knowhowTitle, String knowhowJob) {
List<Knowhow> knowhows = knowhowRepository.findByUserIdAndTermAndFilter(userId, knowhowTitle, knowhowJob);
Expand Down

0 comments on commit 8f84e7a

Please sign in to comment.