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

Refactor: Admission 언어 추가 및 리팩터링 진행 #182

Merged
merged 11 commits into from
Feb 11, 2024
Original file line number Diff line number Diff line change
@@ -1,58 +1,48 @@
package com.wafflestudio.csereal.core.admissions.api

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionReqBody
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsRequest
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionMigrateElem
import com.wafflestudio.csereal.core.admissions.service.AdmissionsService
import com.wafflestudio.csereal.core.admissions.type.AdmissionsMainType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import jakarta.validation.Valid
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RequestMapping("/api/v1/admissions")
@RestController
class AdmissionsController(
private val admissionsService: AdmissionsService
) {
@AuthenticatedStaff
@PostMapping("/undergraduate/{postType}")
fun createUndergraduateAdmissions(
@PathVariable postType: String,
@PostMapping("/{mainTypeStr}/{postTypeStr}")
fun createAdmission(
@PathVariable(required = true) mainTypeStr: String,
@PathVariable(required = true) postTypeStr: String,
@Valid @RequestBody
request: AdmissionsDto
req: AdmissionReqBody
): AdmissionsDto {
return admissionsService.createUndergraduateAdmissions(postType, request)
val mainType = AdmissionsMainType.fromJsonValue(mainTypeStr)
val postType = AdmissionsPostType.fromJsonValue(postTypeStr)
return admissionsService.createAdmission(req, mainType, postType)
}

@AuthenticatedStaff
@PostMapping("/graduate")
fun createGraduateAdmissions(
@Valid @RequestBody
request: AdmissionsDto
@GetMapping("/{mainTypeStr}/{postTypeStr}")
fun readAdmission(
@PathVariable(required = true) mainTypeStr: String,
@PathVariable(required = true) postTypeStr: String,
@RequestParam(required = true, defaultValue = "ko") language: String
): AdmissionsDto {
return admissionsService.createGraduateAdmissions(request)
}

@GetMapping("/undergraduate/{postType}")
fun readUndergraduateAdmissions(
@PathVariable postType: String
): ResponseEntity<AdmissionsDto> {
return ResponseEntity.ok(admissionsService.readUndergraduateAdmissions(postType))
}

@GetMapping("/graduate")
fun readGraduateAdmissions(): ResponseEntity<AdmissionsDto> {
return ResponseEntity.ok(admissionsService.readGraduateAdmissions())
val mainType = AdmissionsMainType.fromJsonValue(mainTypeStr)
val postType = AdmissionsPostType.fromJsonValue(postTypeStr)
val languageType = LanguageType.makeStringToLanguageType(language)
return admissionsService.readAdmission(mainType, postType, languageType)
}

@PostMapping("/migrate")
fun migrateAdmissions(
@RequestBody requestList: List<AdmissionsRequest>
): ResponseEntity<List<AdmissionsDto>> {
return ResponseEntity.ok(admissionsService.migrateAdmissions(requestList))
}
@RequestBody reqList: List<@Valid AdmissionMigrateElem>
): List<AdmissionsDto> = admissionsService.migrateAdmissions(reqList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wafflestudio.csereal.core.admissions.api.req

import org.jetbrains.annotations.NotNull

data class AdmissionMigrateElem(
@field:NotNull val name: String?,
val mainType: String,
val postType: String,
val language: String,
@field:NotNull val description: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wafflestudio.csereal.core.admissions.api.req

import org.jetbrains.annotations.NotNull

data class AdmissionReqBody(
@field:NotNull val name: String?,
val language: String = "ko",
@field:NotNull val description: String?
)
Original file line number Diff line number Diff line change
@@ -1,28 +1,63 @@
package com.wafflestudio.csereal.core.admissions.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionReqBody
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto
import com.wafflestudio.csereal.core.admissions.type.AdmissionsMainType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.Table
import jakarta.persistence.UniqueConstraint

@Entity(name = "admissions")
@Table(
uniqueConstraints = [
UniqueConstraint(columnNames = ["language", "mainType", "postType"])
]
)
class AdmissionsEntity(
val name: String,

@Enumerated(EnumType.STRING)
val language: LanguageType,

@Enumerated(EnumType.STRING)
val mainType: AdmissionsMainType,

@Enumerated(EnumType.STRING)
val postType: AdmissionsPostType,
val pageName: String,

@Column(columnDefinition = "mediumText")
val description: String
) : BaseTimeEntity() {
companion object {
fun of(postType: AdmissionsPostType, pageName: String, admissionsDto: AdmissionsDto): AdmissionsEntity {
return AdmissionsEntity(
postType = postType,
pageName = pageName,
description = admissionsDto.description
)
}
fun of(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
name: String,
admissionsDto: AdmissionsDto
) = AdmissionsEntity(
mainType = mainType,
postType = postType,
name = name,
description = admissionsDto.description,
language = LanguageType.makeStringToLanguageType(admissionsDto.language)
)

fun of(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
req: AdmissionReqBody
) = AdmissionsEntity(
mainType = mainType,
postType = postType,
name = req.name!!,
description = req.description!!,
language = LanguageType.makeStringToLanguageType(req.language)
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.wafflestudio.csereal.core.admissions.database

import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsMainType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import org.springframework.data.jpa.repository.JpaRepository

interface AdmissionsRepository : JpaRepository<AdmissionsEntity, Long> {
fun findByPostType(postType: AdmissionsPostType): AdmissionsEntity
fun findByMainTypeAndPostTypeAndLanguage(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
language: LanguageType
): AdmissionsEntity?
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.wafflestudio.csereal.core.admissions.dto

import com.fasterxml.jackson.annotation.JsonInclude
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.admissions.database.AdmissionsEntity
import java.time.LocalDateTime

data class AdmissionsDto(
@JsonInclude(JsonInclude.Include.NON_NULL)
val id: Long? = null,
val id: Long,
val name: String,
val mainType: String,
val postType: String,
val language: String,
val description: String,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?
val createdAt: LocalDateTime,
val modifiedAt: LocalDateTime
) {
companion object {
fun of(entity: AdmissionsEntity): AdmissionsDto = entity.run {
AdmissionsDto(
id = this.id,
name = this.name,
mainType = this.mainType.toJsonValue(),
postType = this.postType.toJsonValue(),
language = LanguageType.makeLowercase(this.language),
description = this.description,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt
createdAt = this.createdAt!!,
modifiedAt = this.modifiedAt!!
)
}
}
Expand Down

This file was deleted.

Loading
Loading