diff --git a/src/main/java/com/sku/refit/domain/post/controller/PostController.java b/src/main/java/com/sku/refit/domain/post/controller/PostController.java index 179482c..432cae7 100644 --- a/src/main/java/com/sku/refit/domain/post/controller/PostController.java +++ b/src/main/java/com/sku/refit/domain/post/controller/PostController.java @@ -68,9 +68,9 @@ ResponseEntity>> getPostByCate type = "string", allowableValues = {"FREE", "REPAIR", "INFO"}, example = "FREE")) - @RequestParam + @RequestParam(required = false) String category, - @Parameter(description = "마지막으로 조회한 게시글 식별자(첫 조회 시 생략)", example = "3") + @Parameter(description = "마지막으로 조회한 게시글 식별자(첫 조회 시 생략, 최신순이라서 식별자 값 감소)", example = "3") @RequestParam(required = false) Long lastPostId, @Parameter(description = "한 번에 조회할 게시글 개수", example = "3") @RequestParam(defaultValue = "3") diff --git a/src/main/java/com/sku/refit/domain/post/repository/PostRepository.java b/src/main/java/com/sku/refit/domain/post/repository/PostRepository.java index 29de413..d83302e 100644 --- a/src/main/java/com/sku/refit/domain/post/repository/PostRepository.java +++ b/src/main/java/com/sku/refit/domain/post/repository/PostRepository.java @@ -16,10 +16,9 @@ public interface PostRepository extends JpaRepository { Page findByPostCategory(PostCategory category, Pageable pageable); - Page findByPostCategoryContainingAndIdLessThan( - String category, Long lastPostId, Pageable pageable); - Page findAllByUser_Id(Long userId, Pageable pageable); - Page findAllByUser_IdAndIdLessThan(Long userId, Long lastPostId, Pageable pageable); + Page findByIdLessThan(Long id, Pageable pageable); + + Page findByPostCategoryAndIdLessThan(PostCategory category, Long id, Pageable pageable); } diff --git a/src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java b/src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java index 7bf3668..8e28a5e 100644 --- a/src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java +++ b/src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java @@ -155,20 +155,28 @@ public InfiniteResponse getPostsByCategory( Pageable pageable = PageRequest.of(0, size + 1, Sort.by(Sort.Direction.DESC, "id")); List posts; - PostCategory postCategory; - try { - postCategory = PostCategory.valueOf(category); - } catch (IllegalArgumentException e) { - throw new CustomException(PostErrorCode.INVALID_CATEGORY); - } - - if (lastPostId == null) { - posts = postRepository.findByPostCategory(postCategory, pageable).getContent(); + if (category == null || category.isBlank()) { + if (lastPostId == null) { + posts = postRepository.findAll(pageable).getContent(); + } else { + posts = postRepository.findByIdLessThan(lastPostId, pageable).getContent(); + } } else { - posts = - postRepository - .findByPostCategoryContainingAndIdLessThan(category, lastPostId, pageable) - .getContent(); + PostCategory postCategory; + try { + postCategory = PostCategory.valueOf(category); + } catch (IllegalArgumentException e) { + throw new CustomException(PostErrorCode.INVALID_CATEGORY); + } + + if (lastPostId == null) { + posts = postRepository.findByPostCategory(postCategory, pageable).getContent(); + } else { + posts = + postRepository + .findByPostCategoryAndIdLessThan(postCategory, lastPostId, pageable) + .getContent(); + } } boolean hasNext = posts.size() > size; @@ -204,7 +212,7 @@ public InfiniteResponse getPostsByCategory( user)) .toList(); - Long newLastCursor = posts.isEmpty() ? null : posts.getLast().getId(); + Long newLastCursor = posts.isEmpty() ? null : posts.get(posts.size() - 1).getId(); log.info( "[POST CATEGORY LIST] category={}, lastPostId={}, size={}", category, lastPostId, size); diff --git a/src/main/java/com/sku/refit/global/security/OAuth2LoginSuccessHandler.java b/src/main/java/com/sku/refit/global/security/OAuth2LoginSuccessHandler.java index b593fda..62f4f19 100644 --- a/src/main/java/com/sku/refit/global/security/OAuth2LoginSuccessHandler.java +++ b/src/main/java/com/sku/refit/global/security/OAuth2LoginSuccessHandler.java @@ -68,6 +68,6 @@ public void onAuthenticationSuccess( log.info("카카오 로그인 성공: {}", user.getUsername()); response.addHeader("Authorization", "Bearer " + tokenResponse.getAccessToken()); - response.sendRedirect("http://localhost:3000"); + response.sendRedirect("https://refit-lab.vercel.app"); } } diff --git a/src/main/resources b/src/main/resources index e9738e5..b18f530 160000 --- a/src/main/resources +++ b/src/main/resources @@ -1 +1 @@ -Subproject commit e9738e527bba9befe3cf28fad31cbd31949854ab +Subproject commit b18f5301115686c5608bd6285bc6d02f24202840