Skip to content

Commit

Permalink
feature: 사용자 프로필 사진 삭제 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorch9 committed Oct 21, 2023
1 parent 7df23fd commit a4a310c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package daybyquest.user.application;

import daybyquest.image.vo.BaseImageProperties;
import daybyquest.image.vo.Image;
import daybyquest.user.domain.User;
import daybyquest.user.domain.UserImages;
import daybyquest.user.domain.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DeleteUserImageService {

private final UserRepository userRepository;

private final UserImages userImages;

private final BaseImageProperties baseImageProperties;

public DeleteUserImageService(final UserRepository userRepository, final UserImages userImages,
final BaseImageProperties baseImageProperties) {
this.userRepository = userRepository;
this.userImages = userImages;
this.baseImageProperties = baseImageProperties;
}

@Transactional
public void invoke(final Long loginId) {
final User user = userRepository.getById(loginId);
userImages.remove(user.getImageIdentifier());
user.updateImage(new Image(baseImageProperties.getUserIdentifier()));
}
}

15 changes: 14 additions & 1 deletion src/main/java/daybyquest/user/presentation/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import daybyquest.auth.Authorization;
import daybyquest.auth.UserId;
import daybyquest.user.application.DeleteUserImageService;
import daybyquest.user.application.SaveUserService;
import daybyquest.user.application.UpdateUserImageService;
import daybyquest.user.application.UpdateUserInterestService;
Expand All @@ -13,6 +14,7 @@
import daybyquest.user.dto.request.UpdateUserVisibilityRequest;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -33,15 +35,19 @@ public class UserController {

private final UpdateUserImageService updateUserImageService;

private final DeleteUserImageService deleteUserImageService;

public UserController(final SaveUserService saveUserService, final UpdateUserService updateUserService,
final UpdateVisibilityService updateVisibilityService,
final UpdateUserInterestService updateUserInterestService,
final UpdateUserImageService updateUserImageService) {
final UpdateUserImageService updateUserImageService,
final DeleteUserImageService deleteUserImageService) {
this.saveUserService = saveUserService;
this.updateUserService = updateUserService;
this.updateVisibilityService = updateVisibilityService;
this.updateUserInterestService = updateUserInterestService;
this.updateUserImageService = updateUserImageService;
this.deleteUserImageService = deleteUserImageService;
}

@PostMapping("/profile")
Expand Down Expand Up @@ -81,4 +87,11 @@ public ResponseEntity<Void> updateUserImage(@UserId final Long loginId,
updateUserImageService.invoke(loginId, multipartFile);
return ResponseEntity.ok().build();
}

@DeleteMapping("/profile/image")
@Authorization
public ResponseEntity<Void> deleteUserImage(@UserId final Long loginId) {
deleteUserImageService.invoke(loginId);
return ResponseEntity.ok().build();
}
}

0 comments on commit a4a310c

Please sign in to comment.