From 3d32364f377e96f5ed521e5c99037914d1a505d8 Mon Sep 17 00:00:00 2001 From: adorableco Date: Tue, 10 Sep 2024 15:08:40 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=9A=8C=EC=9B=90=20=ED=83=88=ED=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../phote/common/module/Qualifier.kt | 8 ------- .../phote/controller/MemberController.kt | 24 +++++++++++++++++++ .../com/swm_standard/phote/entity/Exam.kt | 2 +- .../com/swm_standard/phote/entity/Member.kt | 6 ++++- .../com/swm_standard/phote/entity/Question.kt | 2 +- .../swm_standard/phote/entity/RefreshToken.kt | 2 +- .../com/swm_standard/phote/entity/Workbook.kt | 2 +- .../phote/service/MemberService.kt | 19 +++++++++++++++ 8 files changed, 52 insertions(+), 13 deletions(-) delete mode 100644 src/main/kotlin/com/swm_standard/phote/common/module/Qualifier.kt create mode 100644 src/main/kotlin/com/swm_standard/phote/controller/MemberController.kt create mode 100644 src/main/kotlin/com/swm_standard/phote/service/MemberService.kt diff --git a/src/main/kotlin/com/swm_standard/phote/common/module/Qualifier.kt b/src/main/kotlin/com/swm_standard/phote/common/module/Qualifier.kt deleted file mode 100644 index 0bc6ca5..0000000 --- a/src/main/kotlin/com/swm_standard/phote/common/module/Qualifier.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.swm_standard.phote.common.module - -class Qualifier { - @MustBeDocumented - @Retention(AnnotationRetention.RUNTIME) - @Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER) - annotation class Generated -} diff --git a/src/main/kotlin/com/swm_standard/phote/controller/MemberController.kt b/src/main/kotlin/com/swm_standard/phote/controller/MemberController.kt new file mode 100644 index 0000000..125e49b --- /dev/null +++ b/src/main/kotlin/com/swm_standard/phote/controller/MemberController.kt @@ -0,0 +1,24 @@ +package com.swm_standard.phote.controller + +import com.swm_standard.phote.common.resolver.memberId.MemberId +import com.swm_standard.phote.common.responsebody.BaseResponse +import com.swm_standard.phote.service.MemberService +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import java.util.UUID + +@RestController +@RequestMapping("/api") +class MemberController( + private val memberService: MemberService, +) { + @DeleteMapping("/member") + fun deleteMember( + @MemberId memberId: UUID, + ): BaseResponse { + val uuid = memberService.deleteMember(memberId) + + return BaseResponse(msg = "멤버 탈퇴 성공", data = uuid) + } +} diff --git a/src/main/kotlin/com/swm_standard/phote/entity/Exam.kt b/src/main/kotlin/com/swm_standard/phote/entity/Exam.kt index 0cf8187..45df678 100644 --- a/src/main/kotlin/com/swm_standard/phote/entity/Exam.kt +++ b/src/main/kotlin/com/swm_standard/phote/entity/Exam.kt @@ -13,7 +13,7 @@ import java.util.UUID @Entity data class Exam( - @ManyToOne + @ManyToOne(cascade = [(CascadeType.REMOVE)]) @JoinColumn(name = "member_id") val member: Member, @ManyToOne diff --git a/src/main/kotlin/com/swm_standard/phote/entity/Member.kt b/src/main/kotlin/com/swm_standard/phote/entity/Member.kt index 2ae3b0d..3950dba 100644 --- a/src/main/kotlin/com/swm_standard/phote/entity/Member.kt +++ b/src/main/kotlin/com/swm_standard/phote/entity/Member.kt @@ -1,6 +1,10 @@ package com.swm_standard.phote.entity -import jakarta.persistence.* +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Id import java.util.UUID @Entity diff --git a/src/main/kotlin/com/swm_standard/phote/entity/Question.kt b/src/main/kotlin/com/swm_standard/phote/entity/Question.kt index e296ae9..3342c3c 100644 --- a/src/main/kotlin/com/swm_standard/phote/entity/Question.kt +++ b/src/main/kotlin/com/swm_standard/phote/entity/Question.kt @@ -24,7 +24,7 @@ import java.util.UUID data class Question( @Id @Column(name = "question_uuid", nullable = false, unique = true) val id: UUID = UUID.randomUUID(), - @ManyToOne + @ManyToOne(cascade = [(CascadeType.REMOVE)]) @JoinColumn(name = "member_id") @JsonIgnore val member: Member, diff --git a/src/main/kotlin/com/swm_standard/phote/entity/RefreshToken.kt b/src/main/kotlin/com/swm_standard/phote/entity/RefreshToken.kt index 5404b74..b776666 100644 --- a/src/main/kotlin/com/swm_standard/phote/entity/RefreshToken.kt +++ b/src/main/kotlin/com/swm_standard/phote/entity/RefreshToken.kt @@ -7,7 +7,7 @@ import org.springframework.data.redis.core.RedisHash import java.time.LocalDateTime import java.util.UUID -@RedisHash(value = "refreshToken", timeToLive = 1296000) +@RedisHash(value = "refreshToken", timeToLive = 12960000) data class RefreshToken( @Id val refreshToken: UUID, diff --git a/src/main/kotlin/com/swm_standard/phote/entity/Workbook.kt b/src/main/kotlin/com/swm_standard/phote/entity/Workbook.kt index 6901305..4053fc9 100644 --- a/src/main/kotlin/com/swm_standard/phote/entity/Workbook.kt +++ b/src/main/kotlin/com/swm_standard/phote/entity/Workbook.kt @@ -21,7 +21,7 @@ import java.util.UUID data class Workbook( var title: String, var description: String?, - @ManyToOne + @ManyToOne(cascade = [(CascadeType.REMOVE)]) @JoinColumn(name = "member_id") @JsonIgnore val member: Member, diff --git a/src/main/kotlin/com/swm_standard/phote/service/MemberService.kt b/src/main/kotlin/com/swm_standard/phote/service/MemberService.kt new file mode 100644 index 0000000..faca49e --- /dev/null +++ b/src/main/kotlin/com/swm_standard/phote/service/MemberService.kt @@ -0,0 +1,19 @@ +package com.swm_standard.phote.service + +import com.swm_standard.phote.repository.MemberRepository +import org.springframework.stereotype.Service +import java.util.UUID + +@Service +class MemberService( + private val memberRepository: MemberRepository, +) { + fun deleteMember(memberId: UUID): UUID { + memberRepository.deleteById(memberId) + if (memberRepository.existsById(memberId)) { + throw IllegalStateException() + } + + return memberId + } +}