Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/mock-auth' into feat/mock-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeryboy committed Feb 21, 2024
2 parents 0fe2f6c + a3904a7 commit 4c0ff20
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wafflestudio.csereal.common.utils

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter

@Converter
class StringListConverter : AttributeConverter<MutableList<String>, String> {
override fun convertToDatabaseColumn(p0: MutableList<String>?): String =
ObjectMapper().writeValueAsString(p0 ?: mutableListOf<String>())

override fun convertToEntityAttribute(p0: String?): MutableList<String> =
ObjectMapper().readValue(p0 ?: "[]")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType
import com.wafflestudio.csereal.common.controller.MainImageContentEntityType
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.common.utils.StringListConverter
import com.wafflestudio.csereal.core.about.dto.AboutDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity
Expand All @@ -22,8 +23,9 @@ class AboutEntity(

var year: Int?,

@OneToMany(mappedBy = "about", cascade = [CascadeType.ALL], orphanRemoval = true)
val locations: MutableList<LocationEntity> = mutableListOf(),
@Column(columnDefinition = "TEXT")
@Convert(converter = StringListConverter::class)
var locations: MutableList<String> = mutableListOf(),

@OneToMany(mappedBy = "")
var attachments: MutableList<AttachmentEntity> = mutableListOf(),
Expand All @@ -42,7 +44,8 @@ class AboutEntity(
language = languageType,
name = aboutDto.name,
description = aboutDto.description,
year = aboutDto.year
year = aboutDto.year,
locations = aboutDto.locations?.toMutableList() ?: mutableListOf()
)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class AboutDto(
year = this.year,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
locations = this.locations.map { it.name },
locations = this.locations,
imageURL = imageURL,
attachments = attachmentResponses
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class FacilityDto(
language = LanguageType.makeLowercase(this.language),
name = this.name!!,
description = this.description,
locations = this.locations.map { it.name }
locations = this.locations
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ class AboutServiceImpl(
val enumLanguageType = LanguageType.makeStringToLanguageType(request.language)
val newAbout = AboutEntity.of(enumPostType, enumLanguageType, request)

if (request.locations != null) {
for (location in request.locations) {
LocationEntity.create(location, newAbout)
}
}

if (mainImage != null) {
mainImageService.uploadMainImage(newAbout, mainImage)
}
Expand Down Expand Up @@ -277,39 +271,31 @@ class AboutServiceImpl(
}

@Transactional
override fun migrateFacilities(requestList: List<FacilityDto>): List<FacilityDto> {
val list = mutableListOf<FacilityDto>()

for (request in requestList) {
val language = request.language
val name = request.name
val description = request.description
val aboutDto = AboutDto(
override fun migrateFacilities(requestList: List<FacilityDto>): List<FacilityDto> =
requestList.map {
AboutDto(
id = null,
language = language,
name = name,
description = description,
language = it.language,
name = it.name,
description = it.description,
year = null,
createdAt = null,
modifiedAt = null,
locations = null,
locations = it.locations,
imageURL = null,
attachments = listOf()
)

val languageType = LanguageType.makeStringToLanguageType(language)
val newAbout = AboutEntity.of(AboutPostType.FACILITIES, languageType, aboutDto)

for (location in request.locations) {
LocationEntity.create(location, newAbout)
).let { dto ->
AboutEntity.of(
AboutPostType.FACILITIES,
LanguageType.makeStringToLanguageType(it.language),
dto
)
}

aboutRepository.save(newAbout)

list.add(FacilityDto.of(newAbout))
}.let {
aboutRepository.saveAll(it)
}.map {
FacilityDto.of(it)
}
return list
}

@Transactional
override fun migrateDirections(requestList: List<DirectionDto>): List<DirectionDto> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class AdmissionsController(
return admissionsService.readAdmission(mainType, postType, languageType)
}

@GetMapping("/search")
fun searchTopAdmissions(
@RequestParam(required = true) keyword: String,
@RequestParam(required = true, defaultValue = "ko") language: String,
@RequestParam(required = true) number: Int
) = admissionsService.searchTopAdmission(
keyword,
LanguageType.makeStringToLanguageType(language),
number
)

@PostMapping("/migrate")
fun migrateAdmissions(
@RequestBody reqList: List<@Valid AdmissionMigrateElem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.wafflestudio.csereal.core.admissions.api.res

import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.admissions.database.AdmissionsEntity

data class AdmissionSearchResBody(
val admissions: List<AdmissionSearchResElem>
)

data class AdmissionSearchResElem(
val id: Long,
val name: String,
val mainType: String,
val postType: String,
val language: String
) {
companion object {
fun of(
admissions: AdmissionsEntity
) = AdmissionSearchResElem(
id = admissions.id,
name = admissions.name,
mainType = admissions.mainType.toJsonValue(),
postType = admissions.postType.toJsonValue(),
language = LanguageType.makeLowercase(admissions.language)
)
}
}
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.common.properties.LanguageType
import com.wafflestudio.csereal.common.utils.cleanTextFromHtml
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
Expand All @@ -20,7 +21,7 @@ import jakarta.persistence.UniqueConstraint
]
)
class AdmissionsEntity(
val name: String,
var name: String,

@Enumerated(EnumType.STRING)
val language: LanguageType,
Expand All @@ -32,7 +33,10 @@ class AdmissionsEntity(
val postType: AdmissionsPostType,

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

@Column(nullable = false, columnDefinition = "mediumText")
var searchContent: String
) : BaseTimeEntity() {
companion object {
fun of(
Expand All @@ -45,7 +49,14 @@ class AdmissionsEntity(
postType = postType,
name = name,
description = admissionsDto.description,
language = LanguageType.makeStringToLanguageType(admissionsDto.language)
language = LanguageType.makeStringToLanguageType(admissionsDto.language),
searchContent = createSearchContent(
name = name,
mainType = mainType,
postType = postType,
language = LanguageType.makeStringToLanguageType(admissionsDto.language),
description = admissionsDto.description
)
)

fun of(
Expand All @@ -57,7 +68,27 @@ class AdmissionsEntity(
postType = postType,
name = req.name!!,
description = req.description!!,
language = LanguageType.makeStringToLanguageType(req.language)
language = LanguageType.makeStringToLanguageType(req.language),
searchContent = createSearchContent(
name = req.name,
mainType = mainType,
postType = postType,
language = LanguageType.makeStringToLanguageType(req.language),
description = req.description
)
)

fun createSearchContent(
name: String,
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
language: LanguageType,
description: String
) = StringBuilder().apply {
appendLine(name)
appendLine(mainType.getLanguageValue(language))
appendLine(postType.getLanguageValue(language))
appendLine(cleanTextFromHtml(description))
}.toString()
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
package com.wafflestudio.csereal.core.admissions.database

import com.querydsl.jpa.impl.JPAQueryFactory
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.common.repository.CommonRepository
import com.wafflestudio.csereal.core.admissions.database.QAdmissionsEntity.admissionsEntity
import com.wafflestudio.csereal.core.admissions.type.AdmissionsMainType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

interface AdmissionsRepository : JpaRepository<AdmissionsEntity, Long> {
interface AdmissionsRepository : JpaRepository<AdmissionsEntity, Long>, AdmissionsCustomRepository {
fun findByMainTypeAndPostTypeAndLanguage(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
language: LanguageType
): AdmissionsEntity?
}

interface AdmissionsCustomRepository {
fun searchTopAdmissions(keyword: String, language: LanguageType, number: Int): List<AdmissionsEntity>
}

@Repository
class AdmissionsCustomRepositoryImpl(
private val commonRepository: CommonRepository,
private val queryFactory: JPAQueryFactory
) : AdmissionsCustomRepository {
override fun searchTopAdmissions(
keyword: String,
language: LanguageType,
number: Int
): List<AdmissionsEntity> =
searchQueryOfLanguage(keyword, language)
.limit(number.toLong())
.fetch()

fun searchQueryOfLanguage(keyword: String, language: LanguageType) =
queryFactory.selectFrom(
admissionsEntity
).where(
commonRepository.searchFullSingleTextTemplate(
keyword,
admissionsEntity.searchContent
).gt(0.0),
admissionsEntity.language.eq(language)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.wafflestudio.csereal.core.admissions.service

import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.common.properties.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.res.AdmissionSearchResElem
import com.wafflestudio.csereal.core.admissions.database.AdmissionsEntity
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import com.wafflestudio.csereal.core.admissions.database.AdmissionsRepository
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionMigrateElem
import com.wafflestudio.csereal.core.admissions.type.AdmissionsMainType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand All @@ -18,12 +19,17 @@ interface AdmissionsService {
mainType: AdmissionsMainType,
postType: AdmissionsPostType
): AdmissionsDto

fun readAdmission(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
language: LanguageType
): AdmissionsDto

fun migrateAdmissions(requestList: List<AdmissionMigrateElem>): List<AdmissionsDto>

@Transactional(readOnly = true)
fun searchTopAdmission(keyword: String, language: LanguageType, number: Int): List<AdmissionSearchResElem>
}

@Service
Expand Down Expand Up @@ -53,6 +59,12 @@ class AdmissionsServiceImpl(
)?.let { AdmissionsDto.of(it) }
?: throw CserealException.Csereal404("해당하는 페이지를 찾을 수 없습니다.")

@Transactional(readOnly = true)
override fun searchTopAdmission(keyword: String, language: LanguageType, number: Int) =
admissionsRepository.searchTopAdmissions(keyword, language, number).map {
AdmissionSearchResElem.of(it)
}

@Transactional
override fun migrateAdmissions(requestList: List<AdmissionMigrateElem>) = requestList.map {
val mainType = AdmissionsMainType.fromJsonValue(it.mainType)
Expand All @@ -63,7 +75,14 @@ class AdmissionsServiceImpl(
mainType = mainType,
postType = postType,
language = language,
description = it.description!!
description = it.description!!,
searchContent = AdmissionsEntity.createSearchContent(
name = it.name,
mainType = mainType,
postType = postType,
language = language,
description = it.description
)
)
}.let {
admissionsRepository.saveAll(it)
Expand Down
Loading

0 comments on commit 4c0ff20

Please sign in to comment.