-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/#120 #122
base: master
Are you sure you want to change the base?
Feature/#120 #122
Changes from 1 commit
cf0ab1a
ec2a824
780dfaf
94e8567
08b8915
4626b07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencies { | ||
implementation 'org.springframework:spring-context:6.0.6' | ||
implementation 'org.springframework:spring-web:6.0.6' | ||
implementation 'org.springframework:spring-tx:6.0.6' | ||
|
||
implementation 'org.springframework.boot:spring-boot:3.0.4' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.b1nd.dodam.neis.client.core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package b1nd.dodam.neis.meal.client.properties; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties("app.neis.meal") | ||
public class NeisMealProperties { | ||
|
||
private String mealEndpoint; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
dependencies { | ||
implementation project(':dodam-in-system-available:dodam-client-core') | ||
implementation project(':dodam-in-system-available:dodam-neis-client-core') | ||
|
||
implementation 'org.springframework:spring-context:6.0.6' | ||
implementation 'org.springframework:spring-web:6.0.6' | ||
implementation 'org.springframework:spring-tx:6.0.6' | ||
|
||
implementation 'org.springframework.boot:spring-boot:3.0.4' | ||
|
||
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.14.2' | ||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2' | ||
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' | ||
|
||
implementation 'com.googlecode.json-simple:json-simple:1.1.1' | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mealData에서 null처리 해야 nullPointException이 안 뜰것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null이 들어올 일이 없을 듯 합니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 메소드는 다 stream형식으로 하였는데 getSchedules메소드만 stream을 적용 안 한 이유가 있나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로직이 복잡해서 stream을 쓰면 가독성이 안좋아질 것 같아서 사용 안했습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일정 합칠때 distinct 필요할것 같아요 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package b1nd.dodam.neis.schedule.client; | ||
|
||
import b1nd.dodam.client.core.WebClientSupport; | ||
import b1nd.dodam.neis.client.core.NeisCoreProperties; | ||
import b1nd.dodam.neis.schedule.client.data.NeisSchedule; | ||
import b1nd.dodam.neis.schedule.client.properties.NeisScheduleProperties; | ||
import b1nd.dodam.neis.schedule.client.util.NeisScheduleUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class NeisScheduleClient { | ||
private final WebClientSupport webClient; | ||
private final NeisCoreProperties coreProperties; | ||
private final NeisScheduleProperties scheduleProperties; | ||
|
||
public List<NeisSchedule> getSchedules(LocalDate startDate, LocalDate endDate) { | ||
String rawResponse = getRawSchedule(startDate, endDate); | ||
JSONArray rawData = NeisScheduleUtil.getRawData(rawResponse); | ||
List<NeisSchedule> scheduleList = new ArrayList<>(); | ||
|
||
for (Object object : rawData) { | ||
JSONObject mealData = (JSONObject) object; | ||
|
||
String eventName = String.valueOf(mealData.get("EVENT_NM")); | ||
List<String> grades = NeisScheduleUtil.determineGrades(mealData); | ||
LocalDate date = NeisScheduleUtil.parseDate(String.valueOf(mealData.get("AA_YMD"))); | ||
|
||
scheduleList.add(new NeisSchedule(eventName, grades, date, null)); | ||
} | ||
|
||
return mergeSchedules(scheduleList); | ||
} | ||
|
||
private List<NeisSchedule> mergeSchedules(List<NeisSchedule> scheduleList) { | ||
return scheduleList.stream() | ||
.collect(Collectors.groupingBy(NeisSchedule::eventName)) | ||
.entrySet().stream() | ||
.map(entry -> createMergedSchedule(entry.getKey(), entry.getValue())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private NeisSchedule createMergedSchedule(String eventName, List<NeisSchedule> schedules) { | ||
LocalDate minDate = schedules.stream() | ||
.map(NeisSchedule::startDate) | ||
.min(LocalDate::compareTo) | ||
.orElse(null); | ||
|
||
LocalDate maxDate = schedules.stream() | ||
.map(NeisSchedule::startDate) | ||
.max(LocalDate::compareTo) | ||
.orElse(null); | ||
|
||
List<String> mergedGrades = schedules.get(0).grades(); | ||
return new NeisSchedule(eventName, mergedGrades, minDate, maxDate); | ||
} | ||
|
||
private String getRawSchedule(LocalDate startDate, LocalDate endDate) { | ||
return webClient.get( | ||
UriComponentsBuilder.fromUriString(coreProperties.getUrl() + scheduleProperties.getScheduleEndpoint()) | ||
.build(coreProperties.getApiKey(), startDate, endDate).toString(), | ||
String.class | ||
).block(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package b1nd.dodam.neis.schedule.client.data; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public record NeisSchedule( | ||
String eventName, | ||
List<String> grades, | ||
LocalDate startDate, | ||
LocalDate endDate | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package b1nd.dodam.neis.schedule.client.properties; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties("app.neis.schedule") | ||
public class NeisScheduleProperties { | ||
|
||
private String scheduleEndpoint; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package b1nd.dodam.neis.schedule.client.util; | ||
|
||
import b1nd.dodam.core.exception.global.InternalServerException; | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class NeisScheduleUtil { | ||
|
||
public static List<String> determineGrades(JSONObject mealData) { | ||
List<String> grades = new ArrayList<>(); | ||
if ("Y".equals(mealData.get("ONE_GRADE_EVENT_YN"))) grades.add("1학년"); | ||
if ("Y".equals(mealData.get("TW_GRADE_EVENT_YN"))) grades.add("2학년"); | ||
if ("Y".equals(mealData.get("THREE_GRADE_EVENT_YN"))) grades.add("3학년"); | ||
|
||
if (grades.size() == 3) { | ||
grades.clear(); | ||
grades.add("전교생"); | ||
} | ||
return grades; | ||
} | ||
|
||
public static LocalDate parseDate(String dateString) { | ||
return LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
} | ||
|
||
public static JSONArray getRawData(String response) { | ||
try { | ||
JSONParser jsonParser = new JSONParser(); | ||
JSONObject parse = (JSONObject) jsonParser.parse(response); | ||
JSONArray schoolScheduleInfo = (JSONArray) parse.get("SchoolSchedule"); | ||
JSONObject scheduleInfo = (JSONObject) schoolScheduleInfo.get(1); | ||
return (JSONArray) scheduleInfo.get("row"); | ||
} catch (Exception e) { | ||
throw new InternalServerException(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.b1nd.dodam.neis.schedule.client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엔터 한개 빼주세요