Skip to content

Commit

Permalink
perf: 학교 검색시 대안학교가 검색되지 않는 오류 수정
Browse files Browse the repository at this point in the history
- 전 코드에서 초등학교부터 고등학교까지 다 조회가 되어 대안학교와 중학교만 할 수 있도록 변경했어요.
  • Loading branch information
jyj1289 committed Oct 14, 2024
1 parent b14b5f5 commit fd8a204
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
Expand All @@ -20,10 +21,17 @@ public class SearchSchoolService {
private final ObjectMapper objectMapper;

public List<SchoolResponse> execute(String q) throws JsonProcessingException {
String htmlResponse = neisClient.getSchoolInfo(neisProperties.getKey(), q);
NeisSchoolResponse response = objectMapper.readValue(htmlResponse, NeisSchoolResponse.class);
String htmlResponse1 = neisClient.getSchoolInfo(neisProperties.getKey(), q, "중학교");
String htmlResponse2 = neisClient.getSchoolInfo(neisProperties.getKey(), q, "각종학교(중)");

return response.getSchoolInfo().stream()
NeisSchoolResponse response1 = objectMapper.readValue(htmlResponse1, NeisSchoolResponse.class);
NeisSchoolResponse response2 = objectMapper.readValue(htmlResponse2, NeisSchoolResponse.class);

List<NeisSchoolResponse.SchoolInfo.Row> combinedSchoolInfo = new ArrayList<>();
combinedSchoolInfo.addAll(response1.getSchoolInfo());
combinedSchoolInfo.addAll(response2.getSchoolInfo());

return combinedSchoolInfo.stream()
.map(s -> SchoolResponse.builder()
.name(s.getSchoolName())
.location(s.getLocation())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface NeisClient {
@GetMapping(value = "/schoolInfo?Type=json&pSize=10")
String getSchoolInfo(
@RequestParam("Key") String key,
@RequestParam("SCHUL_NM") String schoolName
@RequestParam("SCHUL_NM") String schoolName,
@RequestParam(name = "SCHUL_KND_SC_NM", required = false) String schoolType
);
}

0 comments on commit fd8a204

Please sign in to comment.