Skip to content

Commit e8f0a04

Browse files
authored
Merge pull request #92 from SynergyX-AI-Pattern/feat/#91_auth_withdraw_profile
Feat/#91 auth withdraw profile
2 parents e98bce7 + a4fc971 commit e8f0a04

File tree

11 files changed

+153
-3
lines changed

11 files changed

+153
-3
lines changed

src/main/java/com/synergyx/trading/apiPayload/code/status/SuccessStatus.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ public enum SuccessStatus implements BaseCode {
5050
SUCCESS_DELETE_EMOTION_DIARY(HttpStatus.OK, "DIARY2002", "감정 투자 일기가 삭제되었습니다."),
5151

5252
// 인증
53-
AUTH_LOGIN_SUCCESS(HttpStatus.OK, "AUTH200", "로그인 성공"),
54-
AUTH_SIGNUP_SUCCESS(HttpStatus.OK, "AUTH201", "회원가입 성공"),
55-
AUTH_LOGOUT_SUCCESS(HttpStatus.OK, "AUTH202", "로그아웃 성공")
53+
AUTH_LOGIN_SUCCESS(HttpStatus.OK, "AUTH2000", "로그인 성공"),
54+
AUTH_SIGNUP_SUCCESS(HttpStatus.OK, "AUTH2001", "회원가입 성공"),
55+
AUTH_LOGOUT_SUCCESS(HttpStatus.OK, "AUTH2002", "로그아웃 성공"),
56+
AUTH_WITHDRAW_SUCCESS(HttpStatus.OK, "AUTH2003", "회원탈퇴 성공"),
57+
58+
// User
59+
USER_PROFILE_SUCCESS(HttpStatus.OK, "USER2000", "프로필 조회 성공"),
60+
USER_PROFILE_UPDATE_SUCCESS(HttpStatus.OK, "USER2001", "프로필 수정 성공")
5661
;
5762

5863
private final HttpStatus httpStatus;

src/main/java/com/synergyx/trading/controller/AuthController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,19 @@ public ResponseEntity<ApiResponse<Void>> logout(
7474
SuccessStatus.AUTH_LOGOUT_SUCCESS.getMessage()
7575
));
7676
}
77+
78+
@PostMapping("/withdraw")
79+
@Operation(summary = "회원 탈퇴",
80+
description = "현재 로그인된 사용자를 탈퇴 처리합니다.")
81+
public ResponseEntity<ApiResponse<Void>> withdraw(
82+
) {
83+
Long userId = userContext.getCurrentUserId();
84+
85+
userAuthService.withdrawUser(userId);
86+
87+
return ResponseEntity.ok(ApiResponse.onSuccess(
88+
SuccessStatus.AUTH_WITHDRAW_SUCCESS.getCode(),
89+
SuccessStatus.AUTH_WITHDRAW_SUCCESS.getMessage()
90+
));
91+
}
7792
}

src/main/java/com/synergyx/trading/controller/UserController.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import com.synergyx.trading.apiPayload.ApiResponse;
44
import com.synergyx.trading.apiPayload.code.status.SuccessStatus;
55
import com.synergyx.trading.config.context.UserContext;
6+
import com.synergyx.trading.dto.user.ProfileUpdateRequestDTO;
67
import com.synergyx.trading.dto.user.UserRequestDTO;
78
import com.synergyx.trading.service.userService.UserCommandService;
9+
import com.synergyx.trading.service.userService.UserQueryService;
810
import io.swagger.v3.oas.annotations.Operation;
911
import io.swagger.v3.oas.annotations.tags.Tag;
12+
import jakarta.validation.Valid;
1013
import lombok.RequiredArgsConstructor;
1114
import org.springframework.http.ResponseEntity;
1215
import org.springframework.web.bind.annotation.*;
@@ -19,6 +22,7 @@ public class UserController {
1922

2023
private final UserContext userContext;
2124
private final UserCommandService userCommandService;
25+
private final UserQueryService userQueryService;
2226

2327
@Operation(summary = "FCM 토큰 저장", description = "사용자의 FCM 토큰을 저장합니다.")
2428
@PatchMapping("/fcm-token")
@@ -34,4 +38,36 @@ public ResponseEntity<?> updateFcmToken(
3438
)
3539
);
3640
}
41+
42+
@GetMapping("/profile")
43+
@Operation(summary = "프로필 조회",
44+
description = "사용자의 프로필을 조회합니다.")
45+
public ResponseEntity<ApiResponse<String>> getProfile(
46+
) {
47+
Long userId = userContext.getCurrentUserId();
48+
49+
String name = userQueryService.getProfileName(userId);
50+
51+
return ResponseEntity.ok(ApiResponse.onSuccess(
52+
name,
53+
SuccessStatus.USER_PROFILE_SUCCESS.getCode(),
54+
SuccessStatus.USER_PROFILE_SUCCESS.getMessage()
55+
));
56+
}
57+
58+
@PatchMapping("/profile")
59+
@Operation(summary = "프로필 수정",
60+
description = "사용자의 프로필을 수정합니다.")
61+
public ResponseEntity<ApiResponse<Void>> updateProfile(
62+
@Valid @RequestBody ProfileUpdateRequestDTO requestDTO
63+
) {
64+
Long userId = userContext.getCurrentUserId();
65+
66+
userCommandService.updateProfile(userId, requestDTO);
67+
68+
return ResponseEntity.ok(ApiResponse.onSuccess(
69+
SuccessStatus.USER_PROFILE_UPDATE_SUCCESS.getCode(),
70+
SuccessStatus.USER_PROFILE_UPDATE_SUCCESS.getMessage()
71+
));
72+
}
3773
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.synergyx.trading.dto.user;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import jakarta.validation.constraints.NotBlank;
5+
6+
@Schema(description = "프로필 수정 요청 DTO")
7+
public record ProfileUpdateRequestDTO(
8+
9+
@NotBlank(message = "이름은 필수입니다.")
10+
@Schema(description = "새로운 이름", example = "아무개")
11+
String name
12+
) {
13+
}

src/main/java/com/synergyx/trading/model/User.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ public class User extends BaseEntity {
4646

4747
@Column(columnDefinition = "TEXT")
4848
private String fcmToken;
49+
50+
@Column(nullable = false)
51+
private boolean deleted;
4952
}

src/main/java/com/synergyx/trading/service/userService/UserAuthService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ public interface UserAuthService {
1313

1414
// 로그아웃
1515
void logout(Long userId);
16+
17+
// 회원탈퇴
18+
void withdrawUser(Long userId);
1619
}

src/main/java/com/synergyx/trading/service/userService/UserAuthServiceImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ public void logout(Long userId) {
112112
log.info("[LOGOUT] 로그아웃 완료 - userId={}", user.getId());
113113
}
114114

115+
/**
116+
* 회원 탈퇴 (soft delete)
117+
*/
118+
@Override
119+
@Transactional
120+
public void withdrawUser(Long userId) {
121+
User user = userRepository.findById(userId)
122+
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
123+
124+
user.setEmail("deleted_" + user.getId() + "@example.com");
125+
user.setPassword("");
126+
user.setAccessToken(null);
127+
user.setRefreshToken(null);
128+
user.setFcmToken(null);
129+
user.setUsername("탈퇴회원");
130+
user.setAgreeMarketing(false);
131+
user.setAgreeEvent(false);
132+
user.setPushEnabled(false);
133+
user.setDeleted(true); // soft delete flag
134+
}
135+
115136
/**
116137
* SecurityContext에 인증 객체를 설정
117138
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package com.synergyx.trading.service.userService;
22

3+
import com.synergyx.trading.dto.user.ProfileUpdateRequestDTO;
4+
35
public interface UserCommandService {
46

57
/**
68
* FCM 토큰을 업데이트합니다.
9+
*
710
* @param userId 사용자 ID
811
* @param fcmToken 새로운 FCM 토큰
912
*/
1013
void updateFcmToken(Long userId, String fcmToken);
14+
15+
/**
16+
* 사용자 정보를 업데이트 합니다.
17+
*
18+
* @param userId
19+
* @param requestDTO 수정 요청 dto
20+
*/
21+
void updateProfile(Long userId, ProfileUpdateRequestDTO requestDTO);
1122
}

src/main/java/com/synergyx/trading/service/userService/UserCommandServiceImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.synergyx.trading.apiPayload.code.status.ErrorStatus;
44
import com.synergyx.trading.apiPayload.exception.GeneralException;
5+
import com.synergyx.trading.dto.user.ProfileUpdateRequestDTO;
56
import com.synergyx.trading.model.User;
67
import com.synergyx.trading.repository.UserRepository;
78
import lombok.RequiredArgsConstructor;
@@ -25,4 +26,16 @@ public void updateFcmToken(Long userId, String fcmToken) {
2526
user.setFcmToken(fcmToken);
2627
userRepository.save(user);
2728
}
29+
30+
@Override
31+
@Transactional
32+
public void updateProfile(Long userId, ProfileUpdateRequestDTO requestDTO) {
33+
String newName = requestDTO.name();
34+
35+
User user = userRepository.findById(userId)
36+
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
37+
38+
user.setUsername(newName);
39+
userRepository.save(user);
40+
}
2841
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.synergyx.trading.service.userService;
2+
3+
public interface UserQueryService {
4+
5+
String getProfileName(Long userId);
6+
}

0 commit comments

Comments
 (0)