From 40254bfd584b942e13d4dea7969a9631b85080c1 Mon Sep 17 00:00:00 2001 From: Denis Kazantsev <51866756+denis14082000@users.noreply.github.com> Date: Sun, 23 Jan 2022 23:20:50 +0300 Subject: [PATCH] Added dependency, exception (#63) --- s3-storage/build.gradle.kts | 2 ++ .../s3/storage/exceptions/FileLocationNotFoundException.kt | 6 ++++++ .../touchin/s3/storage/services/S3FileStorageServiceImpl.kt | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 s3-storage/src/main/kotlin/ru/touchin/s3/storage/exceptions/FileLocationNotFoundException.kt diff --git a/s3-storage/build.gradle.kts b/s3-storage/build.gradle.kts index 07e0aa7..e99149d 100644 --- a/s3-storage/build.gradle.kts +++ b/s3-storage/build.gradle.kts @@ -5,6 +5,8 @@ plugins { } dependencies { + api(project(":common")) + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.springframework.boot:spring-boot") diff --git a/s3-storage/src/main/kotlin/ru/touchin/s3/storage/exceptions/FileLocationNotFoundException.kt b/s3-storage/src/main/kotlin/ru/touchin/s3/storage/exceptions/FileLocationNotFoundException.kt new file mode 100644 index 0000000..90bd7b4 --- /dev/null +++ b/s3-storage/src/main/kotlin/ru/touchin/s3/storage/exceptions/FileLocationNotFoundException.kt @@ -0,0 +1,6 @@ +package ru.touchin.s3.storage.exceptions + +import ru.touchin.common.exceptions.CommonNotFoundException +import java.util.* + +class FileLocationNotFoundException(id: String) : CommonNotFoundException("File location not found id=$id") diff --git a/s3-storage/src/main/kotlin/ru/touchin/s3/storage/services/S3FileStorageServiceImpl.kt b/s3-storage/src/main/kotlin/ru/touchin/s3/storage/services/S3FileStorageServiceImpl.kt index 26da731..2992fcc 100644 --- a/s3-storage/src/main/kotlin/ru/touchin/s3/storage/services/S3FileStorageServiceImpl.kt +++ b/s3-storage/src/main/kotlin/ru/touchin/s3/storage/services/S3FileStorageServiceImpl.kt @@ -1,6 +1,7 @@ package ru.touchin.s3.storage.services import org.springframework.stereotype.Service +import ru.touchin.s3.storage.exceptions.FileLocationNotFoundException import ru.touchin.s3.storage.properties.S3Properties import ru.touchin.s3.storage.services.dto.DeleteData import ru.touchin.s3.storage.services.dto.GetUrl @@ -16,6 +17,7 @@ import software.amazon.awssdk.services.s3.presigner.S3Presigner import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest import java.net.URL +import java.util.* @Service class S3FileStorageServiceImpl( @@ -50,7 +52,7 @@ class S3FileStorageServiceImpl( s3Client.deleteObject(deleteObjectRequest) } - override fun getUrl(getUrl: GetUrl): URL? { + override fun getUrl(getUrl: GetUrl): URL { val getObjectRequest = GetObjectRequest.builder() .bucket(s3Properties.bucket) .key(keyOf(getUrl.id)) @@ -66,6 +68,7 @@ class S3FileStorageServiceImpl( .takeIf(PresignedGetObjectRequest::isBrowserExecutable) return presignedGetObjectRequest?.url() + ?: throw FileLocationNotFoundException(getUrl.id) } fun keyOf(fileId: String) = folder + fileId