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: academics 패키지 마이그레이션 추가 #195

Merged
merged 16 commits into from
Mar 1, 2024
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 @@ -100,6 +100,48 @@ class AcademicsController(
return ResponseEntity.ok(academicsService.readScholarship(scholarshipId))
}

@PostMapping("/{studentType}/{postType}/migrate")
fun migrateAcademicsDetail(
@PathVariable studentType: String,
@PathVariable postType: String,
@RequestBody requestList: List<AcademicsDto>
): ResponseEntity<List<AcademicsDto>> {
return ResponseEntity.ok(
academicsService.migrateAcademicsDetail(studentType, postType, requestList)
)
}

@PostMapping("/course/migrate/{studentType}")
fun migrateCourses(
@PathVariable studentType: String,
@RequestBody requestList: List<CourseDto>
): ResponseEntity<List<CourseDto>> {
return ResponseEntity.ok(academicsService.migrateCourses(studentType, requestList))
}

@PostMapping("/{studentType}/scholarshipDetail/migrate")
fun migrateScholarshipDetail(
@PathVariable studentType: String,
@RequestBody requestList: List<ScholarshipDto>
): ResponseEntity<List<ScholarshipDto>> {
return ResponseEntity.ok(
academicsService.migrateScholarshipDetail(studentType, requestList)
)
}

@PatchMapping("/migrateAttachment/{academicsId}")
fun migrateAcademicsDetailAttachments(
@PathVariable academicsId: Long,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<AcademicsDto> {
return ResponseEntity.ok(
academicsService.migrateAcademicsDetailAttachments(
academicsId,
attachments
)
)
}

@GetMapping("/search/top")
fun searchTop(
@RequestParam(required = true) keyword: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class AcademicsEntity(
var language: LanguageType,

var name: String,

@Column(columnDefinition = "mediumText")
var description: String,
var year: Int?,
var time: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CourseEntity(
var name: String,
var credit: Int,
var grade: String,

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

@OneToMany(mappedBy = "course", cascade = [CascadeType.ALL], orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wafflestudio.csereal.core.academics.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.academics.dto.ScholarshipDto
import jakarta.persistence.*

Expand All @@ -9,6 +10,9 @@ class ScholarshipEntity(
@Enumerated(EnumType.STRING)
var studentType: AcademicsStudentType,

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

val name: String,

@Column(columnDefinition = "text")
Expand All @@ -20,8 +24,13 @@ class ScholarshipEntity(
) : BaseTimeEntity() {

companion object {
fun of(studentType: AcademicsStudentType, scholarshipDto: ScholarshipDto): ScholarshipEntity {
fun of(
languageType: LanguageType,
studentType: AcademicsStudentType,
scholarshipDto: ScholarshipDto
): ScholarshipEntity {
return ScholarshipEntity(
language = languageType,
studentType = studentType,
name = scholarshipDto.name,
description = scholarshipDto.description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.wafflestudio.csereal.core.academics.dto

import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.academics.database.ScholarshipEntity

data class ScholarshipDto(
val id: Long,
val language: String,
val name: String,
val description: String
) {
companion object {
fun of(scholarshipEntity: ScholarshipEntity): ScholarshipDto {
return ScholarshipDto(
id = scholarshipEntity.id,
language = LanguageType.makeLowercase(scholarshipEntity.language),
name = scholarshipEntity.name,
description = scholarshipEntity.description
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ interface AcademicsService {
fun createScholarshipDetail(studentType: String, request: ScholarshipDto): ScholarshipDto
fun readAllScholarship(studentType: String): ScholarshipPageResponse
fun readScholarship(scholarshipId: Long): ScholarshipDto
fun migrateAcademicsDetail(
studentType: String,
postType: String,
requestList: List<AcademicsDto>
): List<AcademicsDto>
fun migrateCourses(studentType: String, requestList: List<CourseDto>): List<CourseDto>
fun migrateScholarshipDetail(
studentType: String,
requestList: List<ScholarshipDto>
): List<ScholarshipDto>
fun migrateAcademicsDetailAttachments(
academicsId: Long,
attachments: List<MultipartFile>?
): AcademicsDto
}

// TODO: add Update, Delete method
Expand Down Expand Up @@ -156,8 +170,9 @@ class AcademicsServiceImpl(

@Transactional
override fun createScholarshipDetail(studentType: String, request: ScholarshipDto): ScholarshipDto {
val enumLanguageType = LanguageType.makeStringToLanguageType(request.language)
val enumStudentType = makeStringToAcademicsStudentType(studentType)
var newScholarship = ScholarshipEntity.of(enumStudentType, request)
var newScholarship = ScholarshipEntity.of(enumLanguageType, enumStudentType, request)

// create search data
newScholarship.apply {
Expand Down Expand Up @@ -189,6 +204,101 @@ class AcademicsServiceImpl(
return ScholarshipDto.of(scholarship)
}

@Transactional
override fun migrateAcademicsDetail(
studentType: String,
postType: String,
requestList: List<AcademicsDto>
): List<AcademicsDto> {
val enumStudentType = makeStringToAcademicsStudentType(studentType)
val enumPostType = makeStringToAcademicsPostType(postType)
val list = mutableListOf<AcademicsDto>()
for (request in requestList) {
val enumLanguageType = LanguageType.makeStringToLanguageType(request.language)
val newAcademics = AcademicsEntity.of(
enumStudentType,
enumPostType,
enumLanguageType,
request
)

newAcademics.apply {
academicsSearch = AcademicsSearchEntity.create(this)
}

academicsRepository.save(newAcademics)

list.add(AcademicsDto.of(newAcademics, listOf()))
}

return list
}

@Transactional
override fun migrateCourses(studentType: String, requestList: List<CourseDto>): List<CourseDto> {
val enumStudentType = makeStringToAcademicsStudentType(studentType)
val list = mutableListOf<CourseDto>()
for (request in requestList) {
val enumLanguageType = LanguageType.makeStringToLanguageType(request.language)
val newCourse = CourseEntity.of(enumStudentType, enumLanguageType, request)

newCourse.apply {
academicsSearch = AcademicsSearchEntity.create(this)
}
courseRepository.save(newCourse)

list.add(CourseDto.of(newCourse, listOf()))
}

return list
}

@Transactional
override fun migrateScholarshipDetail(
studentType: String,
requestList: List<ScholarshipDto>
): List<ScholarshipDto> {
val enumStudentType = makeStringToAcademicsStudentType(studentType)
val list = mutableListOf<ScholarshipDto>()
for (request in requestList) {
val enumLanguageType = LanguageType.makeStringToLanguageType(request.language)
val newScholarship = ScholarshipEntity.of(
enumLanguageType,
enumStudentType,
request
)

newScholarship.apply {
academicsSearch = AcademicsSearchEntity.create(this)
}

scholarshipRepository.save(newScholarship)

list.add(ScholarshipDto.of(newScholarship))
}

return list
}

@Transactional
override fun migrateAcademicsDetailAttachments(
academicsId: Long,
attachments: List<MultipartFile>?
): AcademicsDto {
val academics = academicsRepository.findByIdOrNull(academicsId)
?: throw CserealException.Csereal404("해당 내용을 찾을 수 없습니다.")

if (attachments != null) {
attachmentService.uploadAllAttachments(academics, attachments)
}

val attachmentResponses = attachmentService.createAttachmentResponses(
academics.attachments
)

return AcademicsDto.of(academics, attachmentResponses)
}

private fun makeStringToAcademicsStudentType(postType: String): AcademicsStudentType {
try {
val upperPostType = postType.replace("-", "_").uppercase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.wafflestudio.csereal.core.conference.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.conference.dto.ConferenceDto
import com.wafflestudio.csereal.core.research.database.ResearchSearchEntity
import jakarta.persistence.*

@Entity(name = "conference")
class ConferenceEntity(
@Enumerated(EnumType.STRING)
var language: LanguageType,

var isDeleted: Boolean = false,
var code: String,
var abbreviation: String,
Expand All @@ -21,9 +25,11 @@ class ConferenceEntity(
) : BaseTimeEntity() {
companion object {
fun of(
languageType: LanguageType,
conferenceDto: ConferenceDto,
conferencePage: ConferencePageEntity
) = ConferenceEntity(
language = languageType,
code = conferenceDto.code,
abbreviation = conferenceDto.abbreviation,
name = conferenceDto.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.wafflestudio.csereal.core.conference.dto

import com.fasterxml.jackson.annotation.JsonInclude
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.conference.database.ConferenceEntity

data class ConferenceDto(
@JsonInclude(JsonInclude.Include.NON_NULL)
val id: Long? = null,
val language: String,
val code: String,
val abbreviation: String,
val name: String
Expand All @@ -14,6 +16,7 @@ data class ConferenceDto(
fun of(conferenceEntity: ConferenceEntity): ConferenceDto {
return ConferenceDto(
id = conferenceEntity.id,
language = LanguageType.makeLowercase(conferenceEntity.language),
code = conferenceEntity.code,
abbreviation = conferenceEntity.abbreviation,
name = conferenceEntity.name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wafflestudio.csereal.core.conference.service

import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.conference.database.ConferenceEntity
import com.wafflestudio.csereal.core.conference.database.ConferencePageEntity
import com.wafflestudio.csereal.core.conference.database.ConferencePageRepository
Expand Down Expand Up @@ -40,7 +41,9 @@ class ConferenceServiceImpl(
}

@Transactional
override fun modifyConferences(conferenceModifyRequest: ConferenceModifyRequest): ConferencePage {
override fun modifyConferences(
conferenceModifyRequest: ConferenceModifyRequest
): ConferencePage {
val user = RequestContextHolder.getRequestAttributes()?.getAttribute(
"loggedInUser",
RequestAttributes.SCOPE_REQUEST
Expand Down Expand Up @@ -76,7 +79,8 @@ class ConferenceServiceImpl(
val conferencePage = ConferencePageEntity.of(user)
conferencePageRepository.save(conferencePage)
for (request in requestList) {
val conference = ConferenceEntity.of(request, conferencePage)
val enumLanguageType = LanguageType.makeStringToLanguageType(request.language)
val conference = ConferenceEntity.of(enumLanguageType, request, conferencePage)

conferenceRepository.save(conference)

Expand All @@ -94,7 +98,9 @@ class ConferenceServiceImpl(
conferenceDto: ConferenceDto,
conferencePage: ConferencePageEntity
): ConferenceEntity {
val enumLanguageType = LanguageType.makeStringToLanguageType(conferenceDto.language)
val newConference = ConferenceEntity.of(
enumLanguageType,
conferenceDto,
conferencePage
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wafflestudio.csereal.core.conference.service

import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.conference.database.ConferenceEntity
import com.wafflestudio.csereal.core.conference.database.ConferencePageEntity
import com.wafflestudio.csereal.core.conference.database.ConferencePageRepository
Expand Down Expand Up @@ -76,18 +77,21 @@ class ConferenceServiceTest(
val conferences = conferenceRepository.saveAll(
listOf(
ConferenceEntity(
language = LanguageType.KO,
code = "code1",
name = "name1",
abbreviation = "abbreviation1",
conferencePage = conferencePage
),
ConferenceEntity(
language = LanguageType.KO,
code = "code2",
name = "name2",
abbreviation = "abbreviation2",
conferencePage = conferencePage
),
ConferenceEntity(
language = LanguageType.KO,
code = "code3",
name = "name3",
abbreviation = "abbreviation3",
Expand All @@ -105,11 +109,13 @@ class ConferenceServiceTest(
val deleteConferenceId = conferences[1].id
val modifiedConference = ConferenceDto(
id = conferences.first().id,
language = "ko",
code = "code0",
name = "modifiedName",
abbreviation = "modifiedAbbreviation"
)
val newConference = ConferenceDto(
language = "ko",
code = "code9",
name = "newName",
abbreviation = "newAbbreviation"
Expand Down
Loading