-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 회원 탈퇴 로직 구현 * feat: @kdomo 리뷰 반영 * fix: 마지막 로그인 시간 테스트 코드 삭제
- Loading branch information
Showing
9 changed files
with
102 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
39 changes: 39 additions & 0 deletions
39
src/main/java/com/depromeet/domain/member/api/MemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.depromeet.domain.member.api; | ||
|
||
import com.depromeet.domain.auth.dto.request.UsernameCheckRequest; | ||
import com.depromeet.domain.member.application.MemberService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "1-2. [회원]", description = "회원 관련 API") | ||
@RestController | ||
@RequestMapping("/members") | ||
@RequiredArgsConstructor | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
@Operation(summary = "아이디 중복 체크", description = "아이디 중복 체크를 진행합니다.") | ||
@PostMapping("/check-username") | ||
public ResponseEntity<Void> memberUsernameCheck( | ||
@Valid @RequestBody UsernameCheckRequest request) { | ||
memberService.checkUsername(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
// TODO: 테스트 코드 작성 필요 | ||
@Operation(summary = "회원 탈퇴", description = "회원탈퇴를 진행합니다.") | ||
@DeleteMapping("/withdrawal") | ||
public ResponseEntity<Void> memberWithdrawal(@Valid @RequestBody UsernameCheckRequest request) { | ||
memberService.withdrawal(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
Empty file.
37 changes: 37 additions & 0 deletions
37
src/main/java/com/depromeet/domain/member/application/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.depromeet.domain.member.application; | ||
|
||
import com.depromeet.domain.auth.dao.RefreshTokenRepository; | ||
import com.depromeet.domain.auth.dto.request.UsernameCheckRequest; | ||
import com.depromeet.domain.member.dao.MemberRepository; | ||
import com.depromeet.domain.member.domain.Member; | ||
import com.depromeet.global.error.exception.CustomException; | ||
import com.depromeet.global.error.exception.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final RefreshTokenRepository refreshTokenRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public void checkUsername(UsernameCheckRequest request) { | ||
if (memberRepository.existsByUsername(request.username())) { | ||
throw new CustomException(ErrorCode.MEMBER_ALREADY_REGISTERED); | ||
} | ||
} | ||
|
||
public void withdrawal(UsernameCheckRequest request) { | ||
final Member member = | ||
memberRepository | ||
.findByUsername(request.username()) | ||
.orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); | ||
|
||
refreshTokenRepository.deleteById(member.getId()); | ||
member.withdrawal(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters