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

๐Ÿš€ ์ด๋ฏธ์ง€ ๊ด€๋ จ validation ์ถ”๊ฐ€์™€ ๊ฐ ์ƒํ™ฉ์— ๋งž๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ #66

Merged
merged 35 commits into from
Jan 12, 2024

Conversation

shoeone96
Copy link
Collaborator

โœ… ์š”๊ตฌ์‚ฌํ•ญ

  • ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ํ›„ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ด๋ฏธ์ง€๋ฅผ ์ง€์šธ ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.
  • ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ์‹œ ์ œํ•œํ•  ์ˆ˜ ์žˆ๋Š” validation์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
  • ๊ฐ ์ƒํ™ฉ์— ๋Œ€ํ•œ test ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.

๐Ÿš€ ์ฃผ์š” ๋ณ€๊ฒฝ์‚ฌํ•ญ

  • ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ํ›„ ๋ฌธ์ œ ๋ฐœ์ƒ ์‹œ ๋กค๋ฐฑํ•˜๋Š” ๋กœ์ง ์ถ”๊ฐ€
  • ์ด๋ฏธ์ง€ validation ์ถ”๊ฐ€
  • ๊ฐ ๋กœ์ง์„ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ์— ์ถ”๊ฐ€
    • avatarItem ๋กœ์ง์— ์ถ”๊ฐ€
    • post ๋กœ์ง์— ์ถ”๊ฐ€
  • avatarItem list๋ฅผ ๋ฐ›์•„์˜ค๋Š” api ์ถ”๊ฐ€
  • ๊ฐ ์ƒํ™ฉ์— ๋Œ€ํ•œ test ์ฝ”๋“œ ์ž‘์„ฑ

Copy link

๐Ÿ“‘ Jacoco ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

Overall Project 96.62% -1.87% ๐Ÿ
Files changed 95.56% ๐Ÿ

File Coverage
Post.java 100% ๐Ÿ
SignupDto.java 100% ๐Ÿ
LoginDto.java 100% ๐Ÿ
CertifyDto.java 100% ๐Ÿ
SendCertificateDto.java 100% ๐Ÿ
AvatarItemResponse.java 100% ๐Ÿ
AvatarItemRequest.java 100% ๐Ÿ
LikeResponse.java 100% ๐Ÿ
LikeRequest.java 100% ๐Ÿ
ForecastCategory.java 100% ๐Ÿ
AvatarItemController.java 100% ๐Ÿ
AvatarItemService.java 100% ๐Ÿ
CoordinateValidator.java 100% ๐Ÿ
CertificateService.java 100% ๐Ÿ
UserService.java 100% ๐Ÿ
ImageControllerAdvice.java 100% ๐Ÿ
WeatherService.java 100% ๐Ÿ
LikeController.java 100% ๐Ÿ
AsyncConfig.java 100% ๐Ÿ
HttpRequestsConfigurer.java 100% ๐Ÿ
ForecastApiClient.java 100% ๐Ÿ
ForecastResultItem.java 100% ๐Ÿ
ItemType.java 100% ๐Ÿ
AvatarItem.java 100% ๐Ÿ
Sex.java 100% ๐Ÿ
WeatherController.java 100% ๐Ÿ
IncorrectCertificateException.java 100% ๐Ÿ
NonCertifiedUserException.java 100% ๐Ÿ
UserControllerAdvice.java 100% ๐Ÿ
AlreadyCertifiedUserException.java 100% ๐Ÿ
PostController.java 100% ๐Ÿ
PostSaveRequest.java 100% ๐Ÿ
PostReadResponse.java 100% ๐Ÿ
ImageFile.java 100% ๐Ÿ
CertificateController.java 100% ๐Ÿ
UserController.java 100% ๐Ÿ
Like.java 100% ๐Ÿ
User.java 100% ๐Ÿ
Certificate.java 100% ๐Ÿ
WeatherResponse.java 100% ๐Ÿ
AssertUtil.java 100% ๐Ÿ
DateTimeProvider.java 100% ๐Ÿ
SkyType.java 100% ๐Ÿ
Temperature.java 100% ๐Ÿ
Coordinate.java 100% ๐Ÿ
PtyType.java 100% ๐Ÿ
PostValidator.java 95.83% ๐Ÿ
AvatarImageValidator.java 95.52% -4.48% ๐Ÿ
MiniOImageServiceImpl.java 94.59% -4.5% ๐Ÿ
ImageAnnotationValidator.java 94.44% -5.56% ๐Ÿ
LikeService.java 93.98% -6.02% ๐Ÿ
ForecastResultErrorManager.java 93.55% ๐Ÿ
PostService.java 92.4% -5.85% ๐Ÿ
TemperatureArrange.java 90.32% -8.06% โŒ
ImageValidator.java 86.84% -13.16% ๐Ÿ
GlobalControllerAdvice.java 80.95% -0.95% โŒ
OotwMailSender.java 62.07% -37.93% โŒ

Copy link
Member

@Sehee-Lee-01 Sehee-Lee-01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š” PR ๋ฉ”์ธ ๋ธŒ๋žœ์น˜๋กœ ๋จธ์ง€๋˜๊ฒŒ ํ•ด๋†“์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ํ™•์ธ ํ•œ ๋ฒˆ ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

@shoeone96 shoeone96 changed the base branch from main to feature January 11, 2024 11:48
Copy link
Member

@Sehee-Lee-01 Sehee-Lee-01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ‘

Comment on lines 45 to 57
if (!postImg.isEmpty()) {
ImageFile imgFile = imageService.uploadImage(postImg);
try {
Post savedPost = postRepository.save(Post.from(user, request, imgFile.url(), temperatureArrange));
return PostSaveResponse.from(savedPost);
} catch (Exception e) {
imageService.deleteImage(imgFile.fileName());
throw new SaveException();
}
}
Post savedPost = postRepository.save(Post.from(user, request, null, temperatureArrange));

return PostSaveResponse.from(savedPost);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์กฐ๊ฑด๋ฌธ์„ ๋ฐ˜๋Œ€๋กœํ•ด์„œ ๊ตฌ์กฐ๋ฅผ ๋ฐ”๊พธ๋ฉด ๋” ๊น”๋”ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator

@ASak1104 ASak1104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!
๊ฐ™์ด ์ด์•ผ๊ธฐํ•œ ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •ํ•˜๊ณ  ๋จธ์ง€ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์š”!

Copy link

๐Ÿ“‘ Jacoco ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

Overall Project 97.32% -0.91% ๐Ÿ
Files changed 92.69% ๐Ÿ

File Coverage
AvatarItemResponse.java 100% ๐Ÿ
AvatarItemController.java 100% ๐Ÿ
AvatarItemService.java 100% ๐Ÿ
ImageControllerAdvice.java 100% ๐Ÿ
ItemType.java 100% ๐Ÿ
AvatarItem.java 100% ๐Ÿ
Sex.java 100% ๐Ÿ
PostController.java 100% ๐Ÿ
ImageFile.java 100% ๐Ÿ
MiniOImageServiceImpl.java 94.59% -4.5% ๐Ÿ
ImageAnnotationValidator.java 94.44% -5.56% ๐Ÿ
AvatarImageValidator.java 94% -6% ๐Ÿ
PostService.java 92.4% -7.6% ๐Ÿ
ImageValidator.java 86.84% -13.16% ๐Ÿ
GlobalControllerAdvice.java 80.95% ๐Ÿ

Copy link

๐Ÿ“‘ Jacoco ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

Overall Project 97.32% -0.91% ๐Ÿ
Files changed 92.69% ๐Ÿ

File Coverage
AvatarItemResponse.java 100% ๐Ÿ
AvatarItemController.java 100% ๐Ÿ
AvatarItemService.java 100% ๐Ÿ
ImageControllerAdvice.java 100% ๐Ÿ
ItemType.java 100% ๐Ÿ
AvatarItem.java 100% ๐Ÿ
Sex.java 100% ๐Ÿ
PostController.java 100% ๐Ÿ
ImageFile.java 100% ๐Ÿ
MiniOImageServiceImpl.java 94.59% -4.5% ๐Ÿ
ImageAnnotationValidator.java 94.44% -5.56% ๐Ÿ
AvatarImageValidator.java 94% -6% ๐Ÿ
PostService.java 92.4% -7.6% ๐Ÿ
ImageValidator.java 86.84% -13.16% ๐Ÿ
GlobalControllerAdvice.java 80.95% ๐Ÿ

Copy link

๐Ÿ“‘ Jacoco ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

Overall Project 97.32% -0.91% ๐Ÿ
Files changed 92.76% ๐Ÿ

File Coverage
AvatarItemResponse.java 100% ๐Ÿ
AvatarItemController.java 100% ๐Ÿ
AvatarItemService.java 100% ๐Ÿ
ImageControllerAdvice.java 100% ๐Ÿ
ItemType.java 100% ๐Ÿ
AvatarItem.java 100% ๐Ÿ
Sex.java 100% ๐Ÿ
WeatherController.java 100% ๐Ÿ
PostController.java 100% ๐Ÿ
ImageFile.java 100% ๐Ÿ
MiniOImageServiceImpl.java 94.59% -4.5% ๐Ÿ
ImageAnnotationValidator.java 94.44% -5.56% ๐Ÿ
AvatarImageValidator.java 94% -6% ๐Ÿ
LikeService.java 93.98% ๐Ÿ
PostService.java 92.4% -7.6% ๐Ÿ
ImageValidator.java 86.84% -13.16% ๐Ÿ
GlobalControllerAdvice.java 80.95% ๐Ÿ

Image domain์„ ๋ฉ”์„œ๋“œ ๋ช…์— ํฌํ•จํ•˜์ง€ ์•Š๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝ
Copy link
Collaborator

@ASak1104 ASak1104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ™์ด ๋ฆฌ๋ทฐ ํ–ˆ๋˜ ๋ถ€๋ถ„์ด ๋ฐ˜์˜์ด ์ •๋ง ์ž˜ ๋๋„ค์š”!

Comment on lines 7 to 9
ImageFile uploadImage(MultipartFile file);

void deleteImage(String fileName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์€ Image ๋‹จ์–ด๊ฐ€ ์—†์–ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”

Comment on lines +16 to +17
Assert.notNull(sex, SEX_ESSENTIAL);
Assert.isTrue(!sex.isBlank(), SEX_ESSENTIAL);
Copy link
Collaborator

@ASak1104 ASak1104 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AssertUtil ์จ์„œ ํ•œ ์ค„๋กœ ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”
AssertUtil.notBlank()๊ฐ€ ๋˜๊ฒ ๋„ค์š”

Comment on lines +10 to +12
@Slf4j
@RestControllerAdvice
public class ImageControllerAdvice {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์— Order๋ฅผ ์ง€์ •์•ˆํ•ด์ค˜๋„ ์ž˜ ๋˜๋‚˜์š”?
์ €๋Š” UserContollerAdvice์—์„œ ์šฐ์„  ์ˆœ์œ„๊ฐ€ ๋ฐ€๋ฆฌ๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๊ฑฐ๋“ ์š”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test์—์„œ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•ด์„œ ๋ฌธ์ œ ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ œ๊ฐ€ ์กฐ๊ธˆ ์ฐพ์•„๋ณด๋‹ˆ @ControllerAdvice์˜ ์˜ค๋”๋ง์€ ๊ธฐ๋ณธ์ ์œผ๋กœ class hierarchy๋ฅผ ๋”ฐ๋ผ๊ฐ„๋‹ค๊ณ  ํ•˜๋„ค์š” ์ถ”ํ›„ ํŒจํ‚ค์ง€ ๋ช…์ด ๋ฐ”๋€Œ์—ˆ์„ ๋•Œ ์˜ˆ์ƒ์น˜ ๋ชป ํ•œ status ๋ฐ˜ํ™˜์ด ๋  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œ ๋Œ€์ƒ ํด๋ž˜์Šค ์ง€์ •๊ณผ ์˜ค๋”๋ง์„ ์œ„ํ•œ ์ˆ˜์ •์ด ํ•„์š”ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

}

String contentType = img.getContentType();
if (!contentType.startsWith("image")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image ๋ฌธ์ž์—ด์„ ์ƒ์ˆ˜๋กœ ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”

Comment on lines 14 to 30
public static void validateImage(MultipartFile img) {
if (img == null) {
throw new IllegalArgumentException(EMPTY_FILE);
}
if (img.isEmpty()) {
throw new IllegalArgumentException(EMPTY_FILE);
}

if (img.getSize() > 10_000_000) {
return false;
throw new IllegalArgumentException(FILE_OVER_SIZE);
}

String contentType = img.getContentType();
if (!contentType.startsWith("image")) {
return false;
throw new IllegalArgumentException(INVALID_FILE_TYPE);
}

return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„๋„ Assert๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”

Comment on lines 46 to 59
if (postImg.isEmpty()) {
Post savedPost = postRepository.save(Post.from(user, request, null, temperatureArrange));
return PostSaveResponse.from(savedPost);
}

ImageFile imgFile = imageService.uploadImage(postImg);
try {
Post savedPost = postRepository.save(Post.from(user, request, imgFile.url(), temperatureArrange));

return PostSaveResponse.from(savedPost);
return PostSaveResponse.from(savedPost);
} catch (Exception e) {
imageService.deleteImage(imgFile.fileName());
throw new SaveException();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ‘

@@ -21,14 +28,18 @@
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.multipart.MultipartFile;

@WithMockUser
@AutoConfigureMockMvc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ์–ด๋…ธํ…Œ์ด์…˜์€ ์–ด๋–ค ์—ญํ• ์„ ํ•˜๋‚˜์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AutoConfigureMockMvc๋ฅผ ์จ์„œ MockMvc๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ์žˆ์–ด์š” :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„ํ•˜ WebMvcTest๊ฐ€ ์•„๋‹ˆ๋ผ SpringBootTest๋กœ ํ•˜์…”์„œ ๊ทธ๋ ‡๊ตฐ์š”

Comment on lines 53 to 54
@ParameterizedTest(name = "[{index}]: ์•„์ดํ…œ ํƒ€์ž…์ด {0}์ธ ๊ฒฝ์šฐ์— ์ €์žฅ์— ์„ฑ๊ณตํ•œ๋‹ค.")
@ValueSource(strings = {"image/jpeg", "image/gif", "image/png"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ •๋ง ์ข‹๋„ค์š” ๐Ÿ‘ image/jpg ๋„ ๋“ค์–ด๊ฐ€๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

Comment on lines 116 to +117
MockMultipartFile postImg =
new MockMultipartFile("postImg", "filename.txt", MediaType.MULTIPART_FORM_DATA_VALUE,
new MockMultipartFile("postImg", "filename.jpeg", MediaType.IMAGE_JPEG_VALUE,
Copy link
Collaborator

@ASak1104 ASak1104 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sehee-Lee-01 Post ํ…Œ์ŠคํŠธ์—์„œ๋„ @ParameterizedTest๋กœ ์ด๋ฏธ์ง€ ํ˜•์‹์„ ํ…Œ์ŠคํŠธํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

Comment on lines 102 to 110
return java.util.stream.Stream.of(
org.junit.jupiter.params.provider.Arguments.of(null, validSex),
org.junit.jupiter.params.provider.Arguments.of(validType, null),
org.junit.jupiter.params.provider.Arguments.of("", validSex),
org.junit.jupiter.params.provider.Arguments.of(validType, ""),
org.junit.jupiter.params.provider.Arguments.of(" ", validSex),
org.junit.jupiter.params.provider.Arguments.of(validType, " "),
org.junit.jupiter.params.provider.Arguments.of("hair", validSex),
org.junit.jupiter.params.provider.Arguments.of(validType, "female")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static import๋กœ ๋ฐ”๊ถˆ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link

๐Ÿ“‘ Jacoco ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

Overall Project 97.44% -0.78% ๐Ÿ
Files changed 93.85% ๐Ÿ

File Coverage
AvatarItemResponse.java 100% ๐Ÿ
AvatarItemController.java 100% ๐Ÿ
AvatarItemService.java 100% ๐Ÿ
ImageControllerAdvice.java 100% ๐Ÿ
ItemType.java 100% ๐Ÿ
AvatarItem.java 100% ๐Ÿ
Sex.java 100% ๐Ÿ
WeatherController.java 100% ๐Ÿ
PostController.java 100% ๐Ÿ
ImageFile.java 100% ๐Ÿ
ImageValidator.java 96.55% -3.45% ๐Ÿ
MiniOImageServiceImpl.java 94.59% -4.5% ๐Ÿ
ImageAnnotationValidator.java 94.44% -5.56% ๐Ÿ
AvatarImageValidator.java 94% -6% ๐Ÿ
LikeService.java 93.98% ๐Ÿ
PostService.java 92.4% -7.6% ๐Ÿ
GlobalControllerAdvice.java 80.95% ๐Ÿ

Copy link

๐Ÿ“‘ Jacoco ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

Overall Project 97.44% -0.78% ๐Ÿ
Files changed 93.85% ๐Ÿ

File Coverage
AvatarItemResponse.java 100% ๐Ÿ
AvatarItemController.java 100% ๐Ÿ
AvatarItemService.java 100% ๐Ÿ
ImageControllerAdvice.java 100% ๐Ÿ
ItemType.java 100% ๐Ÿ
AvatarItem.java 100% ๐Ÿ
Sex.java 100% ๐Ÿ
WeatherController.java 100% ๐Ÿ
PostController.java 100% ๐Ÿ
ImageFile.java 100% ๐Ÿ
ImageValidator.java 96.55% -3.45% ๐Ÿ
MiniOImageServiceImpl.java 94.59% -4.5% ๐Ÿ
ImageAnnotationValidator.java 94.44% -5.56% ๐Ÿ
AvatarImageValidator.java 94% -6% ๐Ÿ
LikeService.java 93.98% ๐Ÿ
PostService.java 92.4% -7.6% ๐Ÿ
GlobalControllerAdvice.java 80.95% ๐Ÿ

@Sehee-Lee-01 Sehee-Lee-01 merged commit 31ffa64 into feature Jan 12, 2024
1 check passed
@Sehee-Lee-01 Sehee-Lee-01 deleted the feature-image-enhancement branch January 12, 2024 05:38
Copy link
Collaborator

@ASak1104 ASak1104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์„ธํฌ๋‹˜ PR์„ ๋‹ค์‹œ ๋ณด๋‹ค ๋ณด๋‹ˆ ์ค‘์›๋‹˜ PR๊ณผ ๊ด€๋ จ๋œ๊ฒŒ ๋งŽ์€ ๊ฒƒ ๊ฐ™๋„ค์š”
์ถ”ํ›„ ๋ฆฌํŽ™ํ† ๋ง์—์„œ ๊ฐ™์ด ์ด์•ผ๊ธฐํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Comment on lines +43 to +45
validateImage(image);
validateItemType(type);
validateSex(sex);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์ด static import method ์ธ ๊ฑธ ๋†“์ณค์—ˆ๋„ค์š”
์„ธํฌ๋‹˜ PR์—์„œ ์ด์•ผ๊ธฐ ํ–ˆ๋˜ ๊ฑด๋ฐ ๊ณ ๋ฏผํ•ด๋ณผ ์ฃผ์ œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Comment on lines +8 to +11
public static boolean checkValue(String itemType) {
return Arrays.stream(ItemType.values())
.anyMatch(e -> e.name().equals(itemType));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ง€๊ธˆ ์ƒ๊ฐํ•ด๋ณด๋ฉด boolean ๋ฉ”์„œ๋“œ๋‹ค ๋ณด๋‹ˆ hasValue๋‚˜ Enum ํด๋ž˜์Šค๋‹ˆ๊นŒ hasName์ด ๋” ์ข‹์€ ๋ฉ”์„œ๋“œ ๋ช…์ผ ๊ฒƒ ๊ฐ™๋„ค์š”
๋‹ค์Œ refactoring ๋•Œ ๊ณ ๋ คํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Comment on lines +26 to +35
try {
String url = imageFile.url();
AvatarItem savedItem = avatarItemRepository.save(AvatarItem.create(requestDto, url));

return AvatarItemResponse.from(savedItem);
return AvatarItemResponse.from(savedItem);
} catch (Exception e) {
imageService.delete(imageFile.fileName());
throw new SaveException();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์„ธํฌ๋‹˜ PR์„ ๋ณด๋‹ˆ image ์ฒ˜๋ฆฌ transaction ๋ฉ”์„œ๋“œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค๋”๋ผ๊ณ ์š”
Supplier๋ฅผ ๋ฐ›์•„์„œ ๋ฉ”์„œ๋“œ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก transaction ๊ธฐ๋Šฅ ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“ค ํ•„์š”๋„ ์žˆ์–ด๋ณด์ž…๋‹ˆ๋‹ค!

Comment on lines +3 to +5
import static com.backendoori.ootw.common.image.exception.ImageException.IMAGE_ROLLBACK_FAIL_MESSAGE;
import static com.backendoori.ootw.common.image.exception.ImageException.IMAGE_UPLOAD_FAIL_MESSAGE;
import static com.backendoori.ootw.common.validation.ImageValidator.validateImage;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๋ ‡๊ฒŒ ๋ฉ”์‹œ์ง€๋ฅผ static import ํ•˜๋Š” ๋ถ€๋ถ„๋„ ์ถ”ํ›„ ๋ฆฌํŒฉํ† ๋ง ๋•Œ ๊ฐ™์ด ์ด์•ผ๊ธฐํ•ด๋ด์š”!

Comment on lines +10 to +12
@Slf4j
@RestControllerAdvice
public class ImageControllerAdvice {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ œ๊ฐ€ ์กฐ๊ธˆ ์ฐพ์•„๋ณด๋‹ˆ @ControllerAdvice์˜ ์˜ค๋”๋ง์€ ๊ธฐ๋ณธ์ ์œผ๋กœ class hierarchy๋ฅผ ๋”ฐ๋ผ๊ฐ„๋‹ค๊ณ  ํ•˜๋„ค์š” ์ถ”ํ›„ ํŒจํ‚ค์ง€ ๋ช…์ด ๋ฐ”๋€Œ์—ˆ์„ ๋•Œ ์˜ˆ์ƒ์น˜ ๋ชป ํ•œ status ๋ฐ˜ํ™˜์ด ๋  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œ ๋Œ€์ƒ ํด๋ž˜์Šค ์ง€์ •๊ณผ ์˜ค๋”๋ง์„ ์œ„ํ•œ ์ˆ˜์ •์ด ํ•„์š”ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Comment on lines +7 to +10
public class ImageAnnotationValidator implements ConstraintValidator<Image, MultipartFile> {

private static final String IMAGE_PREFIX = "image";
private Image annotation;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9๋ฒˆ๊ณผ 10๋ฒˆ ํ–‰ ์‚ฌ์ด์— ๊ฐœํ–‰์„ ํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Comment on lines +46 to +56
if (postImg.isEmpty()) {
Post savedPost = postRepository.save(Post.from(user, request, null, temperatureArrange));
return PostSaveResponse.from(savedPost);
}

ImageFile imgFile = imageService.upload(postImg);
try {
Post savedPost = postRepository.save(Post.from(user, request, imgFile.url(), temperatureArrange));

return PostSaveResponse.from(savedPost);
return PostSaveResponse.from(savedPost);
} catch (Exception e) {
Copy link
Collaborator

@ASak1104 ASak1104 Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sehee-Lee-01 ์„ธํฌ๋‹˜๊ป˜์„œ ํ•ด๋‹น ๋กœ์ง์„ ์ฐธ๊ณ ํ•˜์…จ๋˜ ๊ฒƒ ๊ฐ™๋„ค์š”

Post savedPost = postRepository.save(Post.from(user, request, imgFile.url(), temperatureArrange));

return PostSaveResponse.from(savedPost);

ํ•ด๋‹น ๋ถ€๋ถ„์ด ์ค‘๋ณต๋˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๋Š”๋ฐ private ๋ฉ”์„œ๋“œ๋กœ ๋ถ„๋ฆฌํ•˜๊ณ 
private ๋ฉ”์„œ๋“œ์—์„œ postImage ์—ฌ๋ถ€์— ๋”ฐ๋ผ null์ด๋‚˜ imgFile.url()์„ ๋„ฃ์–ด์ฃผ๋Š” ์‹์œผ๋กœ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”

Comment on lines +44 to +47
@BeforeEach
void setup() {
avatarItemRepository.deleteAll();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup ๋ณด๋‹ค๋Š” cleanup์— ๊ฐ€๊นŒ์›Œ ๋ณด์ด๋„ค์š”!
๊ทธ๋ฆฌ๊ณ  ๋งˆ์ง€๋ง‰ ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ๊ฐ€ ์ง€์›Œ์ง€์ง€ ์•Š์•„์„œ ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ์— ์˜ํ–ฅ์„ ์ค„ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants