Skip to content

Commit 9779f15

Browse files
committed
feat: 회원 삭제 엔드포인트 구현 및 s3 이미지 삭제 오류 해결
2 parents 7666477 + 4687874 commit 9779f15

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/main/java/apptive/team5/global/util/S3Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static String extractFileName(String fileUrl) {
1414

1515
int pathEndIdx = fileUrl.contains("?") ? fileUrl.indexOf("?") : fileUrl.length();
1616

17-
return fileUrl.substring(pathStartIdx, pathEndIdx);
17+
return fileUrl.substring(pathStartIdx, pathEndIdx).trim();
1818
}
1919

2020
}

src/main/java/apptive/team5/user/controller/UserController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public ResponseEntity<UserResponse> changeProfileImage(@Valid @RequestBody FileU
5454
return ResponseEntity.status(HttpStatus.OK).body(userResponse);
5555
}
5656

57+
// 기본 이미지로 변경
58+
@DeleteMapping("/my/profile-image")
59+
public ResponseEntity<UserResponse> deleteProfileImage(@AuthenticationPrincipal Long userId) {
60+
UserResponse userResponse = userService.deleteProfileImage(userId);
61+
62+
return ResponseEntity.status(HttpStatus.OK).body(userResponse);
63+
}
64+
65+
5766
@GetMapping
5867
public ResponseEntity<Page<UserResponse>> getUserList(@RequestParam(required = false) String tag,
5968
@RequestParam(defaultValue = "0") int page,

src/main/java/apptive/team5/user/domain/UserEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ public void changeTag(String tag) {
7676
public void changeProfileImage(String profileImage) {
7777
this.profileImage = profileImage;
7878
}
79+
80+
public void setDefaultImage() {
81+
this.profileImage = DEFAULT_IMAGE;
82+
}
7983
}

src/main/java/apptive/team5/user/service/UserService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,14 @@ public UserResponse getUserInfo(Long userId) {
6666
}
6767

6868
public void deleteUser(Long userId) {
69+
70+
UserEntity findUser = userLowService.findById(userId);
71+
6972
subscribeLowService.deleteByUserId(userId);
7073
diaryLowService.deleteByUserId(userId);
7174
userLowService.deleteByUserId(userId);
7275

76+
s3Service.deleteS3File(findUser.getProfileImage());
7377
}
7478

7579
public UserResponse changeTag(UserTagUpdateRequest userTagUpdateRequest, Long userId) {
@@ -109,6 +113,16 @@ public UserResponse changeProfileImage(FileUploadRequest fileUploadRequest, Long
109113
return new UserResponse(findUser);
110114
}
111115

116+
public UserResponse deleteProfileImage(Long userId) {
117+
UserEntity findUser = userLowService.findById(userId);
118+
String oldProfileImage = findUser.getProfileImage();
119+
findUser.setDefaultImage();
120+
121+
s3Service.deleteS3File(oldProfileImage);
122+
123+
return new UserResponse(findUser);
124+
}
125+
112126
@Transactional(readOnly = true)
113127
public UserStaticsResponse getUserStatics(Long userId) {
114128
int killingPartCount = diaryLowService.countByUserId(userId);

0 commit comments

Comments
 (0)