-
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
S3 연동 및 프로필 이미지 추가 #79
Conversation
# Conflicts: # build.gradle
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 연동 고생 많으셨습니다!
다만 기본 이미지 설정 관련해서 회의에서 기본 이미지 설정은 하지 않고 null로 저장하는 것으로 정했기에 수정이 필요할 것 같아 rc로 남겨두었습니다.
그리고 질문이 있어 코멘트 남겨주시면 감사하겠습니다!
아래는 질문 주신 내용에 대한 답변입니다.
- 기본 이미지 관련해서는 회의에서 논의한대로 null값으로 저장하는 것으로 수정하면 좋을 것 같습니다.
- 테스트 속도가 조금 느리긴 하나 지금 당장 불편함을 느끼진 못해서 아직까진 수정이 필요하다는 생각이 들진 않습니다. 추후에 테스트가 많아져서 불편함이 체감될 정도가 되었을 때 수정해도 무방할 것 같습니다. 정수님 생각은 어떠신가요?
build.gradle
Outdated
// monitoring | ||
implementation 'org.springframework.boot:spring-boot-starter-actuator' | ||
runtimeOnly 'io.micrometer:micrometer-registry-prometheus' |
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.
여기 개행 맞춰주시면 좋을 것 같습니다!
@@ -27,6 +27,7 @@ | |||
@Table(name = "users") | |||
public class User extends BaseTimeEntity { | |||
|
|||
private static final String DEFAULT_PROFILE_IMAGE_URL = "https://dp7ped0142moi.cloudfront.net/default/profile.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.
기본 프로필 이미지는 빼기로 했기 때문에 이부분은 삭제해도 좋을 것 같습니다.
private String processDefaultProfileImageUrl(final String profileImageUrl) { | ||
if (profileImageUrl == null || profileImageUrl.isBlank()) { | ||
return DEFAULT_PROFILE_IMAGE_URL; | ||
} | ||
|
||
return profileImageUrl; | ||
} |
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.
위에서 언급한대로 기본 프로필 이미지는 설정하지 않기로 해서 null로 저장하는 것으로 수정하면 좋을 것 같습니다!
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.
컨벤션에 따라 ""
로 수정했습니다.
원래 안드로이드 측에서 처리가 불편할까 봐 null로 진행하자 건의드린 것이었는데, 유진님께서 괜찮다고 해주셔서 ""
로 수정하고 프로필 이미지 url 컬럼의 nullable은 컨벤션에 따라 false를 유지했습니다.
@@ -48,11 +49,12 @@ public ResponseEntity<ReadUsersWithFriendsStatusResponse> readAllWithKeyword( | |||
@PatchMapping(headers = "X-API-VERSION=1") | |||
public ResponseEntity<ReadUserResponse> updateById( | |||
@Authenticated final AuthenticatedUser authenticatedUser, | |||
@RequestBody final UpdateUserRequest updateUserRequest | |||
@RequestPart final UpdateUserRequest userRequest, | |||
@RequestPart(required = false) final MultipartFile profileImage |
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.
질문입니다!
프로필 이미지는 수정하지 않았을 경우에 대해 null 값으로 받기 위해 @RequestPart
에 required=false
설정을 해준 것으로 이해했는데 그렇다면 이미지 수정을 하지 않은 경우와 기본 이미지로 설정하고자 하는 경우를 어떻게 구분할지도 궁금합니다! (혹시나 제가 아직 이미지 수정 요청/응답을 주고받는 것에 이해가 부족한 것인가 해서 질문드립니다!)
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.
당시 진행할 때는 기본 이미지에 대해 고민하지 않고 진행했습니다.
또한, 기본 이미지로 변경한다는 것은 이미지를 없애겠다는 의미기에 수정 시 전달할 파일도 없고요!
그런데, 기본 이미지로 변경하는 것도 이번 pr에서 추가하면 좋을 것 같아 로직을 조금 수정했습니다.
UserController
는 동일하게 진행하고 UpdateUserRequest
에 changeToDefaultProfile
이라는 boolean 타입의 변수를 추가했습니다.
기본 이미지로 설정하기를 원할 시 이를 true로 전달하면 좋을 것 같다고 생각했는데 어떠신가요?
위 방식 혹은 기본 이미지로 변경하는 것에 대한 추가적인 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.
boolean 타입 변수로 기본 이미지로 변경여부를 전달해주는 방식 좋은 것 같습니다!
softAssertions.assertThat(actual.getProfileImageUrl()) | ||
.isEqualTo("https://dp7ped0142moi.cloudfront.net/default/profile.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.
마찬가지로 기본 이미지 설정 부분이라 수정이 필요할 것 같습니다!
@@ -9,13 +9,15 @@ public class UserTestFixture { | |||
protected final String 기존_소셜_아이디 = "12345"; | |||
protected final OAuthType 기존_소셜_타입 = OAuthType.KAKAO; | |||
protected final String 기존_이름 = "기존 이름"; | |||
protected final String 기존_프로필_이미지_url = "https://original.profile.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.
마찬가지로 기본 이미지 설정 부분이라 수정이 필요할 것 같습니다!
# Conflicts: # src/main/java/com/backend/blooming/exception/GlobalExceptionHandler.java # src/main/resources/static/docs/docs.html
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 연동을 통한 프로필 이미지 저장하기 기능 추가했습니다.
이와 함께 보안 및 성능을 위해 cloudfront도 함께 적용했습니다.
cloudfront의 지정 도메인도 설정해야 하는데, 이 부분은 추후에 함께 이야기하고 결정하기 위해 아직 설정하지 않았습니다.
다만, pr merge는 안드로이드 측에서 이미지 업로드가 완료된 후에 가능할 것 같습니다. (api의 변화로 인해)
또한, 현재
UserController
에 있는 반환 값에만 프로필 이미지 url을 반환하도록 했습니다.다른 곳에서도 필요하다면 안드로이드측과 이야기하여 차츰 리팩터링을 진행해야 할 것 같습니다.
질문드리고 싶은 부분이 몇 가지 있습니다.
다른 방식도 고민해 봤지만, 가장 쉬운 방식이라 판단해 그렇게 진행했습니다.
그런데 보안상 accessKey와 secretKey를 노출시킬 수 없기에 로컬 서버에서는 S3를 사용할 수 없게 됩니다.
그래서 이를 대체하기 위해
LocalStackContainer
라는 것을 통해 로컬에서 가짜 S3 버킷을 사용할 수 있도록 했습니다.이를 사용하는 것은 단점은 로컬 서버 수행과 테스트 시 속도가 조금... 느려졌다는 점입니다.
로컬 서버 자체는 사용하는 게 좋을 것 같은데, 테스트에서 잘 되는 게 확인되었으니 mock 객체를 사용해 테스트 속도를 높이는 것이 좋을지 그래도 제대로 수행되는 것을 검증하기 위해 현재처럼
LocalStackContainer
를 사용해 테스트를 진행하는 게 좋을지 의견을 구하고 싶습니다!