-
Notifications
You must be signed in to change notification settings - Fork 0
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
[feat] 이미지 업로드 기능을 구현한다. #91
Conversation
List<Image> images = imageRepository.findAllByIdeaId(ideaId); | ||
IdeaDetailResponse ideaDetailResponse = IdeaDetailResponse.of(tokenMemberId, idea, images); |
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.
요것만 바뀐거에요! 아래는 option+command+L눌러서 바뀌었어용 호호호
// S3 | ||
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000') | ||
implementation 'com.amazonaws:aws-java-sdk-s3' |
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.
요것만 추가했어요! 의존성에서는용
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 String upload(MultipartFile multipartFile) { | ||
try { | ||
UploadFile uploadFile = UploadFile.from(multipartFile); | ||
fileUpload(uploadFile); | ||
return uploadFile.getOriginalFilename(); | ||
} catch (IOException exception) { | ||
throw new RuntimeException(exception); | ||
} | ||
} | ||
|
||
private void fileUpload(MultipartFile multipartFile) throws IOException { | ||
File tempFile = null; | ||
|
||
try { | ||
tempFile = File.createTempFile("upload_", ".tmp"); | ||
multipartFile.transferTo(tempFile); | ||
amazonS3.putObject(new PutObjectRequest( | ||
bucket, | ||
multipartFile.getOriginalFilename(), | ||
tempFile | ||
)); | ||
} catch (IOException exception) { | ||
throw new IOException(exception); | ||
} finally { | ||
removeTempFileIfExists(tempFile); | ||
} | ||
} | ||
|
||
private void removeTempFileIfExists(File tempFile) { | ||
if (Objects.nonNull(tempFile) && tempFile.exists()) { | ||
tempFile.delete(); | ||
} | ||
} |
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.
얘네는 서비스에말고 저장소(s3,.. )에 저장하는 책임을 담당하는 객체 만들어주면 더 좋겠네영
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가 다른 Service를 참조하는 모양이 조금 그랬었어요.
그냥 그렇게 하는게 나으려나요?
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 void deleteImage(Image image) { | ||
amazonS3.deleteObject(new DeleteObjectRequest(bucket, image.getImageUrl())); | ||
imageRepository.delete(image); | ||
} |
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-front-url}") | ||
private static String cloudFrontUrl; |
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.
얘는 밖에서 만들어주는게 좋지 않나용
이렇게하면 이거 필요한 레코드마다 다 넣어줘야 될거같아서영
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 딴에서 말씀하시는건가용?
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.
넵
} | ||
|
||
@PostMapping(value = "/{ideaId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
public ResponseEntity<Void> saveImage( |
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.
이렇게 되면 API 2번 날리는 구조인거 같은데 트랜잭션 보장이 안되서 뭔가 보강을 하거나 수정해야 될거 같아용
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.
흠랜잭션
📄 Summary
#90 한 작업은 해당 이슈에 있습니다.
🙋🏻 More
이번에 최대한 의존성을 많이 신경썼어요.
Image 패키지는 최대한 다른 패키지를 참조하지 않도록 노력했습니다!
그 과정에서 IdeaValidator가 생기게 되었고요.
또한, Mocking Test를 하기가 너무 싫어서 중요한 로직들은 ImageChecker로 뺐어요!