Skip to content

Commit

Permalink
RU admission v2 (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeryboy authored Jan 11, 2025
1 parent b88f1ba commit 1f477e9
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.csereal.core.admissions.api.req

data class UpdateAdmissionReq(
val ko: String,
val en: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wafflestudio.csereal.core.admissions.api.res

import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto

data class GroupedAdmission(
val ko: AdmissionsDto,
val en: AdmissionsDto
)
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.wafflestudio.csereal.core.admissions.api
package com.wafflestudio.csereal.core.admissions.api.v1

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionReqBody
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto
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 jakarta.validation.constraints.Positive
import org.springframework.context.annotation.Profile
import org.springframework.web.bind.annotation.*

@RequestMapping("/api/v1/admissions")
@RestController
@RestController("AdmissionsControllerV1")
class AdmissionsController(
private val admissionsService: AdmissionsService
) {
Expand All @@ -31,6 +29,7 @@ class AdmissionsController(
return admissionsService.createAdmission(req, mainType, postType)
}

@Deprecated("USE V2 API")
@GetMapping("/{mainTypeStr}/{postTypeStr}")
fun readAdmission(
@PathVariable(required = true) mainTypeStr: String,
Expand Down Expand Up @@ -70,10 +69,4 @@ class AdmissionsController(
pageNum,
amount
)

@Profile("!prod")
@PostMapping("/migrate")
fun migrateAdmissions(
@RequestBody reqList: List<@Valid AdmissionMigrateElem>
): List<AdmissionsDto> = admissionsService.migrateAdmissions(reqList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.wafflestudio.csereal.core.admissions.api.v2

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.core.admissions.api.req.UpdateAdmissionReq
import com.wafflestudio.csereal.core.admissions.api.res.GroupedAdmission
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 org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RequestMapping("/api/v2/admissions")
@RestController
class AdmissionsController(
private val admissionsService: AdmissionsService
) {
@GetMapping("/{mainTypeStr}/{postTypeStr}")
fun readAdmission(
@PathVariable(required = true) mainTypeStr: String,
@PathVariable(required = true) postTypeStr: String
): GroupedAdmission {
val mainType = AdmissionsMainType.fromJsonValue(mainTypeStr)
val postType = AdmissionsPostType.fromJsonValue(postTypeStr)
return admissionsService.readGroupedAdmission(mainType, postType)
}

@AuthenticatedStaff
@PutMapping("/{mainTypeStr}/{postTypeStr}")
fun updateAdmission(
@PathVariable(required = true) mainTypeStr: String,
@PathVariable(required = true) postTypeStr: String,
@RequestBody updateAdmissionReq: UpdateAdmissionReq
) {
val mainType = AdmissionsMainType.fromJsonValue(mainTypeStr)
val postType = AdmissionsPostType.fromJsonValue(postTypeStr)
admissionsService.updateAdmission(mainType, postType, updateAdmissionReq)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AdmissionsEntity(
val postType: AdmissionsPostType,

@Column(columnDefinition = "mediumText")
val description: String,
var description: String,

@Column(nullable = false, columnDefinition = "mediumText")
var searchContent: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.wafflestudio.csereal.core.admissions.service

import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionMigrateElem
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionReqBody
import com.wafflestudio.csereal.core.admissions.api.req.UpdateAdmissionReq
import com.wafflestudio.csereal.core.admissions.api.res.AdmissionSearchResBody
import com.wafflestudio.csereal.core.admissions.api.res.AdmissionSearchResElem
import com.wafflestudio.csereal.core.admissions.api.res.GroupedAdmission
import com.wafflestudio.csereal.core.admissions.database.AdmissionsEntity
import com.wafflestudio.csereal.core.admissions.database.AdmissionsRepository
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto
Expand All @@ -30,7 +31,16 @@ interface AdmissionsService {
language: LanguageType
): AdmissionsDto

fun migrateAdmissions(requestList: List<AdmissionMigrateElem>): List<AdmissionsDto>
fun readGroupedAdmission(
mainType: AdmissionsMainType,
postType: AdmissionsPostType
): GroupedAdmission

fun updateAdmission(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
updateAdmissionReq: UpdateAdmissionReq
)

fun searchPageAdmission(
keyword: String,
Expand Down Expand Up @@ -70,6 +80,48 @@ class AdmissionsServiceImpl(
)?.let { AdmissionsDto.of(it) }
?: throw CserealException.Csereal404("해당하는 페이지를 찾을 수 없습니다.")

@Transactional(readOnly = true)
override fun readGroupedAdmission(
mainType: AdmissionsMainType,
postType: AdmissionsPostType
): GroupedAdmission {
val koAdmission = admissionsRepository.findByMainTypeAndPostTypeAndLanguage(
mainType,
postType,
LanguageType.KO
)?.let { AdmissionsDto.of(it) }
?: throw CserealException.Csereal404("해당하는 한글 페이지를 찾을 수 없습니다.")
val enAdmission = admissionsRepository.findByMainTypeAndPostTypeAndLanguage(
mainType,
postType,
LanguageType.EN
)?.let { AdmissionsDto.of(it) }
?: throw CserealException.Csereal404("해당하는 영어 페이지를 찾을 수 없습니다.")
return GroupedAdmission(koAdmission, enAdmission)
}

@Transactional
override fun updateAdmission(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
updateAdmissionReq: UpdateAdmissionReq
) {
val koAdmission = admissionsRepository.findByMainTypeAndPostTypeAndLanguage(
mainType,
postType,
LanguageType.KO
) ?: throw CserealException.Csereal404("해당하는 한글 페이지를 찾을 수 없습니다.")
val enAdmission = admissionsRepository.findByMainTypeAndPostTypeAndLanguage(
mainType,
postType,
LanguageType.EN
) ?: throw CserealException.Csereal404("해당하는 한글 페이지를 찾을 수 없습니다.")
koAdmission.description = updateAdmissionReq.ko
enAdmission.description = updateAdmissionReq.en
syncSearchAdmission(koAdmission)
syncSearchAdmission(enAdmission)
}

@Transactional(readOnly = true)
override fun searchTopAdmission(
keyword: String,
Expand Down Expand Up @@ -123,30 +175,4 @@ class AdmissionsServiceImpl(
}
)
}

@Transactional
override fun migrateAdmissions(requestList: List<AdmissionMigrateElem>) = requestList.map {
// Todo: add admission migrate search
val mainType = AdmissionsMainType.fromJsonValue(it.mainType)
val postType = AdmissionsPostType.fromJsonValue(it.postType)
val language = LanguageType.makeStringToLanguageType(it.language)
AdmissionsEntity(
name = it.name!!,
mainType = mainType,
postType = postType,
language = language,
description = it.description!!,
searchContent = AdmissionsEntity.createSearchContent(
name = it.name,
mainType = mainType,
postType = postType,
language = language,
description = it.description
)
)
}.let {
admissionsRepository.saveAll(it)
}.map {
AdmissionsDto.of(it)
}
}

0 comments on commit 1f477e9

Please sign in to comment.