-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] : '전체 공개이지만, 등록된 수업이 없는 경우' 예외 처리를 추가한다 #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
src/main/java/side/onetime/exception/status/FixedErrorStatus.java
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| import java.util.Set; | ||
| import java.util.TreeMap; | ||
| import java.util.TreeSet; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.jsoup.Jsoup; | ||
|
|
@@ -35,6 +37,10 @@ | |
| @Service | ||
| @RequiredArgsConstructor | ||
| public class FixedScheduleService { | ||
|
|
||
| private static final int EVERYTIME_PRIVATE_STATUS = -2; | ||
| private static final int EVERYTIME_PUBLIC_STATUS = 1; | ||
|
|
||
| private final UserRepository userRepository; | ||
| private final FixedScheduleRepository fixedScheduleRepository; | ||
| private final FixedSelectionRepository fixedSelectionRepository; | ||
|
|
@@ -132,13 +138,42 @@ private String fetchTimetableXml(String identifier) { | |
| } | ||
|
|
||
| if (!xmlResponse.contains("subject")) { | ||
| // 200 OK 응답이 왔지만, 테이블이 비어있는 경우 (공개 범위 설정 오류 등) | ||
| throw new CustomException(FixedErrorStatus._NOT_FOUND_EVERYTIME_TIMETABLE); | ||
| // 200 OK 응답이 왔지만, 테이블이 비어있는 경우 | ||
| int status = extractStatusFromXml(xmlResponse); | ||
| if (EVERYTIME_PRIVATE_STATUS == status) { | ||
| // 1. 공개 범위가 '전체 공개'가 아닌 경우 | ||
| throw new CustomException(FixedErrorStatus._EVERYTIME_TIMETABLE_NOT_PUBLIC); | ||
| } else if (EVERYTIME_PUBLIC_STATUS == status) { | ||
| // 2. '전체 공개'이지만, 등록된 수업이 없는 경우 | ||
| throw new CustomException(FixedErrorStatus._NOT_FOUND_EVERYTIME_TIMETABLE); | ||
| } | ||
| } | ||
|
|
||
| return xmlResponse; | ||
| } | ||
|
|
||
| /** | ||
| * XML 문자열에서 status 속성값을 추출합니다. | ||
| * 예: <table ... status="1" ... /> -> 1 반환 | ||
| */ | ||
| private int extractStatusFromXml(String xml) { | ||
| // status="숫자" 패턴을 찾음 | ||
| Pattern pattern = Pattern.compile("status=\"(-?\\d+)\""); | ||
|
||
| Matcher matcher = pattern.matcher(xml); | ||
|
|
||
| if (matcher.find()) { | ||
| try { | ||
| return Integer.parseInt(matcher.group(1)); | ||
| } catch (NumberFormatException e) { | ||
| // 숫자가 아닌 경우 파싱 에러 처리 | ||
| throw new CustomException(FixedErrorStatus._EVERYTIME_TIMETABLE_PARSE_ERROR); | ||
| } | ||
| } | ||
|
|
||
| // status 속성을 찾지 못한 경우 파싱 에러 처리 | ||
| throw new CustomException(FixedErrorStatus._EVERYTIME_TIMETABLE_PARSE_ERROR); | ||
| } | ||
|
|
||
| /** | ||
| * Jsoup을 사용하여 XML을 파싱하고 DTO 리스트로 변환합니다. | ||
| */ | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.