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

[feat] 이미지 업로드 기능을 구현한다. #91

Merged
merged 35 commits into from
Jun 15, 2024
Merged

Conversation

kpeel5839
Copy link
Contributor

📄 Summary

#90 한 작업은 해당 이슈에 있습니다.

🙋🏻 More

이번에 최대한 의존성을 많이 신경썼어요.
Image 패키지는 최대한 다른 패키지를 참조하지 않도록 노력했습니다!
그 과정에서 IdeaValidator가 생기게 되었고요.

또한, Mocking Test를 하기가 너무 싫어서 중요한 로직들은 ImageChecker로 뺐어요!

kpeel5839 added 30 commits June 12, 2024 18:50
@kpeel5839 kpeel5839 added the feat 기능 개발 label Jun 14, 2024
@kpeel5839 kpeel5839 self-assigned this Jun 14, 2024
@kpeel5839 kpeel5839 requested review from parkmuhyeun and dnd2dnd June 14, 2024 10:23
Comment on lines 128 to 129
List<Image> images = imageRepository.findAllByIdeaId(ideaId);
IdeaDetailResponse ideaDetailResponse = IdeaDetailResponse.of(tokenMemberId, idea, images);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

요것만 바뀐거에요! 아래는 option+command+L눌러서 바뀌었어용 호호호

Comment on lines +50 to +52
// S3
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000')
implementation 'com.amazonaws:aws-java-sdk-s3'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

요것만 추가했어요! 의존성에서는용

Copy link
Member

@parkmuhyeun parkmuhyeun 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 47 to 79
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();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

얘네는 서비스에말고 저장소(s3,.. )에 저장하는 책임을 담당하는 객체 만들어주면 더 좋겠네영

Copy link
Contributor Author

Choose a reason for hiding this comment

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

사실 처음에 그렇게 하려고 했었는데, Service가 다른 Service를 참조하는 모양이 조금 그랬었어요.
그냥 그렇게 하는게 나으려나요?

Copy link
Member

Choose a reason for hiding this comment

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

분리하면 걔는 service라기 보다는 하나의 역할을 하는 객체인데 주입할 수 있는 컴포넌트에 가깝다고 생각함당(한단계 낮은)

Comment on lines 119 to 122
private void deleteImage(Image image) {
amazonS3.deleteObject(new DeleteObjectRequest(bucket, image.getImageUrl()));
imageRepository.delete(image);
}
Copy link
Member

Choose a reason for hiding this comment

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

얘도

Comment on lines 12 to 13
@Value("${cloud-front-url}")
private static String cloudFrontUrl;
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
Contributor Author

Choose a reason for hiding this comment

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

레코드에서 말고 Service 딴에서 말씀하시는건가용?

Copy link
Member

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(
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 되면 API 2번 날리는 구조인거 같은데 트랜잭션 보장이 안되서 뭔가 보강을 하거나 수정해야 될거 같아용

Copy link
Contributor Author

Choose a reason for hiding this comment

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

흠랜잭션

@kpeel5839 kpeel5839 merged commit dda5de5 into develop Jun 15, 2024
1 check passed
@kpeel5839 kpeel5839 deleted the feat/#90 branch June 15, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants