Skip to content

Commit 8f7c28d

Browse files
authored
Merge pull request #161 from dnd-side-project/dev
feat(UsersController): νšŒμ› νƒˆν‡΄ κΈ°λŠ₯
2 parents 0963f32 + b31a1cd commit 8f7c28d

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

β€Žmain-server/src/main/java/com/example/demo/domain/user/controller/UsersController.javaβ€Ž

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
import lombok.RequiredArgsConstructor;
1414
import org.springframework.http.ResponseEntity;
1515
import org.springframework.security.core.annotation.AuthenticationPrincipal;
16-
import org.springframework.web.bind.annotation.ModelAttribute;
17-
import org.springframework.web.bind.annotation.PatchMapping;
18-
import org.springframework.web.bind.annotation.RequestMapping;
19-
import org.springframework.web.bind.annotation.RestController;
16+
import org.springframework.web.bind.annotation.*;
2017

2118
import java.io.IOException;
2219

@@ -36,10 +33,23 @@ public class UsersController {
3633
@ApiResponse(content = @Content(schema = @Schema(implementation = UpdateProfileResponse.class)))
3734
@PatchMapping("/profile")
3835
public ResponseEntity<UpdateProfileResponse> updateProfile(
39-
@AuthenticationPrincipal CustomUserDetails userDetails,
36+
@AuthenticationPrincipal CustomUserDetails me,
4037
@ModelAttribute UpdateProfileRequest request // MultipartFile + String 같이 λ°›κΈ° μœ„ν•΄ @ModelAttribute
4138
) throws IOException {
42-
UpdateProfileResponse response = usersService.updateProfile(userDetails.getId(), request);
39+
UpdateProfileResponse response = usersService.updateProfile(me.getId(), request);
4340
return ResponseEntity.ok(response);
4441
}
42+
43+
@Operation(
44+
summary = "계정 νƒˆν‡΄",
45+
description = "계정 정보λ₯Ό μ‚­μ œν•˜κ³ , μ„œλΉ„μŠ€μ—μ„œ νƒˆν‡΄ν•©λ‹ˆλ‹€"
46+
)
47+
@ApiResponse(content = @Content(schema = @Schema(implementation = String.class)))
48+
@DeleteMapping("/account")
49+
public ResponseEntity<String> deleteMyAccount(
50+
@AuthenticationPrincipal CustomUserDetails me
51+
) {
52+
usersService.deleteAccount(me.getId());
53+
return ResponseEntity.ok("μ„œλΉ„μŠ€μ—μ„œ νƒˆν‡΄ν•˜μ˜€μŠ΅λ‹ˆλ‹€");
54+
}
4555
}

β€Žmain-server/src/main/java/com/example/demo/domain/user/service/UsersService.javaβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,17 @@ public UpdateProfileResponse updateProfile(String userId, UpdateProfileRequest r
5757

5858
return new UpdateProfileResponse(user.getId(), user.getUsername(), user.getProfileUrl());
5959
}
60+
61+
@Transactional
62+
public void deleteAccount(String userId) {
63+
Users user = usersRepository.findById(userId)
64+
.orElseThrow(() -> new UserException(UserErrorCode.USER_NOT_FOUND));
65+
66+
String imageKey = r2Service.extractKey(user.getProfileUrl());
67+
if (imageKey != null && !imageKey.isBlank()) {
68+
r2Service.delete(imageKey);
69+
}
70+
71+
usersRepository.delete(user);
72+
}
6073
}

0 commit comments

Comments
Β (0)