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) } }