diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/req/UpdateYearReq.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/req/UpdateYearReq.kt index 4756ab49..db9fb2c5 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/req/UpdateYearReq.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/req/UpdateYearReq.kt @@ -1,5 +1,6 @@ package com.wafflestudio.csereal.core.academics.api.req data class UpdateYearReq( - val description: String + val description: String, + val deleteIds: List? = null ) diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/v1/AcademicsController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/v1/AcademicsController.kt index e2614712..0666ffdb 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/v1/AcademicsController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/v1/AcademicsController.kt @@ -63,8 +63,9 @@ class AcademicsController( @RequestParam(required = false, defaultValue = "ko") language: String, @PathVariable studentType: String, @PathVariable postType: String, - @RequestBody request: CreateYearReq - ) = academicsService.createAcademicsYearResponse(language, studentType, postType, request) + @RequestPart request: CreateYearReq, + @RequestPart attachments: List? + ) = academicsService.createAcademicsYearResponse(language, studentType, postType, request, attachments) @AuthenticatedStaff @PutMapping("/{studentType}/{postType}/{year}") @@ -73,8 +74,9 @@ class AcademicsController( @PathVariable studentType: String, @PathVariable postType: String, @PathVariable year: Int, - @RequestBody request: UpdateYearReq - ) = academicsService.updateAcademicsYearResponse(language, studentType, postType, year, request) + @RequestPart request: UpdateYearReq, + @RequestPart newAttachments: List? + ) = academicsService.updateAcademicsYearResponse(language, studentType, postType, year, request, newAttachments) @AuthenticatedStaff @DeleteMapping("/{studentType}/{postType}/{year}") diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt index 58b7b57b..d4e3ef65 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt @@ -54,11 +54,18 @@ interface AcademicsService { studentType: String, postType: String, year: Int, - request: UpdateYearReq + request: UpdateYearReq, + newAttachments: List? ) fun deleteAcademicsYearResponse(language: String, studentType: String, postType: String, year: Int) - fun createAcademicsYearResponse(language: String, studentType: String, postType: String, request: CreateYearReq) + fun createAcademicsYearResponse( + language: String, + studentType: String, + postType: String, + request: CreateYearReq, + attachments: List? + ) } // TODO: add Update, Delete method @@ -124,7 +131,8 @@ class AcademicsServiceImpl( studentType: String, postType: String, year: Int, - request: UpdateYearReq + request: UpdateYearReq, + newAttachments: List? ) { val languageType = LanguageType.makeStringToLanguageType(language) val enumStudentType = makeStringToAcademicsStudentType(studentType) @@ -141,6 +149,12 @@ class AcademicsServiceImpl( academicsEntity.academicsSearch?.update(academicsEntity) ?: let { academicsEntity.academicsSearch = AcademicsSearchEntity.create(academicsEntity) } + + attachmentService.deleteAttachments(request.deleteIds) + + if (newAttachments != null) { + attachmentService.uploadAllAttachments(academicsEntity, newAttachments) + } } @Transactional @@ -156,6 +170,7 @@ class AcademicsServiceImpl( year ) ?: throw CserealException.Csereal404("AcademicsEntity Not Found") + attachmentService.deleteAttachments(academicsEntity.attachments.map { it.id }) academicsRepository.delete(academicsEntity) } @@ -164,7 +179,8 @@ class AcademicsServiceImpl( language: String, studentType: String, postType: String, - request: CreateYearReq + request: CreateYearReq, + attachments: List? ) { val languageType = LanguageType.makeStringToLanguageType(language) val enumStudentType = makeStringToAcademicsStudentType(studentType) @@ -186,6 +202,10 @@ class AcademicsServiceImpl( academicsSearch = AcademicsSearchEntity.create(this) } + if (attachments != null) { + attachmentService.uploadAllAttachments(newAcademics, attachments) + } + academicsRepository.save(newAcademics) }