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 : 유저 프로필 이미지 삭제 #188

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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 @@ -40,10 +40,6 @@
public class UserController {

private final UserService userService;
private final OauthService oauthservice;
private final KakaoConnector kakaoConnector;
private final GoogleConnector googleConnector;

public static final int PAGE_SIZE = 6;

@GetMapping("/info")
Expand Down Expand Up @@ -89,6 +85,13 @@ public ResponseEntity<Void> updateUserProfile(@AuthenticationPrincipal Long user
return ResponseEntity.ok().build();
}

@DeleteMapping("/profile")
public ResponseEntity<Void> deleteUserProfile(@AuthenticationPrincipal Long userId) {
userService.deleteUserProfile(userId);

return ResponseEntity.ok().build();
}

@GetMapping("/mypage/information/owner")
public ResponseEntity<Page<InformationBriefResponse>> retrieveInformationOwner(
@RequestParam(defaultValue = "0") int page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class UserService {

private final UserRepository userRepository;
private final UserImageService userImageService;
private final S3Uploader s3Uploader;
@Value("${user.profile.url.female}")
private String femaleProfileUrl;
@Value("${user.profile.male}")
private String maleProfileUrl;

public UserInfoResponse retrieveUserInfo(Long userId) {
User user = userRepository.findByUserId(userId);
Expand Down Expand Up @@ -60,11 +65,36 @@ public Page<InformationBriefResponse> retrieveInformationBookmark(Pageable pagea

@Transactional
public void updateUserProfile(Long userId, MultipartFile userProfile) {
UserImageResponse response = userImageService.registerInformation(userId, userProfile);
UserImageResponse response = userImageService.updateUserProfile(userId, userProfile);
User user = userRepository.findByUserId(userId);
checkUserProfile(user.getUserImage().getAddress());
user.updateUserImage(response.getImageUrl());
}

@Transactional
public void deleteUserProfile(Long userId) {
User user = userRepository.findByUserId(userId);
resetUserProfile(user,user.getUserImage().getAddress(),user.getSex());
}

private void resetUserProfile(User user, String imageUrl,String sex) {
checkUserProfile(imageUrl);
if(sex.equals("male")){
user.updateUserImage(maleProfileUrl);
} else if (sex.equals("female")) {
user.updateUserImage(femaleProfileUrl);
}else{
user.updateUserImage(noneProfileUrl);
}
}

private void checkUserProfile(String imageUrl) {
if(imageUrl.equals(femaleProfileUrl) || imageUrl.equals(maleProfileUrl )|| imageUrl.equals(noneProfileUrl)){ {
return;
}
s3Uploader.deleteImage(imageUrl);
}

public Page<GatheringMypageResponse> retrieveGatheringHost(Pageable pageable, Long userId) {
return userRepository.retrieveGatheringHost(pageable, userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ResponseEntity<UserImageResponse> createUserImage(@RequestPart("request")
@RequestPart("userImage") MultipartFile userImage,
BindingResult bindingResult) {
Utils.validationRequest(bindingResult);
UserImageResponse informationResponse = userImageService.registerInformation(
UserImageResponse informationResponse = userImageService.updateUserProfile(
imageRequest.getUserId(), userImage);

return ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public UserImage saveUserImage(String imageUrl) {
}

@Transactional
public UserImageResponse registerInformation(Long userId, MultipartFile userImage) {
public UserImageResponse updateUserProfile(Long userId, MultipartFile userImage) {

String userImageUrl = s3Uploader.upload(userImage, IMAGE_PATH, userId);

Expand Down
Loading