Skip to content

Commit

Permalink
[fix] 저장한 검색어
Browse files Browse the repository at this point in the history
  • Loading branch information
jainefer committed Dec 5, 2024
1 parent d3ef463 commit 183dccf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ public BaseResponse<String> deletePostController(@PathVariable(value = "postId",
}
@Operation(summary = "저장한 검색어 불러오기", description = "저장한 검색어 불러오기")
@GetMapping("/searchHist")
public BaseResponse<List<String>> getSearchHistController(){
public BaseResponse<PostsResponse.saveSearchListResponse> 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<List<String>> getRecommendController(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostsResponse.saveSearch> savedSearches){
return PostsResponse.saveSearchListResponse.builder().results(savedSearches).build();
}
public static String toRecommandSearch(SearchKeywordStatsJpaEntity searchKeywordStats){
return searchKeywordStats.getKeyword();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public static class ViewPostResponse{
private String userName;

}
@Getter
@Setter
@Builder
public static class saveSearchListResponse{
private List<saveSearch> results;
}
@Getter
@Setter
@Builder
public static class saveSearch{
private Long id;
private String keyword;
}

@Getter
@Setter
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> findSearchService(String userId);
PostsResponse.saveSearchListResponse findSearchService(String userId);

List<String> findRecommandService();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public PostsResponse.ViewAllResultResponse ViewSearchPostService(String userId,
return PostsConverter.toViewAllList(items);
}

public List<String> findSearchService(String userId){
public PostsResponse.saveSearchListResponse findSearchService(String userId){
UserJpaEntity user = userRepository.findById(userId).orElse(null);
List<UserSearchHistJpaEntity> searchHists=userSearchHistRepository.findByUserAndDelYnOrderByCreatedAtDesc(user,false);
List<String> result= searchHists.stream().map(searchHist-> PostsConverter.toUserSearchHist(searchHist)).toList();
return result;
List<PostsResponse.saveSearch> result= searchHists.stream().map(searchHist-> PostsConverter.toUserSearchHist(searchHist)).toList();
return PostsConverter.toUserSearhList(result);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 183dccf

Please sign in to comment.