Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] refactor/#552 Image 패키징 리팩터링 #534

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'

// S3
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.547'

annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand All @@ -45,9 +48,6 @@ dependencies {
testImplementation 'io.rest-assured:spring-mock-mvc'
testImplementation 'org.assertj:assertj-core:3.19.0'

// S3
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000')
implementation 'com.amazonaws:aws-java-sdk-s3'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mapbefine.mapbefine.common.exception;

import org.springframework.http.HttpStatus;

public class InternalServerException extends GlobalException {
public InternalServerException(ErrorCode<?> errorCode) {
super(errorCode, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mapbefine.mapbefine.common.entity;
package com.mapbefine.mapbefine.image.domain;

import static lombok.AccessLevel.PROTECTED;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,23 @@
import static com.mapbefine.mapbefine.image.exception.ImageErrorCode.ILLEGAL_IMAGE_FILE_EXTENSION;

import com.mapbefine.mapbefine.image.exception.ImageException.ImageBadRequestException;
import java.util.Arrays;

public enum ImageExtension {

JPEG(".jpeg"),
JPG(".jpg"),
JFIF(".jfif"),
PNG(".png"),
SVG(".svg"),
JPEG, JPG, JFIF, PNG, SVG,
;

private final String extension;
public static String extract(String fileName) {
int index = fileName.lastIndexOf(".") + 1;
String extension = fileName.substring(index);

ImageExtension(final String extension) {
this.extension = extension;
}

public static ImageExtension from(String imageFileName) {
return Arrays.stream(values())
.filter(imageExtension -> imageFileName.endsWith(imageExtension.getExtension()))
.findFirst()
.orElseThrow(() -> new ImageBadRequestException(ILLEGAL_IMAGE_FILE_EXTENSION));
}
try {
ImageExtension imageExtension = valueOf(extension.toUpperCase());

public String getExtension() {
return extension;
return imageExtension.name().toLowerCase();
} catch (IllegalArgumentException e) {
throw new ImageBadRequestException(ILLEGAL_IMAGE_FILE_EXTENSION);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mapbefine.mapbefine.image.domain;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

public class ImageNameGenerator {

private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss");

private ImageNameGenerator() {
}

public static String generate(String originalFileName) {
String fileName = generateUniqueName();
String extension = ImageExtension.extract(originalFileName);

return String.join(".", fileName, extension.toLowerCase());
}

private static String generateUniqueName() {
String dateFormat = DATE_TIME_FORMATTER.format(LocalDateTime.now());

String uuid = UUID.randomUUID().toString();
String uniqueName = uuid.split("-")[0];

return String.join("_", dateFormat, uniqueName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mapbefine.mapbefine.image.domain;

import org.springframework.web.multipart.MultipartFile;

public interface ImageUploader {

Image upload(MultipartFile multipartFile);

void delete(String imageName);

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
public enum ImageErrorCode {

ILLEGAL_IMAGE_FILE_EXTENSION("10000", "지원하지 않는 이미지 파일입니다."),
IMAGE_FILE_IS_NULL("10001", "이미지가 선택되지 않았습니다.")
IMAGE_FILE_IS_NULL("10001", "이미지가 선택되지 않았습니다."),
UNKNOWN_SERVER_ERROR("10002", "이미지 업로드를 실패했습니다.")
;

private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mapbefine.mapbefine.common.exception.BadRequestException;
import com.mapbefine.mapbefine.common.exception.ErrorCode;
import com.mapbefine.mapbefine.common.exception.InternalServerException;

public class ImageException {

Expand All @@ -13,4 +14,11 @@ public ImageBadRequestException(ImageErrorCode errorCode) {

}

public static class ImageInternalServerException extends InternalServerException {

public ImageInternalServerException(ImageErrorCode errorCode) {
super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage()));
}
}

}
Loading
Loading