Skip to content

Commit

Permalink
Create scholarship api
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Oct 11, 2024
1 parent 8034a0b commit 01ff480
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bestswlkh0310.graduating.graduatingserver.api.scholarship

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/scholarships")
class ScholarshipController(
private val scholarshipService: ScholarshipService
) {
@GetMapping
fun scholarships() =
scholarshipService.getScholarships()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bestswlkh0310.graduating.graduatingserver.api.scholarship

import com.bestswlkh0310.graduating.graduatingserver.api.scholarship.res.ScholarshipRes
import com.bestswlkh0310.graduating.graduatingserver.core.scholarship.ScholarshipRepository
import org.springframework.stereotype.Service

@Service
class ScholarshipService(
private val scholarshipRepository: ScholarshipRepository
) {
fun getScholarships(): List<ScholarshipRes> =
scholarshipRepository.findAll()
.map(ScholarshipRes::of)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.bestswlkh0310.graduating.graduatingserver.api.scholarship.res

import com.bestswlkh0310.graduating.graduatingserver.core.scholarship.ScholarshipEntity
import com.bestswlkh0310.graduating.graduatingserver.core.scholarship.ScholarshipEntity.FinancialAidType
import com.bestswlkh0310.graduating.graduatingserver.core.scholarship.ScholarshipEntity.OperatingInstitutionCategory
import java.time.LocalDate

data class ScholarshipRes(
val id: Long = 0,
val recruitmentStartDate: LocalDate?,
val recruitmentEndDate: LocalDate?,
val productName: String,
val selectionMethodDetails: String?,
val selectionNumberDetails: String?,
val gradeCriteriaDetails: String?,
val incomeCriteriaDetails: String?,
val operatingInstitutionCategory: OperatingInstitutionCategory,
val operatingInstitutionName: String,
val qualificationRestrictionsDetails: String?,
val requiredDocumentsDetails: String?,
val residencyDetails: String?,
val supportDetails: String?,
val recommendationRequiredDetails: String?,
val specificQualificationDetails: String?,
val schoolCategory: List<String>,
val gradeLevel: List<String>,
val financialAidType: FinancialAidType,
val homepageUrl: String,
) {
companion object {
fun of(entity: ScholarshipEntity) = ScholarshipRes(
id = entity.id,
recruitmentStartDate = entity.recruitmentStartDate,
recruitmentEndDate = entity.recruitmentEndDate,
productName = entity.productName,
selectionMethodDetails = entity.selectionMethodDetails,
selectionNumberDetails = entity.selectionNumberDetails,
gradeCriteriaDetails = entity.gradeLevel,
incomeCriteriaDetails = entity.incomeCriteriaDetails,
operatingInstitutionCategory = entity.operatingInstitutionCategory,
operatingInstitutionName = entity.operatingInstitutionName,
qualificationRestrictionsDetails = entity.qualificationRestrictionsDetails,
requiredDocumentsDetails = entity.requiredDocumentsDetails,
residencyDetails = entity.residencyDetails,
supportDetails = entity.supportDetails,
recommendationRequiredDetails = entity.recommendationRequiredDetails,
specificQualificationDetails = entity.specificQualificationDetails,
schoolCategory = entity.schoolCategory?.split("/") ?: emptyList(),
gradeLevel = entity.gradeLevel.split("/"),
financialAidType = entity.financialAidType,
homepageUrl = entity.homepageUrl,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ScholarshipEntity(
id: Long = 0,
recruitmentStartDate: LocalDate?,
recruitmentEndDate: LocalDate?,
number: Int,
productName: String,
selectionMethodDetails: String?,
selectionNumberDetails: String?,
Expand All @@ -23,7 +22,7 @@ class ScholarshipEntity(
supportDetails: String?,
recommendationRequiredDetails: String?,
specificQualificationDetails: String?,
schoolCategory: String,
schoolCategory: String?,
gradeLevel: String,
financialAidType: FinancialAidType,
homepageUrl: String,
Expand All @@ -39,10 +38,6 @@ class ScholarshipEntity(
var recruitmentEndDate = recruitmentEndDate
private set

@Column(nullable = false)
var number = number
private set

@Column(nullable = false)
var productName = productName
private set
Expand Down Expand Up @@ -95,7 +90,6 @@ class ScholarshipEntity(
var specificQualificationDetails = specificQualificationDetails
private set

@Column(nullable = false)
var schoolCategory = schoolCategory
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.bestswlkh0310.graduating.graduatingserver.infra.publicdata.kosaf.Kosa
import org.springframework.boot.CommandLineRunner
import org.springframework.stereotype.Component

@Component
//@Component
class KosafScholarshipLoader(
private val kasafClient: KosafClient,
private val scholarshipRepository: ScholarshipRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ data class KosafScholarshipRes(
return ScholarshipEntity(
recruitmentStartDate = this.recruitmentStartDate.toLocalDate("yyyy-MM-dd"),
recruitmentEndDate = this.recruitmentEndDate.toLocalDate("yyyy-MM-dd"),
number = this.number,
productName = this.productName,
selectionMethodDetails = this.selectionMethodDetails.takeIf { it != "해당없음" },
selectionNumberDetails = this.selectionNumberDetails.takeIf { it != "해당없음" },
Expand All @@ -54,7 +53,7 @@ data class KosafScholarshipRes(
supportDetails = this.supportDetails.takeIf { it != "해당없음" },
recommendationRequiredDetails = this.recommendationRequiredDetails.takeIf { it != "해당없음" },
specificQualificationDetails = this.specificQualificationDetails.takeIf { it != "해당없음" },
schoolCategory = schoolCategory,
schoolCategory = schoolCategory.takeIf { it != "해당없음" },
gradeLevel = this.gradeLevel,
financialAidType = ScholarshipEntity.FinancialAidType.fromKorean(this.financialAidType)!!,
homepageUrl = this.homepageUrl
Expand Down

0 comments on commit 01ff480

Please sign in to comment.