From 3a7460bfb69faa288872e54f4a3d193087217c1b Mon Sep 17 00:00:00 2001 From: Junhyeong Kim Date: Thu, 28 Nov 2024 01:45:12 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=99=EC=82=AC=20=EB=B0=8F=20=EA=B5=90?= =?UTF-8?q?=EA=B3=BC=20=EC=97=B0=EB=8F=84=EB=B3=84=20api=EC=97=90=20?= =?UTF-8?q?=EC=B2=A8=EB=B6=80=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80=20(#3?= =?UTF-8?q?29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 학사 및 교과 연도별 api에 첨부파일 추가 * 오타 수정 --- .../core/academics/api/req/UpdateYearReq.kt | 3 +- .../academics/api/v1/AcademicsController.kt | 10 ++++--- .../academics/service/AcademicsService.kt | 28 ++++++++++++++++--- 3 files changed, 32 insertions(+), 9 deletions(-) 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) }