-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: 반려동물 프로필 사진 수정 #17
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
base: dev
Are you sure you want to change the base?
Conversation
Pet Entity 수정 Pet Controller, Service 생성
FailedUploadImageException : 이미지 업로드 실패시 예외 ImageNotFoundException : 이미지 파일이 존재하지 않을 시 예외 InvalidImageTypeException : 이미지 확장가 아닐 때 예외 PetNotFoundException : 반려동물 프로필이 존재하지 않을 때의 예외
naekang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주말동안 고생 많으셨습니다~ 🙏
|
|
||
| dir: test-dir | ||
| default: | ||
| image-url: http://127.0.0.1:8001/test-bucket/test-dir/4a95753d-1827-43c5-b9a0-2359186aedec.png |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트용 이미지 url임을 명시하기 위해 이름에 test를 붙이는 것도 좋을거같습니다!
| String urlPath = imageUploadService.uploadPetImage(file); | ||
|
|
||
| // then | ||
| assertThat(urlPath.substring(0, urlPath.lastIndexOf("/") + 1)).isEqualTo("http://127.0.0.1:8001/test-bucket/test-dir/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isEqualTo 메소드 내부를 path변수로 대체할 수 있지 않을까요?? 🤟
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @Import(AwsS3MockConfig.class) | ||
| @SpringBootTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpringBootTest랑 @ExtendWith(MockitoExtension.class) 이 두가지 방식이 있는데 Mock을 이용하는 방식을 택하는 것도 좋을거같습니다!
phantasmicmeans/develop-study#12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 Mock으로 테스트하는 방법이 없어 추후에 더 찾아보고 수정하도록 하겠습니다:)
|
|
||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| public interface ImageUploadService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pet 뿐만 아니라 Member에서도 사용할 수 있기 때문에 메소드 이름에 Pet을 빼는게 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PetService에서 ImageUploadService에 의존하여 image를 업로드하는 것을 따로 뺀 것은 좋은 것 같습니다. 하지만 둘 다 service 계층으로 정의해둘 경우 PetService에서 다른 service에 의존하는게 조금 어색해보입니다. service말고 그냥 component처럼 빈 등록을 하면 어떨까요?
| @PatchMapping("/mypage/pets/{petId}/image") | ||
| public ResponseEntity<String> updatePetImage(@PathVariable("petId") Long id, | ||
| @RequestPart("file") MultipartFile multipartFile) { | ||
| if (multipartFile.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예외 처리를 Service 단에서 진행하는게 어떨까....ㅎ
| private String dir; | ||
|
|
||
| @Override | ||
| public String uploadPetImage(MultipartFile multipartFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional이 있어야 할 거 같습니다!
| public class AwsS3MockConfig { | ||
|
|
||
| @Value("${cloud.aws.s3.bucket}") | ||
| public String bucket; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 public인 이유가 따로 있을까요?
bokyung95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰사항 참고하여 수정하겠습니다:)
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @Import(AwsS3MockConfig.class) | ||
| @SpringBootTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 Mock으로 테스트하는 방법이 없어 추후에 더 찾아보고 수정하도록 하겠습니다:)
ImageUploadService, ImageUploadServiceImpl, PetServiceImpl ImageUploadServiceTest
younghoondoodoom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주말에도 고생 많으셨습니다! 제 생각 코멘트 남겼으니 참고 부탁드립니다!
|
|
||
| private final AmazonS3 amazonS3; | ||
|
|
||
| @Value("${cloud.aws.s3.bucket}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @Value("${cloud.aws.s3.bucket}") | ||
| private String bucket; | ||
|
|
||
| @Value("${dir}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에 코멘트랑 똑같은 생각입니다!
| @Override | ||
| public String createFileName(String filename) { | ||
| return UUID.randomUUID().toString().concat(getFileExtension(filename)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
내부적으로만 사용하는 메소드 같은데 인터페이스를 통해 public으로 열어놓은 이유가 있으실까요??
| validateFileExtension(filename); | ||
|
|
||
| return filename.substring(filename.lastIndexOf(".")); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에 코멘트랑 똑같은 의견입니다!
| fileValidate.add(".png"); | ||
| fileValidate.add(".JPG"); | ||
| fileValidate.add(".JPEG"); | ||
| fileValidate.add(".PNG"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미지 파일 확장자를 저장하는 리스트를 따로 상수로 빼던가 클래스를 분리 시키는게 좋을 것 같습니다! 확장자가 추가된다면 코드를 직접 수정해야하는 번거로움이 있을 것 같습니다!
|
|
||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| public interface ImageUploadService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PetService에서 ImageUploadService에 의존하여 image를 업로드하는 것을 따로 뺀 것은 좋은 것 같습니다. 하지만 둘 다 service 계층으로 정의해둘 경우 PetService에서 다른 service에 의존하는게 조금 어색해보입니다. service말고 그냥 component처럼 빈 등록을 하면 어떨까요?
| @Transactional | ||
| public class ImageUploadServiceImpl implements ImageUploadService { | ||
|
|
||
| private final AmazonS3 amazonS3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 클래스가 AmazonS3에 직접적으로 의존하고 있는 것 같습니다. 만약 이미지 업로드를 다른 방식으로 하게되면 해당 클래스를 직접 수정해야하는 상황이 발생할 것 같습니다. 중간에 인터페이스를 둔 클래스 분리를 통해 의존성을 숨기는게 어떨까요?
| private final ImageUploadService imageUploadService; | ||
| private final PetRepository petRepository; | ||
|
|
||
| @Value("${default.image-url}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에 @value에 대한 의견과 같습니다!
Uh oh!
There was an error while loading. Please reload this page.