Adds FileTypeEnumConverter for Selection FileType for AddProfilePicture
This commit is contained in:
@@ -72,12 +72,14 @@ public class UserController {
|
|||||||
|
|
||||||
@PostMapping("/profile-picture")
|
@PostMapping("/profile-picture")
|
||||||
@UserResourceGuard(accessType = UserResourceGuardEnum.USER)
|
@UserResourceGuard(accessType = UserResourceGuardEnum.USER)
|
||||||
public StorageServiceUploadResponse addProfilePicture() {
|
public StorageServiceUploadResponse addProfilePicture(
|
||||||
|
@RequestParam FileTypeEnum fileType
|
||||||
|
) {
|
||||||
UserDTO user = this.authService.getLoggedUser();
|
UserDTO user = this.authService.getLoggedUser();
|
||||||
return this.storageService.getNewFileUrl(
|
return this.storageService.getNewFileUrl(
|
||||||
user.getUsername(),
|
user.getUsername(),
|
||||||
"profile",
|
"profile",
|
||||||
FileTypeEnum.PNG
|
fileType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +103,4 @@ public class UserController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
package com.hideyoshi.backendportfolio.microservice.storageService.enums;
|
package com.hideyoshi.backendportfolio.microservice.storageService.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.hideyoshi.backendportfolio.util.exception.BadRequestException;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||||
public enum FileTypeEnum {
|
public enum FileTypeEnum {
|
||||||
PNG("png"),
|
PNG("png"),
|
||||||
|
|
||||||
JPEG("jpeg");
|
JPEG("jpeg");
|
||||||
|
|
||||||
|
|
||||||
private String fileExtension;
|
private final String fileExtension;
|
||||||
|
|
||||||
private FileTypeEnum(String fileExtension) {
|
FileTypeEnum(String fileExtension) {
|
||||||
this.fileExtension = fileExtension;
|
this.fileExtension = fileExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileExtension() {
|
public static FileTypeEnum fromValue(String value) {
|
||||||
return this.fileExtension;
|
for (FileTypeEnum e: FileTypeEnum.values()) {
|
||||||
|
if (e.getFileExtension().equals(value)) {
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
throw new BadRequestException("Invalid FileType.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.hideyoshi.backendportfolio.microservice.storageService.enums;
|
||||||
|
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class FileTypeEnumConverter implements Converter<String, FileTypeEnum> {
|
||||||
|
@Override
|
||||||
|
public FileTypeEnum convert(String value) {
|
||||||
|
return FileTypeEnum.fromValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user