회원탈퇴 API 추가
This commit is contained in:
		| @@ -41,6 +41,9 @@ data class Member( | |||||||
|     @OneToMany(mappedBy = "creator") |     @OneToMany(mappedBy = "creator") | ||||||
|     var follower: MutableList<CreatorFollowing> = mutableListOf() |     var follower: MutableList<CreatorFollowing> = mutableListOf() | ||||||
|  |  | ||||||
|  |     @OneToMany(mappedBy = "member", cascade = [CascadeType.ALL]) | ||||||
|  |     val signOutReasons: MutableList<SignOut> = mutableListOf() | ||||||
|  |  | ||||||
|     @OneToOne(mappedBy = "member", fetch = FetchType.LAZY) |     @OneToOne(mappedBy = "member", fetch = FetchType.LAZY) | ||||||
|     var notification: MemberNotification? = null |     var notification: MemberNotification? = null | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.member.following.CreatorFollowRequest | |||||||
| import kr.co.vividnext.sodalive.member.login.LoginRequest | import kr.co.vividnext.sodalive.member.login.LoginRequest | ||||||
| import kr.co.vividnext.sodalive.member.notification.UpdateNotificationSettingRequest | import kr.co.vividnext.sodalive.member.notification.UpdateNotificationSettingRequest | ||||||
| import org.springframework.security.core.annotation.AuthenticationPrincipal | import org.springframework.security.core.annotation.AuthenticationPrincipal | ||||||
|  | import org.springframework.security.core.userdetails.User | ||||||
| import org.springframework.web.bind.annotation.GetMapping | import org.springframework.web.bind.annotation.GetMapping | ||||||
| import org.springframework.web.bind.annotation.PostMapping | import org.springframework.web.bind.annotation.PostMapping | ||||||
| import org.springframework.web.bind.annotation.PutMapping | import org.springframework.web.bind.annotation.PutMapping | ||||||
| @@ -144,4 +145,10 @@ class MemberController(private val service: MemberService) { | |||||||
|  |  | ||||||
|         ApiResponse.ok(service.searchMember(nickname = nickname, memberId = member.id!!)) |         ApiResponse.ok(service.searchMember(nickname = nickname, memberId = member.id!!)) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @PostMapping("/sign_out") | ||||||
|  |     fun signOut( | ||||||
|  |         @RequestBody signOutRequest: SignOutRequest, | ||||||
|  |         @AuthenticationPrincipal user: User | ||||||
|  |     ) = ApiResponse.ok(service.signOut(signOutRequest, user), "정상적으로 탈퇴 처리되었습니다.") | ||||||
| } | } | ||||||
|   | |||||||
| @@ -32,6 +32,7 @@ import org.springframework.data.repository.findByIdOrNull | |||||||
| import org.springframework.security.authentication.UsernamePasswordAuthenticationToken | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken | ||||||
| import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder | ||||||
| import org.springframework.security.core.context.SecurityContextHolder | import org.springframework.security.core.context.SecurityContextHolder | ||||||
|  | import org.springframework.security.core.userdetails.User | ||||||
| import org.springframework.security.core.userdetails.UserDetails | import org.springframework.security.core.userdetails.UserDetails | ||||||
| import org.springframework.security.core.userdetails.UserDetailsService | import org.springframework.security.core.userdetails.UserDetailsService | ||||||
| import org.springframework.security.core.userdetails.UsernameNotFoundException | import org.springframework.security.core.userdetails.UsernameNotFoundException | ||||||
| @@ -51,6 +52,7 @@ class MemberService( | |||||||
|     private val stipulationAgreeRepository: StipulationAgreeRepository, |     private val stipulationAgreeRepository: StipulationAgreeRepository, | ||||||
|     private val creatorFollowingRepository: CreatorFollowingRepository, |     private val creatorFollowingRepository: CreatorFollowingRepository, | ||||||
|     private val blockMemberRepository: BlockMemberRepository, |     private val blockMemberRepository: BlockMemberRepository, | ||||||
|  |     private val signOutRepository: SignOutRepository, | ||||||
|  |  | ||||||
|     private val memberNotificationService: MemberNotificationService, |     private val memberNotificationService: MemberNotificationService, | ||||||
|  |  | ||||||
| @@ -390,4 +392,22 @@ class MemberService( | |||||||
|     private fun getOrCreateLock(memberId: Long): ReentrantReadWriteLock { |     private fun getOrCreateLock(memberId: Long): ReentrantReadWriteLock { | ||||||
|         return tokenLocks.computeIfAbsent(memberId) { ReentrantReadWriteLock() } |         return tokenLocks.computeIfAbsent(memberId) { ReentrantReadWriteLock() } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Transactional | ||||||
|  |     fun signOut(signOutRequest: SignOutRequest, user: User) { | ||||||
|  |         val member = repository.findByEmail(user.username) ?: throw SodaException("로그인 정보를 확인해주세요.") | ||||||
|  |         if (!passwordEncoder.matches(signOutRequest.password, member.password)) { | ||||||
|  |             throw SodaException("비밀번호가 일치하지 않습니다.") | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (signOutRequest.reason.isBlank()) { | ||||||
|  |             throw SodaException("탈퇴하려는 이유를 입력해 주세요.") | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         member.isActive = false | ||||||
|  |  | ||||||
|  |         val signOut = SignOut(reason = signOutRequest.reason) | ||||||
|  |         signOut.member = member | ||||||
|  |         signOutRepository.save(signOut) | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								src/main/kotlin/kr/co/vividnext/sodalive/member/SignOut.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/main/kotlin/kr/co/vividnext/sodalive/member/SignOut.kt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | package kr.co.vividnext.sodalive.member | ||||||
|  |  | ||||||
|  | import kr.co.vividnext.sodalive.common.BaseEntity | ||||||
|  | import javax.persistence.Column | ||||||
|  | import javax.persistence.Entity | ||||||
|  | import javax.persistence.FetchType | ||||||
|  | import javax.persistence.JoinColumn | ||||||
|  | import javax.persistence.ManyToOne | ||||||
|  |  | ||||||
|  | @Entity | ||||||
|  | data class SignOut( | ||||||
|  |     @Column(columnDefinition = "TEXT", nullable = false) | ||||||
|  |     val reason: String | ||||||
|  | ) : BaseEntity() { | ||||||
|  |     @ManyToOne(fetch = FetchType.LAZY) | ||||||
|  |     @JoinColumn(name = "member_id", nullable = false) | ||||||
|  |     var member: Member? = null | ||||||
|  |         set(value) { | ||||||
|  |             value?.signOutReasons?.add(this) | ||||||
|  |             field = value | ||||||
|  |         } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | package kr.co.vividnext.sodalive.member | ||||||
|  |  | ||||||
|  | import org.springframework.data.jpa.repository.JpaRepository | ||||||
|  | import org.springframework.stereotype.Repository | ||||||
|  |  | ||||||
|  | @Repository | ||||||
|  | interface SignOutRepository : JpaRepository<SignOut, Long> | ||||||
| @@ -0,0 +1,6 @@ | |||||||
|  | package kr.co.vividnext.sodalive.member | ||||||
|  |  | ||||||
|  | data class SignOutRequest( | ||||||
|  |     val reason: String, | ||||||
|  |     val password: String | ||||||
|  | ) | ||||||
		Reference in New Issue
	
	Block a user