Skip to content

Commit

Permalink
[Fix] 회원 탈퇴 문제 수정 - #67
Browse files Browse the repository at this point in the history
  • Loading branch information
Juser0 committed Nov 10, 2023
1 parent 09d3b95 commit 4105283
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

@Getter
@ApiModel(value = "기본 응답")
<<<<<<< Updated upstream
@NoArgsConstructor
@AllArgsConstructor
@Builder
=======
>>>>>>> Stashed changes
public class DefaultResponseDto <T> {

@ApiModelProperty(position = 1, value = "응답 코드", example = "RESPONSE_CODE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public String uploadFileToS3(String fileName, MultipartFile file) {
@Transactional
public void deleteFileFromS3(String fileName) {
try {
if (fileName == "") return;
amazonS3Client.deleteObject(bucketName, fileName);
} catch (SdkClientException e) {
throw new CustomException(e, FILE_NOT_FOUND);
Expand Down
26 changes: 11 additions & 15 deletions favor/src/main/java/com/favor/favor/user/UserPhotoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.favor.favor.photo.UserPhoto;
import com.favor.favor.photo.PhotoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.net.URL;
import java.util.Optional;
import java.util.UUID;

import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR;

@Slf4j
@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand Down Expand Up @@ -53,15 +56,12 @@ public UserPhoto getUserProfilePhoto(Long userNo) {

//유저 프로필사진 삭제
@Transactional
public User deleteUserProfilePhoto(Long userNo) {
public void deleteUserProfilePhoto(Long userNo) {

User user = userService.findUserByUserNo(userNo);
String fileName = extractProfilePhotoFileName(user);

user.setUserProfilePhoto(null);
photoService.deleteFileFromS3(fileName);

return userRepository.save(user);
}


Expand Down Expand Up @@ -97,15 +97,12 @@ public UserPhoto getUserBackgroundPhoto(Long userNo) {

//유저 배경사진 삭제
@Transactional
public User deleteUserBackgroundPhoto(Long userNo) {
public void deleteUserBackgroundPhoto(Long userNo) {

User user = userService.findUserByUserNo(userNo);
String fileName = extractBackgroundPhotoFileName(user);

user.setUserBackgroundPhoto(null);
photoService.deleteFileFromS3(fileName);

return userRepository.save(user);
}


Expand All @@ -123,11 +120,10 @@ public String getUserBackgroundFileName(String fileName){

//유저의 프로필 사진 이름 추출
public static String extractProfilePhotoFileName(User user) {
String path = null;

String path;
try {
URL url = new URL(user.getUserProfilePhoto().getPhotoUrl());
path = url.getPath();
if (user.getUserProfilePhoto() == null) return "";
path = new URL(user.getUserProfilePhoto().getPhotoUrl()).getPath();

if (path.startsWith("/")) {
path = path.substring(1);
Expand All @@ -140,11 +136,11 @@ public static String extractProfilePhotoFileName(User user) {
}
//유저의 배경 사진 이름 추출
public static String extractBackgroundPhotoFileName(User user) {
String path = null;
String path;

try {
URL url = new URL(user.getUserBackgroundPhoto().getPhotoUrl());
path = url.getPath();
if (user.getUserBackgroundPhoto() == null) return "";
path = new URL(user.getUserBackgroundPhoto().getPhotoUrl()).getPath();

if (path.startsWith("/")) {
path = path.substring(1);
Expand Down

0 comments on commit 4105283

Please sign in to comment.