-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refac] 검색 리팩토링 및 최근 검색어 삭제 기능 추가 (#62)
* [feat] 최근 검색어 삭제 기능 추가 #59 * [refac] 최근 검색어 불러오기 response 변경 #59 * [chore] spotless 적용 #61 * [refac] 검색어 검색 http method 변경 #61 * [feat] 강제 데이터 주입 기능 추가 #61 * [refac] 연관 검색어 기능 로직 수정 및 코드 정리 #61 * [refac] 연관 검색어 range 수정 #61 * [refac] 점색어 자동완성 get 으로 변환 #61
- Loading branch information
Showing
16 changed files
with
205 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Api/src/main/java/allchive/server/api/search/model/dto/response/SearchVoListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package allchive.server.api.search.model.dto.response; | ||
|
||
|
||
import allchive.server.api.search.model.vo.LatestSearchVo; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SearchVoListResponse { | ||
private List<LatestSearchVo> keywords; | ||
|
||
@Builder | ||
private SearchVoListResponse(List<LatestSearchVo> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
public static SearchVoListResponse from(List<LatestSearchVo> keywords) { | ||
return SearchVoListResponse.builder().keywords(keywords).build(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Api/src/main/java/allchive/server/api/search/model/vo/LatestSearchVo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package allchive.server.api.search.model.vo; | ||
|
||
|
||
import allchive.server.domain.domains.search.domain.LatestSearch; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class LatestSearchVo { | ||
@Schema(description = "최근 검색 내용") | ||
private String word; | ||
|
||
@Schema(description = "최근 검색 내용 고유번호") | ||
private Long latestSearchId; | ||
|
||
@Builder | ||
private LatestSearchVo(String word, Long latestSearchId) { | ||
this.word = word; | ||
this.latestSearchId = latestSearchId; | ||
} | ||
|
||
public static LatestSearchVo from(LatestSearch latestSearch) { | ||
return LatestSearchVo.builder() | ||
.word(latestSearch.getKeyword()) | ||
.latestSearchId(latestSearch.getId()) | ||
.build(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Api/src/main/java/allchive/server/api/search/service/DeleteLatestSearchUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package allchive.server.api.search.service; | ||
|
||
|
||
import allchive.server.api.config.security.SecurityUtil; | ||
import allchive.server.core.annotation.UseCase; | ||
import allchive.server.domain.domains.search.adaptor.LatestSearchAdaptor; | ||
import allchive.server.domain.domains.search.validator.LatestSearchValidator; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class DeleteLatestSearchUseCase { | ||
private final LatestSearchValidator latestSearchValidator; | ||
private final LatestSearchAdaptor latestSearchAdaptor; | ||
|
||
@Transactional | ||
public void execute(Long latestSearchId) { | ||
Long userId = SecurityUtil.getCurrentUserId(); | ||
validateExecution(latestSearchId, userId); | ||
latestSearchAdaptor.deleteByIdAndUserId(latestSearchId, userId); | ||
} | ||
|
||
private void validateExecution(Long latestSearchId, Long userId) { | ||
latestSearchValidator.validateExistByIdAndUserId(latestSearchId, userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Domain/src/main/java/allchive/server/domain/domains/search/exception/SearchErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package allchive.server.domain.domains.search.exception; | ||
|
||
import static allchive.server.core.consts.AllchiveConst.*; | ||
|
||
import allchive.server.core.dto.ErrorReason; | ||
import allchive.server.core.error.BaseErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SearchErrorCode implements BaseErrorCode { | ||
LATEST_SEARCH_NOT_FOUND(NOT_FOUND, "LATESTSEARCH_404_1", "최근 검색어를 찾을 수 없습니다."); | ||
private int status; | ||
private String code; | ||
private String reason; | ||
|
||
@Override | ||
public ErrorReason getErrorReason() { | ||
return ErrorReason.of(status, code, reason); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...hive/server/domain/domains/search/exception/exceptions/LatestSearchNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package allchive.server.domain.domains.search.exception.exceptions; | ||
|
||
|
||
import allchive.server.core.error.BaseErrorException; | ||
import allchive.server.domain.domains.search.exception.SearchErrorCode; | ||
|
||
public class LatestSearchNotFoundException extends BaseErrorException { | ||
|
||
public static final BaseErrorException EXCEPTION = new LatestSearchNotFoundException(); | ||
|
||
private LatestSearchNotFoundException() { | ||
super(SearchErrorCode.LATEST_SEARCH_NOT_FOUND); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../src/main/java/allchive/server/domain/domains/search/validator/LatestSearchValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package allchive.server.domain.domains.search.validator; | ||
|
||
|
||
import allchive.server.core.annotation.Validator; | ||
import allchive.server.domain.domains.search.adaptor.LatestSearchAdaptor; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Validator | ||
@RequiredArgsConstructor | ||
public class LatestSearchValidator { | ||
private final LatestSearchAdaptor latestSearchAdaptor; | ||
|
||
public void validateExistByIdAndUserId(Long latestSearchId, Long userId) { | ||
latestSearchAdaptor.findByIdAndUserId(latestSearchId, userId); | ||
} | ||
} |