Fixes StorageService Implementation

This commit is contained in:
2024-05-26 02:23:19 -03:00
parent b602d7dc33
commit 66415761c0
5 changed files with 14 additions and 16 deletions

View File

@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class StorageServiceDownloadResponse {
@JsonProperty("presigned_url")
private String presignedUrl;
@JsonProperty("signed_url")
private String signedUrl;
}

View File

@@ -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;
}

View File

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

View File

@@ -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<StorageServiceUploadResponse> getNewFileUrl(String username, String filePostfix, FileTypeEnum fileTypeEnum) {
HashMap<String, String> 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<String, String> values = new HashMap<>() {{
put(PARAMETER_USERNAME, username);
put(PARAMETER_FILE_KEY, username);
put(PARAMETER_FILE_POSTFIX, filePostfix);
}};

View File

@@ -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;