From 66415761c0e0c35672f02484b7d2052bb0dca155 Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Nakazone Batista Date: Sun, 26 May 2024 02:23:19 -0300 Subject: [PATCH] Fixes StorageService Implementation --- .../microservice/StorageServiceDownloadResponse.java | 4 ++-- .../microservice/StorageServiceUploadResponse.java | 8 ++++---- .../hideyoshi/auth/security/service/AuthService.java | 4 +--- .../auth/service/microservice/StorageService.java | 10 +++++----- .../auth/service/microservice/StorageServiceTest.java | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceDownloadResponse.java b/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceDownloadResponse.java index bdf4bec..146d48d 100644 --- a/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceDownloadResponse.java +++ b/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceDownloadResponse.java @@ -11,7 +11,7 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class StorageServiceDownloadResponse { - @JsonProperty("presigned_url") - private String presignedUrl; + @JsonProperty("signed_url") + private String signedUrl; } diff --git a/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceUploadResponse.java b/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceUploadResponse.java index 635af07..7435443 100644 --- a/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceUploadResponse.java +++ b/src/main/java/br/com/hideyoshi/auth/model/microservice/StorageServiceUploadResponse.java @@ -11,10 +11,10 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class StorageServiceUploadResponse { - @JsonProperty("presigned_url") - private String presignedUrl; + @JsonProperty("signed_url") + private String signedUrl; - @JsonProperty("file_key") - private String fileKey; + @JsonProperty("expires_in") + private String expiresIn; } diff --git a/src/main/java/br/com/hideyoshi/auth/security/service/AuthService.java b/src/main/java/br/com/hideyoshi/auth/security/service/AuthService.java index 5380eba..74a961a 100644 --- a/src/main/java/br/com/hideyoshi/auth/security/service/AuthService.java +++ b/src/main/java/br/com/hideyoshi/auth/security/service/AuthService.java @@ -39,8 +39,6 @@ import static java.util.Arrays.stream; @Service @RequiredArgsConstructor public class AuthService { - private static final String AUTHORIZATION_TYPE_STRING = "Bearer "; - private final UserService userService; private final StorageService storageService; @@ -166,7 +164,7 @@ public class AuthService { private String extractProfilePictureUrl(UserDTO user) { return this.storageService.getFileUrl(user.getUsername(), "profile") - .map(StorageServiceDownloadResponse::getPresignedUrl) + .map(StorageServiceDownloadResponse::getSignedUrl) .orElse(null); } diff --git a/src/main/java/br/com/hideyoshi/auth/service/microservice/StorageService.java b/src/main/java/br/com/hideyoshi/auth/service/microservice/StorageService.java index fe1d98a..132cc18 100644 --- a/src/main/java/br/com/hideyoshi/auth/service/microservice/StorageService.java +++ b/src/main/java/br/com/hideyoshi/auth/service/microservice/StorageService.java @@ -35,7 +35,7 @@ public class StorageService { private final StorageServiceConfig storageServiceConfig; - private final String PARAMETER_USERNAME = "username"; + private final String PARAMETER_FILE_KEY = "file_key"; private final String PARAMETER_FILE_POSTFIX = "file_postfix"; @@ -43,7 +43,7 @@ public class StorageService { public Optional getNewFileUrl(String username, String filePostfix, FileTypeEnum fileTypeEnum) { HashMap values = new HashMap<>() {{ - put(PARAMETER_USERNAME, username); + put(PARAMETER_FILE_KEY, username); put(PARAMETER_FILE_POSTFIX, filePostfix); put(PARAMETER_FILE_TYPE, fileTypeEnum.getFileExtension()); }}; @@ -66,7 +66,7 @@ public class StorageService { URI uri; try { uri = new URIBuilder(storageServiceConfig.getFileServicePath() + "/file") - .addParameter(PARAMETER_USERNAME, username) + .addParameter(PARAMETER_FILE_KEY, username) .addParameter(PARAMETER_FILE_POSTFIX, filePostfix) .build(); } catch (URISyntaxException e) { @@ -90,7 +90,7 @@ public class StorageService { URI uri = null; try { uri = new URIBuilder(storageServiceConfig.getFileServicePath() + "/file") - .addParameter(PARAMETER_USERNAME, username) + .addParameter(PARAMETER_FILE_KEY, username) .addParameter(PARAMETER_FILE_POSTFIX, filePostfix) .build(); } catch (URISyntaxException e) { @@ -106,7 +106,7 @@ public class StorageService { public void processFile(String username, String filePostfix) { HashMap values = new HashMap<>() {{ - put(PARAMETER_USERNAME, username); + put(PARAMETER_FILE_KEY, username); put(PARAMETER_FILE_POSTFIX, filePostfix); }}; diff --git a/src/test/java/br/com/hideyoshi/auth/service/microservice/StorageServiceTest.java b/src/test/java/br/com/hideyoshi/auth/service/microservice/StorageServiceTest.java index 7422147..e05b27b 100644 --- a/src/test/java/br/com/hideyoshi/auth/service/microservice/StorageServiceTest.java +++ b/src/test/java/br/com/hideyoshi/auth/service/microservice/StorageServiceTest.java @@ -40,7 +40,7 @@ public class StorageServiceTest { // When try { - String responseString = "{\"presigned_url\":\"https://test.com\", \"file_key\":\"test\"}"; + String responseString = "{\"signed_url\":\"https://test.com\", \"expires_in\":\"3600\"}"; Mockito.doReturn(responseString).when(storageService).postRequest(Mockito.any(), Mockito.any()); } catch (IOException e) { assert false; @@ -85,7 +85,7 @@ public class StorageServiceTest { // When try { - String responseString = "{\"presigned_url\":\"http://test.com\"}"; + String responseString = "{\"signed_url\":\"http://test.com\"}"; Mockito.doReturn(responseString).when(storageService).getRequest(Mockito.any()); } catch (IOException e) { assert false;