-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from minseok1015/dev
Keyword 검색 api 완료(뱃지도 같이 response)
- Loading branch information
Showing
9 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/store/itpick/backend/common/exception/KeywordException.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 store.itpick.backend.common.exception; | ||
|
||
|
||
import lombok.Getter; | ||
import store.itpick.backend.common.response.status.ResponseStatus; | ||
|
||
@Getter | ||
public class KeywordException extends RuntimeException{ | ||
private final ResponseStatus exceptionStatus; | ||
|
||
public KeywordException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../java/store/itpick/backend/common/exception_handler/KeywordExceptionControllerAdvice.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,24 @@ | ||
package store.itpick.backend.common.exception_handler; | ||
|
||
|
||
import jakarta.annotation.Priority; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import store.itpick.backend.common.exception.KeywordException; | ||
import store.itpick.backend.common.exception.ReferenceException; | ||
import store.itpick.backend.common.response.BaseErrorResponse; | ||
|
||
@Slf4j | ||
@Priority(0) | ||
@RestControllerAdvice | ||
public class KeywordExceptionControllerAdvice { | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(KeywordException.class) | ||
public BaseErrorResponse handle_UserException(KeywordException e) { | ||
log.error("[handle_KeywordException]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/store/itpick/backend/controller/KeywordController.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,43 @@ | ||
package store.itpick.backend.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import store.itpick.backend.common.exception.KeywordException; | ||
import store.itpick.backend.common.response.BaseResponse; | ||
import store.itpick.backend.dto.keyword.SearchDTO; | ||
import store.itpick.backend.model.Keyword; | ||
import store.itpick.backend.service.KeywordService; | ||
|
||
import java.util.List; | ||
|
||
import static store.itpick.backend.common.response.status.BaseExceptionResponseStatus.EMPTY_REFERENCE; | ||
import static store.itpick.backend.common.response.status.BaseExceptionResponseStatus.NO_SEARCH_KEYWORD; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/keyword") | ||
public class KeywordController { | ||
|
||
private final KeywordService keywordService; | ||
|
||
@GetMapping("/search/nobadge") | ||
public BaseResponse<List<String>> searchKeywords(@RequestParam String query) { | ||
List<String> keywords = keywordService.searchKeywords(query); | ||
if(keywords.isEmpty()){ | ||
throw new KeywordException(NO_SEARCH_KEYWORD); | ||
} | ||
return new BaseResponse<>(keywords); | ||
} | ||
@GetMapping("/search") | ||
public BaseResponse<List<SearchDTO>> searchKeywordsWithBadge(@RequestParam String query) { | ||
List<SearchDTO> keywords = keywordService.searchKeywordsWithBadge(query); | ||
if(keywords.isEmpty()){ | ||
throw new KeywordException(NO_SEARCH_KEYWORD); | ||
} | ||
return new BaseResponse<>(keywords); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/store/itpick/backend/dto/keyword/SearchDTO.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 store.itpick.backend.dto.keyword; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class SearchDTO { | ||
private String keyword; | ||
private long nateRank; | ||
private long naverRank; | ||
private long zumRank; | ||
} | ||
|
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