Skip to content

Commit

Permalink
fix 문제 추천 및 문제 검색 숫자 integer 넘어가는 값 예외처리 및 integer에서 long으로 필드값 변경
Browse files Browse the repository at this point in the history
fix: 숫자 기반 추천 숫자 검증 로직 추가 (#70)
  • Loading branch information
toychip authored Jan 26, 2024
1 parent 2a5f692 commit 7bfee7e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public SuccessResponse<RecResponseDto> getUserBasedProList() throws IOException
@ApiResponse(responseCode = "200", description = "추천 성공")
})
@GetMapping("/problem")
public SuccessResponse<RecResponseDto> getSolvedProList(@RequestParam(value = "solvedRecentId") Long solvedNumber)

public SuccessResponse<RecResponseDto> getSolvedProList(@RequestParam(value = "solvedRecentId") String solvedNumber)
throws IOException {
RecResponseDto responseDto = recommendService.getListByProblem(solvedNumber);
return new SuccessResponse<>(responseDto);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/api/TaveShot/global/util/NumberValidator.java
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);
}
}
}

0 comments on commit 7bfee7e

Please sign in to comment.