From 7bfee7e3d8a7236203a17b6d5202232a7c575578 Mon Sep 17 00:00:00 2001 From: toychip <109949924+toychip@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:58:30 +0900 Subject: [PATCH] =?UTF-8?q?fix=20=EB=AC=B8=EC=A0=9C=20=EC=B6=94=EC=B2=9C?= =?UTF-8?q?=20=EB=B0=8F=20=EB=AC=B8=EC=A0=9C=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90=20integer=20=EB=84=98=EC=96=B4=EA=B0=80?= =?UTF-8?q?=EB=8A=94=20=EA=B0=92=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=8F=20integer=EC=97=90=EC=84=9C=20long=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 숫자 기반 추천 숫자 검증 로직 추가 (#70) --- .../controller/RecommendController.java | 3 ++- .../recommend/service/RecommendService.java | 6 ++++- .../domain/search/service/SearchService.java | 10 ++------ .../TaveShot/global/util/NumberValidator.java | 25 +++++++++++++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/api/TaveShot/global/util/NumberValidator.java diff --git a/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java b/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java index 2bbada5..c872f95 100644 --- a/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java +++ b/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java @@ -38,7 +38,8 @@ public SuccessResponse getUserBasedProList() throws IOException @ApiResponse(responseCode = "200", description = "추천 성공") }) @GetMapping("/problem") - public SuccessResponse getSolvedProList(@RequestParam(value = "solvedRecentId") Long solvedNumber) + + public SuccessResponse getSolvedProList(@RequestParam(value = "solvedRecentId") String solvedNumber) throws IOException { RecResponseDto responseDto = recommendService.getListByProblem(solvedNumber); return new SuccessResponse<>(responseDto); diff --git a/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java b/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java index acafba7..d747194 100644 --- a/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java +++ b/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java @@ -1,5 +1,7 @@ package com.api.TaveShot.domain.recommend.service; +import static com.api.TaveShot.global.util.NumberValidator.extractNumberFromRecommendString; + import com.api.TaveShot.domain.Member.domain.Member; import com.api.TaveShot.domain.Member.repository.MemberRepository; import com.api.TaveShot.domain.recommend.domain.ProblemElement; @@ -76,7 +78,9 @@ public RecResponseDto getListByUser() throws IOException { } // 문제 기반 추천 서비스 - public RecResponseDto getListByProblem(Long solvedRecentId) throws IOException { + public RecResponseDto getListByProblem(String solvedRecentIdStr) throws IOException { + + Long solvedRecentId = extractNumberFromRecommendString(solvedRecentIdStr); UserCrawlingDto dto = getUserInfo(); diff --git a/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java b/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java index e1dd7ac..89a0c2e 100644 --- a/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java +++ b/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java @@ -1,5 +1,7 @@ package com.api.TaveShot.domain.search.service; +import static com.api.TaveShot.global.util.NumberValidator.extractNumberFromBojString; + import com.api.TaveShot.domain.recommend.repository.ProblemElementRepository; import com.api.TaveShot.domain.search.dto.GoogleItemDto; import com.api.TaveShot.domain.search.dto.GoogleListResponseDto; @@ -68,12 +70,4 @@ public GoogleListResponseDto findBlog(String query, int index) { } - public Long extractNumberFromBojString(String input) { - Pattern pattern = Pattern.compile("백준 (\\d+)번"); - Matcher matcher = pattern.matcher(input); - if (matcher.find()) { - return Long.parseLong(matcher.group(1)); - } - throw new ApiException(ErrorType._PROBLEM_NOT_FOUND); - } } diff --git a/src/main/java/com/api/TaveShot/global/util/NumberValidator.java b/src/main/java/com/api/TaveShot/global/util/NumberValidator.java new file mode 100644 index 0000000..8847309 --- /dev/null +++ b/src/main/java/com/api/TaveShot/global/util/NumberValidator.java @@ -0,0 +1,25 @@ +package com.api.TaveShot.global.util; + +import com.api.TaveShot.global.exception.ApiException; +import com.api.TaveShot.global.exception.ErrorType; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class NumberValidator { + public static Long extractNumberFromBojString(String input) { + Pattern pattern = Pattern.compile("백준 (\\d+)번"); + Matcher matcher = pattern.matcher(input); + if (matcher.find()) { + return Long.parseLong(matcher.group(1)); + } + throw new ApiException(ErrorType._PROBLEM_NOT_FOUND); + } + + public static Long extractNumberFromRecommendString(String input) { + try { + return Long.parseLong(input); + } catch (Exception e) { + throw new ApiException(ErrorType._PROBLEM_NOT_FOUND); + } + } +}