Skip to content

Commit

Permalink
[Feat]: 회원탈퇴시 이유 받기 API 추가 (#97)
Browse files Browse the repository at this point in the history
이유 request body 추가
관련 로직 수정

Related to: #96
  • Loading branch information
dev-Crayon committed Mar 5, 2024
1 parent 5cd1708 commit 5db8e27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public JwtTokenResponse refresh(String token) {
}

@Transactional
public void leave(Long userId) {
public void leave(Long userId, String leaveReason) {

User user = userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_USER));
Expand All @@ -71,6 +71,6 @@ public void leave(Long userId) {
}

redisTemplate.delete(user.getSocialInfo().getSocialId());
user.deleteUser();
user.deleteUser(leaveReason);
}
}
6 changes: 5 additions & 1 deletion src/main/java/io/sobok/SobokSobok/auth/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class User extends BaseEntity implements UserDetails {
@Column
private LocalDateTime deletedAt;

@Column
private String leaveReason;

@Builder
public User(String username, SocialInfo socialInfo, String deviceToken, String roles) {
this.username = username;
Expand All @@ -62,10 +65,11 @@ public void changeUsername(String username) {
this.username = username;
}

public void deleteUser() {
public void deleteUser(String leaveReason) {
this.deviceToken = "";
this.username = "";
this.isDeleted = true;
this.leaveReason = leaveReason;
this.deletedAt = LocalDateTime.now();
this.socialInfo.removeSocialInfo();
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/sobok/SobokSobok/auth/ui/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ public ResponseEntity<ApiResponse<JwtTokenResponse>> refresh(
summary = "소복소복 회원 탈퇴",
description = "소복소복 서비스를 탈퇴하는 API 입니다."
)
public ResponseEntity<ApiResponse<Void>> refresh(
public ResponseEntity<ApiResponse<Void>> leave(
@RequestBody @Valid final LeaveRequest request,
@AuthenticationPrincipal User user
) {

authService.leave(user.getId());
authService.leave(user.getId(), request.text());
return ResponseEntity
.status(HttpStatus.OK)
.body(ApiResponse.success(
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/sobok/SobokSobok/auth/ui/dto/LeaveRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.sobok.SobokSobok.auth.ui.dto;

import jakarta.validation.constraints.NotBlank;

public record LeaveRequest(

@NotBlank
String text
) {
}

0 comments on commit 5db8e27

Please sign in to comment.