From ca4ea0e5ea3b7bebc75abbdec6aba6ac2223a1ea Mon Sep 17 00:00:00 2001
From: Klaus <klaus@vividnext.co.kr>
Date: Thu, 1 Aug 2024 22:03:41 +0900
Subject: [PATCH] =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0?=
 =?UTF-8?q?=20=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20-=20=EC=98=A4?=
 =?UTF-8?q?=EB=94=94=EC=98=A4=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20?=
 =?UTF-8?q?=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../creatorCommunity/CreatorCommunity.kt      |  2 ++
 .../CreatorCommunityController.kt             |  4 +++
 .../CreatorCommunityService.kt                | 25 ++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunity.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunity.kt
index 68143c7..7143dc2 100644
--- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunity.kt
+++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunity.kt
@@ -17,6 +17,8 @@ data class CreatorCommunity(
     var isCommentAvailable: Boolean,
     var isAdult: Boolean,
     @Column(nullable = true)
+    var audioPath: String? = null,
+    @Column(nullable = true)
     var imagePath: String? = null,
     var isActive: Boolean = true
 ) : BaseEntity() {
diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt
index 0307940..7c72840 100644
--- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt
+++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt
@@ -27,6 +27,9 @@ class CreatorCommunityController(private val service: CreatorCommunityService) {
     @PostMapping
     @PreAuthorize("hasRole('CREATOR')")
     fun createCommunityPost(
+        @Nullable
+        @RequestPart("contentFile")
+        audioFile: MultipartFile?,
         @Nullable
         @RequestPart("postImage")
         postImage: MultipartFile?,
@@ -37,6 +40,7 @@ class CreatorCommunityController(private val service: CreatorCommunityService) {
 
         ApiResponse.ok(
             service.createCommunityPost(
+                audioFile = audioFile,
                 postImage = postImage,
                 requestString = requestString,
                 member = member
diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt
index cf429c1..da14f5a 100644
--- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt
+++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt
@@ -50,13 +50,22 @@ class CreatorCommunityService(
     private val imageHost: String
 ) {
     @Transactional
-    fun createCommunityPost(postImage: MultipartFile?, requestString: String, member: Member) {
+    fun createCommunityPost(
+        audioFile: MultipartFile?,
+        postImage: MultipartFile?,
+        requestString: String,
+        member: Member
+    ) {
         val request = objectMapper.readValue(requestString, CreateCommunityPostRequest::class.java)
 
         if (request.price > 0 && postImage == null) {
             throw SodaException("유료 게시글 등록을 위해서는 이미지가 필요합니다.")
         }
 
+        if (audioFile != null && postImage == null) {
+            throw SodaException("오디오 등록을 위해서는 이미지가 필요합니다.")
+        }
+
         val post = CreatorCommunity(
             content = request.content,
             price = request.price,
@@ -84,6 +93,20 @@ class CreatorCommunityService(
             post.imagePath = imagePath
         }
 
+        if (audioFile != null) {
+            val metadata = ObjectMetadata()
+            metadata.contentLength = audioFile.size
+
+            val audioPath = s3Uploader.upload(
+                inputStream = audioFile.inputStream,
+                bucket = imageBucket,
+                filePath = "creator_community/${post.id}/${generateFileName(prefix = "${post.id}-audio")}.m4a",
+                metadata = metadata
+            )
+
+            post.audioPath = audioPath
+        }
+
         applicationEventPublisher.publishEvent(
             FcmEvent(
                 type = FcmEventType.CHANGE_NOTICE,