Skip to content
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

feat: migrateAdmissions 추가 #165

Merged
merged 4 commits into from
Sep 28, 2023
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
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
Loading