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: migrateAbout, migrateFutureCareers 추가 #118

Merged
merged 6 commits into from
Sep 16, 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
@@ -1,9 +1,9 @@
package com.wafflestudio.csereal.core.about.api

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.core.about.dto.AboutDto
import com.wafflestudio.csereal.core.about.dto.CompanyDto
import com.wafflestudio.csereal.core.about.dto.FutureCareersPage
import com.wafflestudio.csereal.core.about.dto.*
import com.wafflestudio.csereal.core.about.dto.request.AboutRequest
import com.wafflestudio.csereal.core.about.dto.request.FutureCareersRequest
import com.wafflestudio.csereal.core.about.service.AboutService
import jakarta.validation.Valid
import org.springframework.http.ResponseEntity
Expand Down Expand Up @@ -59,4 +59,17 @@ class AboutController(
return ResponseEntity.ok(aboutService.readFutureCareers())
}

@PostMapping("/migrate")
fun migrateAbout(
@RequestBody requestList: List<AboutRequest>
): ResponseEntity<List<AboutDto>> {
return ResponseEntity.ok(aboutService.migrateAbout(requestList))
}

@PostMapping("/future-careers/migrate")
fun migrateFutureCareers(
@RequestBody request: FutureCareersRequest
): ResponseEntity<FutureCareersResponse> {
return ResponseEntity.ok(aboutService.migrateFutureCareers(request))
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package com.wafflestudio.csereal.core.about.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.core.about.dto.FutureCareersCompanyDto
import jakarta.persistence.Entity

@Entity(name = "company")
class CompanyEntity(
var name: String,
var url: String,
var year: Int,
var url: String?,
var year: Int?,
) : BaseTimeEntity() {
companion object {
fun of(companyDto: FutureCareersCompanyDto): CompanyEntity {
return CompanyEntity(
name = companyDto.name,
url = companyDto.url,
year = companyDto.year,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wafflestudio.csereal.core.about.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.core.about.dto.FutureCareersStatDegreeDto
import com.wafflestudio.csereal.core.about.dto.FutureCareersStatDto
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
Expand All @@ -14,6 +16,16 @@ class StatEntity(
var name: String,
var count: Int,
): BaseTimeEntity() {
companion object {
fun of(year: Int, degree: Degree, statDto: FutureCareersStatDegreeDto): StatEntity {
return StatEntity(
year = year,
degree = degree,
name = statDto.name,
count = statDto.count,
)
}
}
}

enum class Degree {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.wafflestudio.csereal.core.about.dto


import com.fasterxml.jackson.annotation.JsonInclude
import com.wafflestudio.csereal.core.about.database.AboutEntity
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse
import java.time.LocalDateTime

data class AboutDto(
val id: Long,
@JsonInclude(JsonInclude.Include.NON_NULL)
val id: Long? = null,
val name: String?,
val engName: String?,
val description: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.wafflestudio.csereal.core.about.dto

data class CompanyDto(
val name: String,
val url: String,
val year: Int,
val url: String?,
val year: Int?,
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wafflestudio.csereal.core.about.dto

data class FutureCareersCompanyDto(
val name: String,
val url: String?,
val year: Int?
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wafflestudio.csereal.core.about.dto

data class FutureCareersResponse(
val description: String,
val stat: List<FutureCareersStatDto>,
val companies: List<FutureCareersCompanyDto>
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.csereal.core.about.dto

data class FutureCareersStatDegreeDto(
val name: String,
val count: Int,
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wafflestudio.csereal.core.about.dto

data class FutureCareersStatDto(
val year: Int,
val bachelor: List<FutureCareersStatDegreeDto>,
val master: List<FutureCareersStatDegreeDto>,
val doctor: List<FutureCareersStatDegreeDto>
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wafflestudio.csereal.core.about.dto.request

import java.time.LocalDateTime

data class AboutRequest(
val postType: String,
val description: String,
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wafflestudio.csereal.core.about.dto.request

import com.wafflestudio.csereal.core.about.dto.FutureCareersCompanyDto
import com.wafflestudio.csereal.core.about.dto.FutureCareersStatDto

data class FutureCareersRequest(
val description: String,
val stat: List<FutureCareersStatDto>,
val companies: List<FutureCareersCompanyDto>
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ package com.wafflestudio.csereal.core.about.service
import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.core.about.database.*
import com.wafflestudio.csereal.core.about.dto.*
import com.wafflestudio.csereal.core.about.dto.request.AboutRequest
import com.wafflestudio.csereal.core.about.dto.request.FutureCareersRequest
import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService
import com.wafflestudio.csereal.core.resource.mainImage.service.MainImageService
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

interface AboutService {
fun createAbout(postType: String, request: AboutDto, mainImage: MultipartFile?, attachments: List<MultipartFile>?): AboutDto
fun createAbout(
postType: String,
request: AboutDto,
mainImage: MultipartFile?,
attachments: List<MultipartFile>?
): AboutDto

fun readAbout(postType: String): AboutDto
fun readAllClubs() : List<AboutDto>
fun readAllFacilities() : List<AboutDto>
fun readAllClubs(): List<AboutDto>
fun readAllFacilities(): List<AboutDto>
fun readAllDirections(): List<AboutDto>
fun readFutureCareers(): FutureCareersPage
fun migrateAbout(requestList: List<AboutRequest>): List<AboutDto>
fun migrateFutureCareers(request: FutureCareersRequest): FutureCareersResponse

}

Expand All @@ -28,21 +38,26 @@ class AboutServiceImpl(
private val attachmentService: AttachmentService,
) : AboutService {
@Transactional
override fun createAbout(postType: String, request: AboutDto, mainImage: MultipartFile?, attachments: List<MultipartFile>?): AboutDto {
override fun createAbout(
postType: String,
request: AboutDto,
mainImage: MultipartFile?,
attachments: List<MultipartFile>?
): AboutDto {
val enumPostType = makeStringToEnum(postType)
val newAbout = AboutEntity.of(enumPostType, request)

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

if(mainImage != null) {
if (mainImage != null) {
mainImageService.uploadMainImage(newAbout, mainImage)
}

if(attachments != null) {
if (attachments != null) {
attachmentService.uploadAllAttachments(newAbout, attachments)
}
aboutRepository.save(newAbout)
Expand Down Expand Up @@ -111,7 +126,7 @@ class AboutServiceImpl(
"그 이후로는 국내외 관련 산업계, 학계에 주로 진출하고 있고, 새로운 아이디어로 벤처기업을 창업하기도 한다."

val statList = mutableListOf<StatDto>()
for(i: Int in 2021 downTo 2011) {
for (i: Int in 2021 downTo 2011) {
val bachelor = statRepository.findAllByYearAndDegree(i, Degree.BACHELOR).map {
CompanyNameAndCountDto(
id = it.id,
Expand Down Expand Up @@ -152,9 +167,96 @@ class AboutServiceImpl(
return FutureCareersPage(description, statList, companyList)
}

private fun makeStringToEnum(postType: String) : AboutPostType {
@Transactional
override fun migrateAbout(requestList: List<AboutRequest>): List<AboutDto> {
val list = mutableListOf<AboutDto>()

for (request in requestList) {
val enumPostType = makeStringToEnum(request.postType)

val aboutDto = AboutDto(
id = null,
name = null,
engName = null,
description = request.description,
year = null,
createdAt = null,
modifiedAt = null,
locations = null,
imageURL = null,
attachments = listOf()
)
val newAbout = AboutEntity.of(enumPostType, aboutDto)

aboutRepository.save(newAbout)

list.add(AboutDto.of(newAbout, null, listOf()))

}
return list
}

@Transactional
override fun migrateFutureCareers(request: FutureCareersRequest): FutureCareersResponse {
val description = request.description
val statList = mutableListOf<FutureCareersStatDto>()
val companyList = mutableListOf<FutureCareersCompanyDto>()

val aboutDto = AboutDto(
id = null,
name = null,
engName = null,
description = description,
year = null,
createdAt = null,
modifiedAt = null,
locations = null,
imageURL = null,
attachments = listOf()
)
val newAbout = AboutEntity.of(AboutPostType.FUTURE_CAREERS, aboutDto)
aboutRepository.save(newAbout)

for (stat in request.stat) {
val year = stat.year
val bachelorList = mutableListOf<FutureCareersStatDegreeDto>()
val masterList = mutableListOf<FutureCareersStatDegreeDto>()
val doctorList = mutableListOf<FutureCareersStatDegreeDto>()

for (bachelor in stat.bachelor) {
val newBachelor = StatEntity.of(year, Degree.BACHELOR, bachelor)
statRepository.save(newBachelor)

bachelorList.add(bachelor)
}
for (master in stat.master) {
val newMaster = StatEntity.of(year, Degree.MASTER, master)
statRepository.save(newMaster)

masterList.add(master)
}
for (doctor in stat.doctor) {
val newDoctor = StatEntity.of(year, Degree.DOCTOR, doctor)
statRepository.save(newDoctor)

doctorList.add(doctor)
}
}

for (company in request.companies) {
val newCompany = CompanyEntity.of(company)
companyRepository.save(newCompany)

companyList.add(company)
}


return FutureCareersResponse(description, statList.toList(), companyList.toList())
}

private fun makeStringToEnum(postType: String): AboutPostType {
try {
val upperPostType = postType.replace("-","_").uppercase()
val upperPostType = postType.replace("-", "_").uppercase()
return AboutPostType.valueOf(upperPostType)

} catch (e: IllegalArgumentException) {
Expand Down