-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix 문제 추천 및 문제 검색 숫자 integer 넘어가는 값 예외처리 및 integer에서 long으로 필드값 변경
fix: 숫자 기반 추천 숫자 검증 로직 추가 (#70)
- Loading branch information
Showing
4 changed files
with
34 additions
and
10 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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/api/TaveShot/global/util/NumberValidator.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,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); | ||
} | ||
} | ||
} |