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/upload 이미지 업로드 구현 #56

Merged
merged 5 commits into from
Sep 9, 2024
Merged

Feat/upload 이미지 업로드 구현 #56

merged 5 commits into from
Sep 9, 2024

Conversation

Ho-s
Copy link
Collaborator

@Ho-s Ho-s commented Sep 6, 2024

PR Type

  • Bugfix
  • Feature
  • Docs
  • Refactoring (no functional changes, no api changes)

For what purpose

Key changes

To reviewers

Screenshots

.example.env Outdated Show resolved Hide resolved
Comment on lines 51 to 65
async update(
id: number,
updateUserDto: UpdateUserDto,
profileImage?: Express.Multer.File,
) {
const user = await this.userRepository.findOne(id);
if (user == undefined) {
throw new UserNotFoundException();
}

if (profileImage) {
const profileImageUrl = await this.uploadService.uploadFile(profileImage);
Object.assign(updateUserDto, { profileImageUrl });
}

Copy link
Collaborator

@sally0226 sally0226 Sep 8, 2024

Choose a reason for hiding this comment

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

request로부터 받은 이미지 업로드 하는 로직을 분리하는건 어떨까유?

controller에서 서비스 두개 호출

  • 사진 업로드 서비스 호출 후url 받기
  • 받은 url을 이용해 user update 서비스 호출

그러면 userService.update에서는 파일을 직접받지 않고 사진 url (string)만 받아 처리할 수 있어 간편해질 것 같고

추후에 다른 곳에도 사진 업로드가 필요할 때 편리할 것 같아서유 ~

(아래 형태로 확장 가능)
controller에서 서비스 두개 호출

  • 사진 업로드 서비스 호출 후url 받기
  • 받은 url을 이용해 ???? 서비스 호출

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

나도 이 방식을 선호하는데, 전에 같이 협업하던 프론트분도 이 방식이 불편하다해서,
웹팀한테 물어보니 , 지금 방식으로 해달라고 해서 이렇게 작성하였습니다!

Copy link
Collaborator

@sally0226 sally0226 Sep 8, 2024

Choose a reason for hiding this comment

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

웅웅!! API를 두개로 나누라는 말은 아니었어~~
컨트롤러 안에서 나누자는 뜻!!

  • AS-IS
    • user update service에서 1)파일업로드, 2)업로드된 url로 user profile 정보 업데이트 한번에 진행
  • TO-BE
    • file upload service 호출해서 파일업로드
    • user update service에는 string형태로 profile_image 전달

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아 이해했슴둥! 확인구다사이!

Copy link
Collaborator

Choose a reason for hiding this comment

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

완벽해여~~~ 👍

Comment on lines 69 to 78
async updateMe(
@Body() updateUserDto: UpdateUserRequestDto,
@CurrentUser() user: User,
@UploadedFile() profileImage?: Express.Multer.File,
): Promise<UserResponseDto> {
const updatedUser = await this.userService.update(user.id, updateUserDto);
const updatedUser = await this.userService.update(
user.id,
updateUserDto,
profileImage,
);
Copy link
Collaborator

@sally0226 sally0226 Sep 8, 2024

Choose a reason for hiding this comment

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

예를들면 요런식으로여~~~

async updateMe(
    @Body() updateUserDto: UpdateUserRequestDto,
    @CurrentUser() user: User,
    @UploadedFile() profileImage?: Express.Multer.File,
  ): Promise<UserResponseDto> {
    const uploadedURL: String = await this.fileService.upload(profileImage);
    const updatedUser =  await this.userService.update(
      user.id,
      updateUserDto,
      uploadedURL,
    );

@Ho-s Ho-s merged commit 0cb807d into stage Sep 9, 2024
3 checks passed
@Ho-s Ho-s deleted the feat/upload branch September 9, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants