-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 사용자 정보 수정 시 사용
- Loading branch information
Showing
7 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/com/j9/bestmoments/constants/ImageFileTypes.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.j9.bestmoments.constants; | ||
|
||
import java.util.Arrays; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ImageFileTypes { | ||
JPEG("image/jpeg"), | ||
PNG("image/png"), | ||
GIF("image/gif"), | ||
BMP("image/bmp"), | ||
TIFF("image/tiff"), | ||
WEBP("image/webp"), | ||
SVG("image/svg+xml"), | ||
; | ||
|
||
private final String contentType; | ||
|
||
public static boolean contains(String contentType) { | ||
System.out.println(contentType); | ||
if (contentType == null) { | ||
return false; | ||
} | ||
String findingContentType = contentType.toLowerCase(); | ||
return Arrays.stream(ImageFileTypes.values()) | ||
.map(ImageFileTypes::getContentType) | ||
.anyMatch(type -> type.equals(findingContentType)); | ||
} | ||
|
||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/j9/bestmoments/dto/request/MemberUpdateDto.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
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/j9/bestmoments/validator/ImageTypeCheck.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,17 @@ | ||
package com.j9.bestmoments.validator; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Constraint(validatedBy = ImageTypeValidator.class) | ||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ImageTypeCheck { | ||
String message() default "Invalid Image File Type"; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/j9/bestmoments/validator/ImageTypeValidator.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,16 @@ | ||
package com.j9.bestmoments.validator; | ||
|
||
import com.j9.bestmoments.constants.ImageFileTypes; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public class ImageTypeValidator implements ConstraintValidator<ImageTypeCheck, MultipartFile> { | ||
|
||
@Override | ||
public boolean isValid(@NotNull MultipartFile file, ConstraintValidatorContext context) { | ||
String contentType = file.getContentType(); | ||
return ImageFileTypes.contains(contentType); | ||
} | ||
} |