-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from backendoori/feature-image-enhancement
🚀 이미지 관련 validation 추가와 각 상황에 맞는 테스트 코드 작성
- Loading branch information
Showing
29 changed files
with
626 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
src/main/java/com/backendoori/ootw/avatar/domain/ItemType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.backendoori.ootw.avatar.domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ItemType { | ||
HAIR, TOP, PANTS, ACCESSORY, SHOES, BACKGROUND | ||
HAIR, TOP, PANTS, ACCESSORY, SHOES, BACKGROUND; | ||
|
||
public static boolean checkValue(String itemType) { | ||
return Arrays.stream(ItemType.values()) | ||
.anyMatch(e -> e.name().equals(itemType)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.backendoori.ootw.avatar.domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum Sex { | ||
MALE, FEMALE | ||
MALE, FEMALE; | ||
|
||
public static boolean checkValue(String sex) { | ||
return Arrays.stream(Sex.values()) | ||
.anyMatch(e -> e.name().equals(sex)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/backendoori/ootw/avatar/validation/AvatarImageValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.backendoori.ootw.avatar.validation; | ||
|
||
import com.backendoori.ootw.avatar.domain.ItemType; | ||
import com.backendoori.ootw.avatar.domain.Sex; | ||
import io.jsonwebtoken.lang.Assert; | ||
|
||
public class AvatarImageValidator { | ||
|
||
private static final String NO_IMAGE_URL_MESSAGE = "아바타 이미지 url이 존재하지 않습니다."; | ||
private static final String ITEM_TYPE_ESSENTIAL = "아바타 타입은 반드시 포함되어야 합니다."; | ||
private static final String INVALID_ITEM_TYPE_MESSAGE = "해당 단어가 아바타 이미지 타입이 존재하지 않습니다."; | ||
private static final String SEX_ESSENTIAL = "성별은 반드시 포함되어야 합니다."; | ||
private static final String INVALID_WORD_MESSAGE = "해당 단어가 프로젝트 내 성별 분류 체계에 존재하지 않습니다."; | ||
|
||
public static void validateSex(String sex) { | ||
Assert.notNull(sex, SEX_ESSENTIAL); | ||
Assert.isTrue(!sex.isBlank(), SEX_ESSENTIAL); | ||
Assert.isTrue(Sex.checkValue(sex), INVALID_WORD_MESSAGE); | ||
} | ||
|
||
public static void validateItemType(String type) { | ||
Assert.notNull(type, ITEM_TYPE_ESSENTIAL); | ||
Assert.isTrue(!type.isBlank(), ITEM_TYPE_ESSENTIAL); | ||
Assert.isTrue(ItemType.checkValue(type), INVALID_ITEM_TYPE_MESSAGE); | ||
} | ||
|
||
public static void validateImage(String image) { | ||
Assert.notNull(image, NO_IMAGE_URL_MESSAGE); | ||
Assert.isTrue(!image.isBlank(), NO_IMAGE_URL_MESSAGE); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backendoori/ootw/common/image/ImageFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.backendoori.ootw.common.image; | ||
|
||
public record ImageFile( | ||
String url, | ||
String fileName | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/backendoori/ootw/common/image/exception/ImageControllerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.backendoori.ootw.common.image.exception; | ||
|
||
import com.backendoori.ootw.exception.ErrorResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class ImageControllerAdvice { | ||
|
||
private static final String IMAGE_RELATED_EXCEPTION = "업로드 요청 중 문제가 발생했습니다."; | ||
|
||
@ExceptionHandler(ImageException.class) | ||
public ResponseEntity<ErrorResponse> handleImageUploadException(ImageException e) { | ||
log.error("error message : {}", e.getMessage()); | ||
ErrorResponse errorResponse = new ErrorResponse(IMAGE_RELATED_EXCEPTION); | ||
|
||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) | ||
.body(errorResponse); | ||
} | ||
|
||
@ExceptionHandler(SaveException.class) | ||
public ResponseEntity<ErrorResponse> handleSaveException(SaveException e) { | ||
log.error("error message : {}", e.getMessage()); | ||
ErrorResponse errorResponse = new ErrorResponse(IMAGE_RELATED_EXCEPTION); | ||
|
||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) | ||
.body(errorResponse); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/backendoori/ootw/common/image/exception/ImageException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.backendoori.ootw.common.image.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class ImageException extends RuntimeException { | ||
|
||
public static final String IMAGE_UPLOAD_FAIL_MESSAGE = "이미지 업로드 중 예외가 발생했습니다."; | ||
public static final String IMAGE_ROLLBACK_FAIL_MESSAGE = "이미지 롤백 중 예외가 발생했습니다."; | ||
|
||
private final String message; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/backendoori/ootw/common/image/exception/SaveException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.backendoori.ootw.common.image.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class SaveException extends RuntimeException { | ||
|
||
private static final String DEFAULT_MESSAGE = "이미지 업로드 후 저장 로직에서 예외가 발생했습니다."; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.