Skip to content

Commit

Permalink
Merge pull request #134 from 1e5i-Shark/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
GiHoo authored Mar 15, 2024
2 parents 8a4ece4 + 0cd9c18 commit 9ff61a4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import ei.algobaroapi.domain.problem.exception.common.ProblemErrorCode;
import ei.algobaroapi.domain.solve.domain.SolveStatus;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -38,7 +39,37 @@ public ProblemHtmlResponse getProblemInfoHtml(String problemLink) {

@Override
public List<ProblemTestCaseResponse> getProblemTestCases(ProblemFindRequest request) {
return Collections.emptyList();
try {
String problemLink = request.getProblemLink();

// Jsoup을 사용하여 웹페이지 가져오기
Document doc = Jsoup.connect(problemLink).get();

Elements sampleInputs = doc.select("[id^=sampleinput]");
Elements sampleOutputs = doc.select("[id^=sampleoutput]");

// 예제 입력과 출력의 개수 확인
int numSamples = sampleInputs.size();

List<ProblemTestCaseResponse> problemTestCases = new ArrayList<>();

// 예제 입력 출력을 출력
for (int i = 0; i < numSamples; i++) {
Element inputElement = sampleInputs.get(i);
Element outputElement = sampleOutputs.get(i);

// 예제 입력과 출력 텍스트 추출
String inputText = inputElement.select("pre").text();
String outputText = outputElement.select("pre").text();

// ProblemTestCaseResponse 생성
problemTestCases.add(ProblemTestCaseResponse.of(i + 1, inputText, outputText));
}

return problemTestCases;
} catch (IOException e) {
throw CrawlingAccessException.of(ProblemErrorCode.CRAWLING_NOT_ACCESS);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import ei.algobaroapi.domain.solve.exception.SolveFoundException;
import ei.algobaroapi.global.response.message.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class SolveExceptionHandler {

@ExceptionHandler(SolveFoundException.class)
Expand Down

0 comments on commit 9ff61a4

Please sign in to comment.