diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java index 73697ab..4034a1d 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java @@ -101,13 +101,14 @@ public BaseResponse deletePostController(@PathVariable(value = "postId", } @Operation(summary = "저장한 검색어 불러오기", description = "저장한 검색어 불러오기") @GetMapping("/searchHist") - public BaseResponse> getSearchHistController(){ + public BaseResponse getSearchHistController(){ String userId = ""; if(MDC.get(JWTUtil.MDC_USER_ID) != null) { userId= MDC.get(JWTUtil.MDC_USER_ID).toString(); } return new BaseResponse<>(postsService.findSearchService(userId)); } + @Operation(summary = "추천 검색어 불러오기", description = "추천 검색어 주기") @GetMapping("/recommend") public BaseResponse> getRecommendController(){ diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java index 99d42d2..9697a2f 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java @@ -99,8 +99,12 @@ public static SearchKeywordStatsJpaEntity toSearchKeywordStats(String keyword){ .keyword(keyword) .searchCount(1).build(); } - public static String toUserSearchHist(UserSearchHistJpaEntity userSearchHist){ - return userSearchHist.getKeyword(); + public static PostsResponse.saveSearch toUserSearchHist(UserSearchHistJpaEntity userSeachHistory){ + return PostsResponse.saveSearch.builder().id(userSeachHistory.getSearchId()) + .keyword(userSeachHistory.getKeyword()).build(); + } + public static PostsResponse.saveSearchListResponse toUserSearhList(List savedSearches){ + return PostsResponse.saveSearchListResponse.builder().results(savedSearches).build(); } public static String toRecommandSearch(SearchKeywordStatsJpaEntity searchKeywordStats){ return searchKeywordStats.getKeyword(); diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java index 4a75906..455c196 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java @@ -52,6 +52,20 @@ public static class ViewPostResponse{ private String userName; } + @Getter + @Setter + @Builder + public static class saveSearchListResponse{ + private List results; + } + @Getter + @Setter + @Builder + public static class saveSearch{ + private Long id; + private String keyword; + } + @Getter @Setter @Builder diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java index c372700..e3e15f9 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java @@ -19,7 +19,7 @@ public interface PostsService { PostsResponse.ViewAllResultResponse ViewSearchPostService(String userId,String category, int page, Sort.Direction direction, String orderType,String keyword,boolean state); - List findSearchService(String userId); + PostsResponse.saveSearchListResponse findSearchService(String userId); List findRecommandService(); diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java index 266b2c4..d57e8e7 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java @@ -181,11 +181,11 @@ public PostsResponse.ViewAllResultResponse ViewSearchPostService(String userId, return PostsConverter.toViewAllList(items); } - public List findSearchService(String userId){ + public PostsResponse.saveSearchListResponse findSearchService(String userId){ UserJpaEntity user = userRepository.findById(userId).orElse(null); List searchHists=userSearchHistRepository.findByUserAndDelYnOrderByCreatedAtDesc(user,false); - List result= searchHists.stream().map(searchHist-> PostsConverter.toUserSearchHist(searchHist)).toList(); - return result; + List result= searchHists.stream().map(searchHist-> PostsConverter.toUserSearchHist(searchHist)).toList(); + return PostsConverter.toUserSearhList(result); } diff --git a/src/main/java/site/billbill/apiserver/model/user/UserSearchHistJpaEntity.java b/src/main/java/site/billbill/apiserver/model/user/UserSearchHistJpaEntity.java index 87804b1..b28847d 100644 --- a/src/main/java/site/billbill/apiserver/model/user/UserSearchHistJpaEntity.java +++ b/src/main/java/site/billbill/apiserver/model/user/UserSearchHistJpaEntity.java @@ -17,7 +17,7 @@ public class UserSearchHistJpaEntity extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "search_seq", nullable = false) - private String searchId; + private Long searchId; @Column(name = "keyword", nullable = true) private String keyword; @Column(name = "del_yn", nullable = false)