From 97cf5eac65c7b067c39e953ccd2ada7608dc9603 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:20:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=89=8A=E9=99=A4=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/service/media/MediaDataStore.kt | 2 +- .../usbharu/hideout/service/media/S3MediaDataStore.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/media/MediaDataStore.kt b/src/main/kotlin/dev/usbharu/hideout/service/media/MediaDataStore.kt index dd21b519..bd03f704 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/MediaDataStore.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/MediaDataStore.kt @@ -5,5 +5,5 @@ import dev.usbharu.hideout.domain.model.hideout.dto.SavedMedia interface MediaDataStore { suspend fun save(dataMediaSave: MediaSave): SavedMedia - suspend fun delete(id: Long) + suspend fun delete(id: String) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt b/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt index cc7d459f..91e4bcff 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.withContext import org.springframework.stereotype.Service import software.amazon.awssdk.core.sync.RequestBody import software.amazon.awssdk.services.s3.S3Client +import software.amazon.awssdk.services.s3.model.DeleteObjectRequest import software.amazon.awssdk.services.s3.model.GetUrlRequest import software.amazon.awssdk.services.s3.model.PutObjectRequest @@ -53,7 +54,11 @@ class S3MediaDataStore(private val s3Client: S3Client, private val storageConfig ) } - override suspend fun delete(id: Long) { - TODO("Not yet implemented") + override suspend fun delete(id: String) { + val fileDeleteRequest = DeleteObjectRequest.builder().bucket(storageConfig.bucket).key(id).build() + val thumbnailDeleteRequest = + DeleteObjectRequest.builder().bucket(storageConfig.bucket).key("thumbnail-$id").build() + s3Client.deleteObject(fileDeleteRequest) + s3Client.deleteObject(thumbnailDeleteRequest) } }