Skip to content

Commit

Permalink
fix: migrateAdmissions 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
skfotakf committed Sep 26, 2023
1 parent 3db1459 commit 78e5b07
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,4 +48,11 @@ class AdmissionsController(
fun readGraduateAdmissions(): ResponseEntity<AdmissionsDto> {
return ResponseEntity.ok(admissionsService.readGraduateAdmissions())
}

@PostMapping("/migrate")
fun migrateAdmissions(
@RequestBody requestList: List<AdmissionsRequest>
): ResponseEntity<List<AdmissionsDto>> {
return ResponseEntity.ok(admissionsService.migrateAdmissions(requestList))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -11,6 +12,8 @@ class AdmissionsEntity(
@Enumerated(EnumType.STRING)
val postType: AdmissionsPostType,
val pageName: String,

@Column(columnDefinition = "mediumText")
val description: String
) : BaseTimeEntity() {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.csereal.core.admissions.dto

data class AdmissionsRequest(
val postType: String,
val description: String
)
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,6 +14,7 @@ interface AdmissionsService {
fun createGraduateAdmissions(request: AdmissionsDto): AdmissionsDto
fun readUndergraduateAdmissions(postType: String): AdmissionsDto
fun readGraduateAdmissions(): AdmissionsDto
fun migrateAdmissions(requestList: List<AdmissionsRequest>): List<AdmissionsDto>
}

@Service
Expand Down Expand Up @@ -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("해당하는 페이지를 찾을 수 없습니다.")
}
}
Expand All @@ -63,6 +67,36 @@ class AdmissionsServiceImpl(
return AdmissionsDto.of(admissionsRepository.findByPostType(AdmissionsPostType.GRADUATE))
}

@Transactional
override fun migrateAdmissions(requestList: List<AdmissionsRequest>): List<AdmissionsDto> {
val list = mutableListOf<AdmissionsDto>()

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()
Expand Down

0 comments on commit 78e5b07

Please sign in to comment.