From 78e5b071cf2556df99994e1e3d4cfd0c5c9f76d1 Mon Sep 17 00:00:00 2001 From: "DESKTOP-USQPRVG\\gram" Date: Tue, 26 Sep 2023 22:01:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20migrateAdmissions=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csereal/common/config/SecurityConfig.kt | 2 +- .../admissions/api/AdmissionsController.kt | 8 +++++ .../admissions/database/AdmissionsEntity.kt | 3 ++ .../core/admissions/dto/AdmissionsDto.kt | 4 ++- .../core/admissions/dto/AdmissionsRequest.kt | 6 ++++ .../admissions/service/AdmissionsService.kt | 36 ++++++++++++++++++- 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsRequest.kt diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt b/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt index 6f5c7ff1..fbb56f82 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt @@ -31,7 +31,7 @@ class SecurityConfig( .cors().and() .csrf().disable() .oauth2Login() - .loginPage("${endpointProperties.frontend}/oauth2/authorization/idsnucse") + .loginPage("/oauth2/authorization/idsnucse") .redirectionEndpoint() .baseUri("/api/v1/login/oauth2/code/idsnucse").and() .userInfoEndpoint().oidcUserService(customOidcUserService).and() diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/api/AdmissionsController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/api/AdmissionsController.kt index d9f6a733..5b716ef9 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/api/AdmissionsController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/api/AdmissionsController.kt @@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.admissions.api import com.wafflestudio.csereal.common.aop.AuthenticatedStaff import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto +import com.wafflestudio.csereal.core.admissions.dto.AdmissionsRequest import com.wafflestudio.csereal.core.admissions.service.AdmissionsService import jakarta.validation.Valid import org.springframework.http.ResponseEntity @@ -47,4 +48,11 @@ class AdmissionsController( fun readGraduateAdmissions(): ResponseEntity { return ResponseEntity.ok(admissionsService.readGraduateAdmissions()) } + + @PostMapping("/migrate") + fun migrateAdmissions( + @RequestBody requestList: List + ): ResponseEntity> { + return ResponseEntity.ok(admissionsService.migrateAdmissions(requestList)) + } } diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/database/AdmissionsEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/database/AdmissionsEntity.kt index 8510708a..a2f50be2 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/database/AdmissionsEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/database/AdmissionsEntity.kt @@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.admissions.database import com.wafflestudio.csereal.common.config.BaseTimeEntity import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto +import jakarta.persistence.Column import jakarta.persistence.Entity import jakarta.persistence.EnumType import jakarta.persistence.Enumerated @@ -11,6 +12,8 @@ class AdmissionsEntity( @Enumerated(EnumType.STRING) val postType: AdmissionsPostType, val pageName: String, + + @Column(columnDefinition = "mediumText") val description: String ) : BaseTimeEntity() { companion object { diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsDto.kt b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsDto.kt index 5b8ae40a..890f4825 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsDto.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsDto.kt @@ -1,10 +1,12 @@ package com.wafflestudio.csereal.core.admissions.dto +import com.fasterxml.jackson.annotation.JsonInclude import com.wafflestudio.csereal.core.admissions.database.AdmissionsEntity import java.time.LocalDateTime data class AdmissionsDto( - val id: Long, + @JsonInclude(JsonInclude.Include.NON_NULL) + val id: Long? = null, val description: String, val createdAt: LocalDateTime?, val modifiedAt: LocalDateTime? diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsRequest.kt b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsRequest.kt new file mode 100644 index 00000000..4fd1e458 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/dto/AdmissionsRequest.kt @@ -0,0 +1,6 @@ +package com.wafflestudio.csereal.core.admissions.dto + +data class AdmissionsRequest( + val postType: String, + val description: String +) diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/service/AdmissionsService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/service/AdmissionsService.kt index e89b57ee..4f943785 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/admissions/service/AdmissionsService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/admissions/service/AdmissionsService.kt @@ -1,10 +1,11 @@ package com.wafflestudio.csereal.core.admissions.service import com.wafflestudio.csereal.common.CserealException -import com.wafflestudio.csereal.core.admissions.database.AdmissionsPostType import com.wafflestudio.csereal.core.admissions.database.AdmissionsEntity +import com.wafflestudio.csereal.core.admissions.database.AdmissionsPostType import com.wafflestudio.csereal.core.admissions.database.AdmissionsRepository import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto +import com.wafflestudio.csereal.core.admissions.dto.AdmissionsRequest import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -13,6 +14,7 @@ interface AdmissionsService { fun createGraduateAdmissions(request: AdmissionsDto): AdmissionsDto fun readUndergraduateAdmissions(postType: String): AdmissionsDto fun readGraduateAdmissions(): AdmissionsDto + fun migrateAdmissions(requestList: List): List } @Service @@ -51,9 +53,11 @@ class AdmissionsServiceImpl( "early" -> AdmissionsDto.of( admissionsRepository.findByPostType(AdmissionsPostType.UNDERGRADUATE_EARLY_ADMISSION) ) + "regular" -> AdmissionsDto.of( admissionsRepository.findByPostType(AdmissionsPostType.UNDERGRADUATE_REGULAR_ADMISSION) ) + else -> throw CserealException.Csereal404("해당하는 페이지를 찾을 수 없습니다.") } } @@ -63,6 +67,36 @@ class AdmissionsServiceImpl( return AdmissionsDto.of(admissionsRepository.findByPostType(AdmissionsPostType.GRADUATE)) } + @Transactional + override fun migrateAdmissions(requestList: List): List { + val list = mutableListOf() + + for (request in requestList) { + val enumPostType = makeStringToAdmissionsPostType(request.postType) + + val pageName = when (enumPostType) { + AdmissionsPostType.UNDERGRADUATE_EARLY_ADMISSION -> "수시 모집" + AdmissionsPostType.UNDERGRADUATE_REGULAR_ADMISSION -> "정시 모집" + AdmissionsPostType.GRADUATE -> "대학원" + else -> throw CserealException.Csereal404("해당하는 페이지를 찾을 수 없습니다.") + } + + val admissionsDto = AdmissionsDto( + id = null, + description = request.description, + createdAt = null, + modifiedAt = null + ) + + val newAdmissions = AdmissionsEntity.of(enumPostType, pageName, admissionsDto) + + admissionsRepository.save(newAdmissions) + + list.add(AdmissionsDto.of(newAdmissions)) + } + return list + } + private fun makeStringToAdmissionsPostType(postType: String): AdmissionsPostType { try { val upperPostType = postType.replace("-", "_").uppercase() From b0afcd5c0991dd0f50fca3547428f7d72943d9bc Mon Sep 17 00:00:00 2001 From: "DESKTOP-USQPRVG\\gram" Date: Tue, 26 Sep 2023 22:03:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=9E=98=EB=AA=BB=20=EC=93=B4?= =?UTF-8?q?=EA=B1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wafflestudio/csereal/common/config/SecurityConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt b/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt index fbb56f82..6f5c7ff1 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/common/config/SecurityConfig.kt @@ -31,7 +31,7 @@ class SecurityConfig( .cors().and() .csrf().disable() .oauth2Login() - .loginPage("/oauth2/authorization/idsnucse") + .loginPage("${endpointProperties.frontend}/oauth2/authorization/idsnucse") .redirectionEndpoint() .baseUri("/api/v1/login/oauth2/code/idsnucse").and() .userInfoEndpoint().oidcUserService(customOidcUserService).and()