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..b1698f5 --- /dev/null +++ b/src/main/kotlin/com/swm_standard/phote/controller/MemberController.kt @@ -0,0 +1,25 @@ +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.dto.DeleteMemberResponse +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 = DeleteMemberResponse(uuid)) + } +} diff --git a/src/main/kotlin/com/swm_standard/phote/dto/DeleteMemberResponse.kt b/src/main/kotlin/com/swm_standard/phote/dto/DeleteMemberResponse.kt new file mode 100644 index 0000000..d8e81be --- /dev/null +++ b/src/main/kotlin/com/swm_standard/phote/dto/DeleteMemberResponse.kt @@ -0,0 +1,7 @@ +package com.swm_standard.phote.dto + +import java.util.UUID + +data class DeleteMemberResponse( + val id: UUID, +) 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..e7b0448 100644 --- a/src/main/kotlin/com/swm_standard/phote/entity/Member.kt +++ b/src/main/kotlin/com/swm_standard/phote/entity/Member.kt @@ -1,9 +1,19 @@ package com.swm_standard.phote.entity -import jakarta.persistence.* +import jakarta.persistence.CascadeType +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Id +import jakarta.persistence.OneToMany +import org.hibernate.annotations.SQLDelete +import org.hibernate.annotations.SQLRestriction import java.util.UUID @Entity +@SQLDelete(sql = "UPDATE member SET deleted_at = NOW() WHERE member_uuid = ?") +@SQLRestriction("deleted_at is NULL") data class Member( val name: String, val email: String, @@ -14,4 +24,13 @@ data class Member( @Id @Column(name = "member_uuid", nullable = false, unique = true) val id: UUID = UUID.randomUUID() + + @OneToMany(mappedBy = "member", cascade = [(CascadeType.REMOVE)]) + val questions: List = emptyList() + + @OneToMany(mappedBy = "member", cascade = [(CascadeType.REMOVE)]) + val workbooks: List = emptyList() + + @OneToMany(mappedBy = "member", cascade = [(CascadeType.REMOVE)]) + val exams: List = emptyList() } 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/service/MemberService.kt b/src/main/kotlin/com/swm_standard/phote/service/MemberService.kt new file mode 100644 index 0000000..ed0c262 --- /dev/null +++ b/src/main/kotlin/com/swm_standard/phote/service/MemberService.kt @@ -0,0 +1,16 @@ +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) + + return memberId + } +} diff --git a/src/test/kotlin/com/swm_standard/phote/entity/AnswerTest.kt b/src/test/kotlin/com/swm_standard/phote/entity/AnswerTest.kt index edcc157..2db23fa 100644 --- a/src/test/kotlin/com/swm_standard/phote/entity/AnswerTest.kt +++ b/src/test/kotlin/com/swm_standard/phote/entity/AnswerTest.kt @@ -1,19 +1,10 @@ package com.swm_standard.phote.entity -import com.navercorp.fixturemonkey.FixtureMonkey -import com.navercorp.fixturemonkey.kotlin.KotlinPlugin -import com.navercorp.fixturemonkey.kotlin.giveMeOne import org.assertj.core.api.Assertions import org.junit.jupiter.api.Test import java.util.UUID class AnswerTest { - private val fixtureMonkey: FixtureMonkey = - FixtureMonkey - .builder() - .plugin(KotlinPlugin()) - .build() - @Test fun `문제가 객관식이면 정오답 체크한다`() { val category = Category.MULTIPLE @@ -51,13 +42,13 @@ class AnswerTest { Workbook( title = "hinc", description = null, - member = fixtureMonkey.giveMeOne(), + member = createMember(), emoji = "📚", ) fun createExam() = Exam( - member = fixtureMonkey.giveMeOne(), + member = createMember(), workbook = createWorkbook(), sequence = 4282, time = 40, @@ -110,4 +101,12 @@ class AnswerTest { tags = mutableListOf(), memo = null, ) + + private fun createMember() = + Member( + name = "Wilbur Noel", + email = "leslie.warner@example.com", + image = "ocurreret", + provider = Provider.APPLE, + ) } diff --git a/src/test/kotlin/com/swm_standard/phote/entity/QuestionTest.kt b/src/test/kotlin/com/swm_standard/phote/entity/QuestionTest.kt index 65dbf15..9db8397 100644 --- a/src/test/kotlin/com/swm_standard/phote/entity/QuestionTest.kt +++ b/src/test/kotlin/com/swm_standard/phote/entity/QuestionTest.kt @@ -2,20 +2,11 @@ package com.swm_standard.phote.entity import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper -import com.navercorp.fixturemonkey.FixtureMonkey -import com.navercorp.fixturemonkey.kotlin.KotlinPlugin -import com.navercorp.fixturemonkey.kotlin.giveMeOne import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.util.UUID class QuestionTest { - private val fixtureMonkey: FixtureMonkey = - FixtureMonkey - .builder() - .plugin(KotlinPlugin()) - .build() - private fun createQuestion(): Question { val objectMapper = ObjectMapper() val jsonString = """ @@ -82,15 +73,22 @@ class QuestionTest { @Test fun `공유받은 문제를 복사해서 저장한다`() { val questions = listOf(createQuestion(), createQuestion(), createQuestion()) - // val questions = fixtureMonkey.giveMeBuilder().size(Question::tags, 0).sampleList(5) - val member: Member = fixtureMonkey.giveMeOne() + val member: Member = createMember() val sharedQuestions = Question.createSharedQuestions(questions, member) assertEquals(sharedQuestions.size, questions.size) - assertEquals(sharedQuestions[0].member, member) + assertEquals(sharedQuestions[0].member.image, member.image) assertEquals(sharedQuestions[2].answer, questions[2].answer) assertEquals(sharedQuestions[1].tags[0].name, questions[1].tags[0].name) assertEquals(sharedQuestions[1].tags[0].id, questions[1].tags[0].id) } + + private fun createMember() = + Member( + name = "Wilbur Noel", + email = "leslie.warner@example.com", + image = "ocurreret", + provider = Provider.APPLE, + ) } diff --git a/src/test/kotlin/com/swm_standard/phote/entity/WorkbookTest.kt b/src/test/kotlin/com/swm_standard/phote/entity/WorkbookTest.kt index 16264c3..f4dda85 100644 --- a/src/test/kotlin/com/swm_standard/phote/entity/WorkbookTest.kt +++ b/src/test/kotlin/com/swm_standard/phote/entity/WorkbookTest.kt @@ -15,6 +15,7 @@ class WorkbookTest { Assertions.assertThat(workbook.title).isEqualTo(testTitle) Assertions.assertThat(workbook.emoji).isEqualTo("➗") Assertions.assertThat(workbook.member.email).isEqualTo(member.email) + Assertions.assertThat(workbook.member.provider).isEqualTo(member.provider) } @Test