Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 회원 탈퇴 #209

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<DeleteMemberResponse> {
val uuid = memberService.deleteMember(memberId)

return BaseResponse(msg = "멤버 탈퇴 성공", data = DeleteMemberResponse(uuid))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.swm_standard.phote.dto

import java.util.UUID

data class DeleteMemberResponse(
val id: UUID,
)
21 changes: 20 additions & 1 deletion src/main/kotlin/com/swm_standard/phote/entity/Member.kt
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<Question> = emptyList()

@OneToMany(mappedBy = "member", cascade = [(CascadeType.REMOVE)])
val workbooks: List<Workbook> = emptyList()

@OneToMany(mappedBy = "member", cascade = [(CascadeType.REMOVE)])
val exams: List<Exam> = emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/com/swm_standard/phote/service/MemberService.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 10 additions & 11 deletions src/test/kotlin/com/swm_standard/phote/entity/AnswerTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -110,4 +101,12 @@ class AnswerTest {
tags = mutableListOf(),
memo = null,
)

private fun createMember() =
Member(
name = "Wilbur Noel",
email = "[email protected]",
image = "ocurreret",
provider = Provider.APPLE,
)
}
22 changes: 10 additions & 12 deletions src/test/kotlin/com/swm_standard/phote/entity/QuestionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -82,15 +73,22 @@ class QuestionTest {
@Test
fun `공유받은 문제를 복사해서 저장한다`() {
val questions = listOf(createQuestion(), createQuestion(), createQuestion())
// val questions = fixtureMonkey.giveMeBuilder<Question>().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 = "[email protected]",
image = "ocurreret",
provider = Provider.APPLE,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading