-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 최근검색어 조회/삭제 api 구현 #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3c9333e
c8fad59
7de9e15
b9cface
4d5103c
4729258
bb005ff
f1c5a76
492657e
7b452f3
083e8ad
f361b61
752f1c3
8638179
8e4a2e5
379df8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,33 @@ | ||
| package konkuk.thip.recentSearch.adapter.in.web; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import konkuk.thip.common.dto.BaseResponse; | ||
| import konkuk.thip.common.security.annotation.UserId; | ||
| import konkuk.thip.common.swagger.annotation.ExceptionDescription; | ||
| import konkuk.thip.recentSearch.application.port.in.RecentSearchDeleteUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import static konkuk.thip.common.swagger.SwaggerResponseDescription.RECENT_SEARCH_DELETE; | ||
|
|
||
| @Tag(name = "Recent Search Command API", description = "최근 검색어 상태 변경 관련 API") | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class RecentSearchCommandController { | ||
|
|
||
| private final RecentSearchDeleteUseCase recentSearchDeleteUseCase; | ||
|
|
||
| @Operation(summary = "최근 검색어 삭제", description = "최근 검색어를 삭제합니다.") | ||
| @ExceptionDescription(RECENT_SEARCH_DELETE) | ||
| @DeleteMapping("/recent-searches/{recentSearchId}") | ||
| public BaseResponse<Void> deleteRecentSearch( | ||
| @PathVariable(value = "recentSearchId") final Long recentSearchId, | ||
| @UserId final Long userId | ||
| ) { | ||
| return BaseResponse.ok(recentSearchDeleteUseCase.deleteRecentSearch(recentSearchId, userId)); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,32 @@ | ||||||||||||||||||||||||||||||||||||
| package konkuk.thip.recentSearch.adapter.in.web; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.Operation; | ||||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.Parameter; | ||||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||||||||||||||||||||||||||||||||||
| import konkuk.thip.common.dto.BaseResponse; | ||||||||||||||||||||||||||||||||||||
| import konkuk.thip.common.security.annotation.UserId; | ||||||||||||||||||||||||||||||||||||
| import konkuk.thip.recentSearch.adapter.in.web.response.RecentSearchGetResponse; | ||||||||||||||||||||||||||||||||||||
| import konkuk.thip.recentSearch.application.port.in.RecentSearchGetUseCase; | ||||||||||||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RequestParam; | ||||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RestController; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Tag(name = "Recent Search Query API", description = "최근 검색어 조회 관련 API") | ||||||||||||||||||||||||||||||||||||
| @RestController | ||||||||||||||||||||||||||||||||||||
| @RequiredArgsConstructor | ||||||||||||||||||||||||||||||||||||
| public class RecentSearchQueryController { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private final RecentSearchGetUseCase recentSearchGetUseCase; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Operation(summary = "최근 검색어 조회", description = "사용자의 최근 검색어를 조회합니다. 최신순으로 최대 5개까지 조회됩니다.") | ||||||||||||||||||||||||||||||||||||
| @GetMapping("/recent-searches") | ||||||||||||||||||||||||||||||||||||
| public BaseResponse<RecentSearchGetResponse> showRecentSearches( | ||||||||||||||||||||||||||||||||||||
| @Parameter(description = "최근 검색어 유형 (사용자 검색 : USER / 방 검색 : ROOM / 책 검색 : BOOK)", example = "USER") | ||||||||||||||||||||||||||||||||||||
| @RequestParam(value = "type") String type, | ||||||||||||||||||||||||||||||||||||
| @Parameter(hidden = true) @UserId final Long userId | ||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||
| return BaseResponse.ok(recentSearchGetUseCase.getRecentSearches(type, userId)); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 타입 파라미터에 대한 검증이 필요합니다.
다음과 같이 검증을 추가하는 것을 제안합니다: @GetMapping("/recent-searches")
public BaseResponse<RecentSearchGetResponse> showRecentSearches(
@Parameter(description = "최근 검색어 유형 (사용자 검색 : USER / 방 검색 : ROOM / 책 검색 : BOOK)", example = "USER")
- @RequestParam(value = "type") String type,
+ @RequestParam(value = "type") @Pattern(regexp = "^(USER|ROOM|BOOK)$", message = "유효하지 않은 검색 타입입니다") String type,
@Parameter(hidden = true) @UserId final Long userId
) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package konkuk.thip.recentSearch.adapter.in.web.response; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record RecentSearchGetResponse( | ||
| List<RecentSearchDto> recentSearchList | ||
| ) { | ||
|
|
||
| public record RecentSearchDto( | ||
| Long recentSearchId, | ||
| String searchTerm | ||
| ) { | ||
| } | ||
| public static RecentSearchGetResponse of(List<RecentSearchDto> recentSearchList) { | ||
| return new RecentSearchGetResponse(recentSearchList); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| import jakarta.persistence.*; | ||||||||||||||||||
| import konkuk.thip.common.entity.BaseJpaEntity; | ||||||||||||||||||
| import konkuk.thip.recentSearch.domain.RecentSearch; | ||||||||||||||||||
| import konkuk.thip.user.adapter.out.jpa.UserJpaEntity; | ||||||||||||||||||
| import lombok.*; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -25,15 +24,9 @@ public class RecentSearchJpaEntity extends BaseJpaEntity { | |||||||||||||||||
|
|
||||||||||||||||||
| @Enumerated(EnumType.STRING) | ||||||||||||||||||
| @Column(nullable = false) | ||||||||||||||||||
| private SearchType type; | ||||||||||||||||||
| private RecentSearchType type; | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RecentSearchType 임포트 누락으로 컴파일 에러 발생.
다음 임포트를 추가해 주세요: package konkuk.thip.recentSearch.adapter.out.jpa;
import jakarta.persistence.*;
import konkuk.thip.common.entity.BaseJpaEntity;
+import konkuk.thip.recentSearch.domain.RecentSearchType;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import lombok.*;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| @ManyToOne(fetch = FetchType.LAZY) | ||||||||||||||||||
| @JoinColumn(name = "user_id") | ||||||||||||||||||
| private UserJpaEntity userJpaEntity; | ||||||||||||||||||
|
|
||||||||||||||||||
| public void updateFrom(RecentSearch recentSearch) { | ||||||||||||||||||
| this.searchTerm = recentSearch.getSearchTerm(); | ||||||||||||||||||
| this.type = SearchType.from(recentSearch.getType()); | ||||||||||||||||||
| this.setCreatedAt(recentSearch.getCreatedAt()); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package konkuk.thip.recentSearch.adapter.out.jpa; | ||
|
|
||
|
|
||
| import konkuk.thip.common.exception.InvalidStateException; | ||
| import lombok.Getter; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.INVALID_SEARCH_TYPE; | ||
|
|
||
| @Getter | ||
| public enum RecentSearchType { | ||
|
|
||
| USER_SEARCH("USER"), | ||
| BOOK_SEARCH("BOOK"), | ||
| ROOM_SEARCH("ROOM"), | ||
| ; | ||
|
|
||
| private final String searchType; | ||
|
|
||
| RecentSearchType(String searchType) { | ||
| this.searchType = searchType; | ||
| } | ||
|
|
||
| public static RecentSearchType from(String searchType) { | ||
| for (RecentSearchType type : RecentSearchType.values()) { | ||
| if (type.getSearchType().equals(searchType)) { | ||
| return type; | ||
| } | ||
| } | ||
| throw new InvalidStateException(INVALID_SEARCH_TYPE); | ||
| } | ||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM