diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/about/api/AboutController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/about/api/AboutController.kt index 87468574..61043e39 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/about/api/AboutController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/about/api/AboutController.kt @@ -102,4 +102,15 @@ class AboutController( ): ResponseEntity> { return ResponseEntity.ok(aboutService.migrateDirections(requestList)) } + + @PatchMapping("/migrateImage/{aboutId}") + fun migrateAboutImageAndAttachment( + @PathVariable aboutId: Long, + @RequestPart("mainImage") mainImage: MultipartFile?, + @RequestPart("attachments") attachments: List? + ): ResponseEntity { + return ResponseEntity.ok( + aboutService.migrateAboutImageAndAttachments(aboutId, mainImage, attachments) + ) + } } diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/about/service/AboutService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/about/service/AboutService.kt index cfc3acb6..c63b6c3a 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/about/service/AboutService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/about/service/AboutService.kt @@ -6,6 +6,7 @@ import com.wafflestudio.csereal.core.about.database.* import com.wafflestudio.csereal.core.about.dto.* import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService import com.wafflestudio.csereal.core.resource.mainImage.service.MainImageService +import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import org.springframework.web.multipart.MultipartFile @@ -28,6 +29,11 @@ interface AboutService { fun migrateStudentClubs(requestList: List): List fun migrateFacilities(requestList: List): List fun migrateDirections(requestList: List): List + fun migrateAboutImageAndAttachments( + aboutId: Long, + mainImage: MultipartFile?, + attachments: List? + ): AboutDto } @Service @@ -329,6 +335,25 @@ class AboutServiceImpl( return list } + @Transactional + override fun migrateAboutImageAndAttachments( + aboutId: Long, + mainImage: MultipartFile?, + attachments: List? + ): AboutDto { + val about = aboutRepository.findByIdOrNull(aboutId) + ?: throw CserealException.Csereal404("해당 소개는 존재하지 않습니다.") + + if (mainImage != null) { + mainImageService.uploadMainImage(about, mainImage) + } + + val imageURL = mainImageService.createImageURL(about.mainImage) + val attachmentResponses = attachmentService.createAttachmentResponses(about.attachments) + + return AboutDto.of(about, imageURL, attachmentResponses) + } + private fun makeStringToEnum(postType: String): AboutPostType { try { val upperPostType = postType.replace("-", "_").uppercase()