diff --git a/be/src/main/java/com/secondhand/category/CategoryController.java b/be/src/main/java/com/secondhand/category/CategoryController.java index 0480e355a..252a7bc13 100644 --- a/be/src/main/java/com/secondhand/category/CategoryController.java +++ b/be/src/main/java/com/secondhand/category/CategoryController.java @@ -3,7 +3,6 @@ import com.secondhand.category.dto.CategoriesDto; import com.secondhand.category.dto.CategoryInterestsDto; import com.secondhand.category.dto.PostTitleDto; -import com.secondhand.category.dto.RecommendedCategoriesDto; import com.secondhand.post.repository.InterestRepository; import com.secondhand.util.CustomResponse; import lombok.RequiredArgsConstructor; @@ -46,9 +45,7 @@ public ResponseEntity> getInterestCategoryL } @GetMapping("/recommend") - public ResponseEntity> findRecommendedCategories(@RequestBody PostTitleDto postTitleDto) { - - + public ResponseEntity> findRecommendedCategories(@RequestBody PostTitleDto postTitleDto) { return ResponseEntity .ok() @@ -56,7 +53,7 @@ public ResponseEntity> findRecommendedC "success", 200, "관심 카테고리 목록 조회 성공", - null) - ); + categoryService.getRecommendedCategories(postTitleDto.getTitle()) + )); } } diff --git a/be/src/main/java/com/secondhand/category/CategoryService.java b/be/src/main/java/com/secondhand/category/CategoryService.java index cf70d40ee..bf5767c5c 100644 --- a/be/src/main/java/com/secondhand/category/CategoryService.java +++ b/be/src/main/java/com/secondhand/category/CategoryService.java @@ -19,7 +19,7 @@ public CategoriesDto getCategoryList() { return categoryRepository.findAllCategories(); } - public CategoriesDto getRecommendedCategories() { + public CategoriesDto getRecommendedCategories(String postTitle) { return recommendCategories(categoryRepository.findAllCategories().getCategories()); } diff --git a/be/src/main/java/com/secondhand/category/dto/RecommendedCategoriesDto.java b/be/src/main/java/com/secondhand/category/dto/RecommendedCategoriesDto.java index 1202b6e6e..eecc51980 100644 --- a/be/src/main/java/com/secondhand/category/dto/RecommendedCategoriesDto.java +++ b/be/src/main/java/com/secondhand/category/dto/RecommendedCategoriesDto.java @@ -2,14 +2,10 @@ import lombok.Getter; +import java.util.List; + @Getter public class RecommendedCategoriesDto { - private int id; - private String name; - - public RecommendedCategoriesDto(int id, String name) { - this.id = id; - this.name = name; - } + private List categories; } diff --git a/be/src/main/java/com/secondhand/category/dto/RecommendedCategoryDto.java b/be/src/main/java/com/secondhand/category/dto/RecommendedCategoryDto.java new file mode 100644 index 000000000..838255611 --- /dev/null +++ b/be/src/main/java/com/secondhand/category/dto/RecommendedCategoryDto.java @@ -0,0 +1,15 @@ +package com.secondhand.category.dto; + +import com.querydsl.core.annotations.QueryProjection; + +public class RecommendedCategoryDto { + + private int id; + private String name; + + @QueryProjection + public RecommendedCategoryDto(CategoryDto categoryDto) { + this.id = categoryDto.getId(); + this.name = categoryDto.getName(); + } +} diff --git a/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryCustom.java b/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryCustom.java index c45d5b438..23d636122 100644 --- a/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryCustom.java +++ b/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryCustom.java @@ -5,4 +5,5 @@ public interface CategoryRepositoryCustom { CategoriesDto findAllCategories(); + } diff --git a/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryImpl.java b/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryImpl.java index 93bd9b833..333687491 100644 --- a/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryImpl.java +++ b/be/src/main/java/com/secondhand/post/repository/CategoryRepositoryImpl.java @@ -3,7 +3,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import com.secondhand.category.dto.CategoriesDto; import com.secondhand.category.dto.QCategoryDto; -import com.secondhand.post.repository.CategoryRepositoryCustom; +import com.secondhand.category.dto.RecommendedCategoriesDto; import javax.persistence.EntityManager; @@ -29,4 +29,5 @@ public CategoriesDto findAllCategories() { .from(category) .fetch()); } + }