Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package team.incube.flooding.domain.neis.client

import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
import org.springframework.web.client.ResourceAccessException
import org.springframework.web.client.RestClient
import org.springframework.web.client.RestClientResponseException
import team.incube.flooding.domain.neis.client.dto.GetTimetablesRequest
import team.incube.flooding.domain.neis.config.NeisTimetableProperties
import team.incube.flooding.domain.neis.config.DgTimetableProperties
import team.themoment.sdk.exception.ExpectedException
import tools.jackson.databind.JsonNode

@Component
class NeisTimetableClient(
private val neisTimetableProperties: NeisTimetableProperties,
private val dgTimetableProperties: DgTimetableProperties,
restClientBuilder: RestClient.Builder,
@Value("\${datagsm.open-api-key}") private val apiKey: String,
) {
private val restClient =
restClientBuilder
.clone()
.baseUrl(neisTimetableProperties.baseUrl)
.baseUrl(dgTimetableProperties.baseUrl)
.build()

fun getTimetables(request: GetTimetablesRequest): JsonNode =
Expand All @@ -27,28 +29,23 @@ class NeisTimetableClient(
.get()
.uri { builder ->
builder
.path(neisTimetableProperties.path)
.queryParam("KEY", neisTimetableProperties.apiKey)
.queryParam("Type", neisTimetableProperties.dataType)
.queryParam("pIndex", 1)
.queryParam("pSize", neisTimetableProperties.pageSize)
.queryParam("ATPT_OFCDC_SC_CODE", request.officeCode)
.queryParam("SD_SCHUL_CODE", request.schoolCode)
.queryParam("GRADE", request.grade)
.queryParam("CLASS_NM", request.classNumber)
.queryParam("ALL_TI_YMD", request.date.replace("-", ""))
.path(dgTimetableProperties.path)
.queryParam("grade", request.grade)
.queryParam("classNum", request.classNumber)
.queryParam("date", request.date)
.build()
}.retrieve()
}.header("X-API-KEY", apiKey)
.retrieve()
.body(JsonNode::class.java)
?: throw ExpectedException("NEIS 시간표 응답이 비어 있습니다.", HttpStatus.INTERNAL_SERVER_ERROR)
?: throw ExpectedException("DG 시간표 응답이 비어 있습니다.", HttpStatus.INTERNAL_SERVER_ERROR)
} catch (exception: RestClientResponseException) {
throw ExpectedException(
"NEIS 시간표 호출에 실패했습니다. status=${exception.statusCode.value()}",
"DG 시간표 호출에 실패했습니다. status=${exception.statusCode.value()}",
HttpStatus.INTERNAL_SERVER_ERROR,
)
} catch (exception: ResourceAccessException) {
throw ExpectedException(
"NEIS 시간표 서버에 연결할 수 없습니다.",
"DG 시간표 서버에 연결할 수 없습니다.",
HttpStatus.INTERNAL_SERVER_ERROR,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package team.incube.flooding.domain.neis.client.dto

data class GetTimetablesRequest(
val officeCode: String,
val schoolCode: String,
val grade: Int,
val classNumber: Int,
val date: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.incube.flooding.domain.neis.config

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "datagsm.neis.timetables")
data class DgTimetableProperties(
val baseUrl: String,
val path: String = "v1/neis/timetables",
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,12 @@ class NeisController(
),
)

@Operation(summary = "시간표 조회", description = "NEIS 원본 API를 사용해 시간표를 조회합니다.")
@Operation(summary = "시간표 조회", description = "DataGSM API를 사용해 시간표를 조회합니다.")
@ApiResponses(
ApiResponse(responseCode = "200", description = "시간표 조회 성공"),
)
@GetMapping("/timetables")
fun getTimetables(
@Parameter(description = "시도교육청 코드")
@RequestParam officeCode: String,
@Parameter(description = "학교 코드")
@RequestParam schoolCode: String,
@Parameter(description = "학년")
@RequestParam
@Min(value = 1, message = "grade는 1 이상이어야 합니다.")
Expand All @@ -74,8 +70,6 @@ class NeisController(
"OK",
getNeisTimetablesService.execute(
GetNeisTimetablesRequest(
officeCode = officeCode,
schoolCode = schoolCode,
grade = grade,
classNumber = classNumber,
date = date,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package team.incube.flooding.domain.neis.presentation.data.request

data class GetNeisTimetablesRequest(
val officeCode: String,
val schoolCode: String,
val grade: Int,
val classNumber: Int,
val date: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class GetNeisTimetablesServiceImpl(
val response =
neisTimetableClient.getTimetables(
GetTimetablesRequest(
officeCode = request.officeCode,
schoolCode = request.schoolCode,
grade = request.grade,
classNumber = request.classNumber,
date = request.date,
Expand Down Expand Up @@ -66,7 +64,7 @@ class GetNeisTimetablesServiceImpl(
period = periodNumbers.firstOrNull() ?: (idx + 1),
subject = valueOf(periodNode, "ITRT_CNTNT", "subject") ?: "미정",
teacher = valueOf(periodNode, "TEACHER_NM", "teacher"),
classroom = valueOf(periodNode, "CLRM_NM", "CLASSROOM", "classroom"),
classroom = valueOf(periodNode, "CLRM_NM", "CLASSROOM", "classroom", "classroomName"),
)

periodNumbers.forEach { periodNum ->
Expand Down
10 changes: 3 additions & 7 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,16 @@ oauth:
client-id: ${OAUTH_CLIENT_ID}
client-secret: ${OAUTH_CLIENT_SECRET}

neis:
openapi:
timetable:
baseUrl: ${NEIS_OPENAPI_TIMETABLE_BASE_URL:https://open.neis.go.kr/}
apiKey: ${NEIS_TIMETABLE_API_KEY}
path: "hub/hisTimetable"

datagsm:
base-url: ${DATAGSM_BASE_URL:https://api.datagsm.com}
open-api-key: ${DATAGSM_OPEN_API_KEY}
neis:
meals:
baseUrl: ${DATAGSM_NEIS_MEALS_BASE_URL:https://openapi.datagsm.kr/}
path: "v1/neis/meals"
timetables:
baseUrl: ${DATAGSM_NEIS_TIMETABLES_BASE_URL:https://openapi.datagsm.kr/}
path: "v1/neis/timetables"

ai:
chatbot:
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/application-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ oauth:
client-id: test-client-id
client-secret: test-client-secret

neis:
openapi:
timetable:
apiKey: test-key

datagsm:
open-api-key: test-key

Expand Down
Loading