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

[배포] 유저 프로필 이미지 삭제 기능 추가 #198

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ public User updateProfileInfo(Long userId, UserProfileInfoUpdateRequest request)
return userRepository.save(user.withProfileInfo(request));
}

@Transactional
public User updateProfileImg(Long userId, MultipartFile file) {
User user = getUserById(userId);
final String uploadImgUrl = imageUploadService.uploadProfileImage(file);
return userRepository.save(user.withProfileImg(uploadImgUrl));
}

@Transactional
public User deleteProfileImg(Long userId) {
User user = getUserById(userId);
return userRepository.save(user.withProfileImg(null));
}

private User getUserById(Long userId) {
return userRepository.getByIdAndStatus(userId, UserStatus.ACTIVE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package site.travellaboratory.be.user.presentation.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -12,6 +13,7 @@
import site.travellaboratory.be.user.application.service.UserProfileWriterService;
import site.travellaboratory.be.user.domain.User;
import site.travellaboratory.be.user.domain.request.UserProfileInfoUpdateRequest;
import site.travellaboratory.be.user.presentation.response.writer.UserProfileImgDeleteResponse;
import site.travellaboratory.be.user.presentation.response.writer.UserProfileImgUpdateResponse;
import site.travellaboratory.be.user.presentation.response.writer.UserProfileInfoUpdateResponse;

Expand All @@ -22,7 +24,7 @@ public class UserProfileWriterController {

private final UserProfileWriterService userProfileWriterService;

@PutMapping("/profile")
@PatchMapping("/profile")
public ApiResponse<UserProfileInfoUpdateResponse> updateProfileInfo(
@RequestBody UserProfileInfoUpdateRequest userProfileInfoUpdateRequest,
@UserId Long userId) {
Expand All @@ -37,4 +39,11 @@ public ApiResponse<UserProfileImgUpdateResponse> updateProfileImg(
final User result = userProfileWriterService.updateProfileImg(userId, file);
return ApiResponse.OK(UserProfileImgUpdateResponse.from(result));
}

@PatchMapping("/profile/img")
public ApiResponse<UserProfileImgDeleteResponse> deleteProfileImg(
@UserId Long userId) {
final User result = userProfileWriterService.deleteProfileImg(userId);
return ApiResponse.OK(UserProfileImgDeleteResponse.from(result));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package site.travellaboratory.be.user.presentation.response.writer;

import site.travellaboratory.be.user.domain.User;

public record UserProfileImgDeleteResponse(
String profileImgUrl
) {
public static UserProfileImgDeleteResponse from(User user) {
return new UserProfileImgDeleteResponse(
user.getProfileImgUrl()
);
}
}
Loading