Skip to content

Commit

Permalink
refactor: Target과 Feedback을 어그리거트루트로 설정한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed Mar 6, 2024
1 parent ec32d3b commit 535459f
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import javax.persistence.*

@Entity
class ChoiceFormQuestionFeedback(
id: Long? = null,
id: Long,
formQuestionId: Long,
isRead: Boolean = false,
bookmark: Bookmark,
Expand Down
27 changes: 23 additions & 4 deletions survey/src/main/kotlin/me/nalab/survey/domain/feedback/Feedback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,49 @@ import javax.persistence.*
class Feedback(
@Id
@Column(name = "feedback_id")
private var id: Long? = null,
val id: Long,

@JoinColumn(name = "survey_id", nullable = false)
private val surveyId: Long,
val surveyId: Long,

@OneToMany(
mappedBy = "feedback",
fetch = FetchType.LAZY,
cascade = [CascadeType.PERSIST, CascadeType.MERGE]
)
private val allQuestionFeedbacks: MutableList<FormQuestionFeedbackable>,
val allQuestionFeedbacks: MutableList<FormQuestionFeedbackable>,

@Column(name = "is_read", nullable = false)
private var isRead: Boolean = false,

@JoinColumn(name = "reviewer_id", nullable = false)
@OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.PERSIST, CascadeType.MERGE])
private val reviewer: Reviewer,
val reviewer: Reviewer,
) : Comparable<Feedback>, TimeBaseEntity() {

fun read(read: Boolean) {
isRead = read
}

fun generateFirstReviewerNickName() {
reviewer.nickName = "A"
}

fun generateNickName(lastName: String) {
reviewer.nickName = getNextNickName(lastName)
}

private fun getNextNickName(lastName: String): String {
for (i in lastName.length - 1 downTo 0) {
if (lastName[i] != 'Z') {
return lastName.substring(0, i) + (lastName[i].code + 1).toChar() + "A".repeat(
lastName.length - (i + 1)
)
}
}
return "A".repeat(Math.max(0, lastName.length + 1))
}

override fun compareTo(other: Feedback): Int {
if (updatedAt.isAfter(other.updatedAt)) {
return -1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
package me.nalab.survey.domain.feedback

import java.time.Instant
import javax.persistence.*

@Entity
@Table(name = "form_feedback")
abstract class FormQuestionFeedbackable(
@Id
@Column(name = "form_feedback_id")
protected open var id: Long? = null,
open val id: Long,

@Column(name = "form_question_id")
@JoinColumn(name = "form_question_id", nullable = false)
protected open val formQuestionId: Long,
open val formQuestionId: Long,

@Column(name = "is_read")
protected open var isRead: Boolean = false,
open var isRead: Boolean = false,

@Embedded
protected open val bookmark: Bookmark,
open val bookmark: Bookmark,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "feedback_id")
private var feedback: Feedback,
) {

fun bookmark() {
bookmark.isBookmarked = true
bookmark.bookmarkedAt = Instant.now()
}

fun cancel() {
bookmark.isBookmarked = false
bookmark.bookmarkedAt = Instant.now()
}
}
val feedback: Feedback,
)
30 changes: 5 additions & 25 deletions survey/src/main/kotlin/me/nalab/survey/domain/feedback/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,14 @@ import javax.persistence.Table
class Reviewer(
@Id
@Column(name = "reviewer_id")
private var id: Long? = null,
val id: Long,

@Column(name = "nick_name", nullable = false)
private var nickName: String,
var nickName: String,

@Column(name = "collaboration_experience", nullable = false)
private val collaborationExperience: Boolean,
val collaborationExperience: Boolean,

@Column(name = "position", nullable = false)
private var position: String? = null,
) : TimeBaseEntity() {

fun generateFirstReviewerNickName() {
nickName = "A"
}

fun generateNickName(lastName: String) {
nickName = getNextNickName(lastName)
}

private fun getNextNickName(lastName: String): String {
for (i in lastName.length - 1 downTo 0) {
if (lastName[i] != 'Z') {
return lastName.substring(0, i) + (lastName[i].code + 1).toChar() + "A".repeat(
lastName.length - (i + 1)
)
}
}
return "A".repeat(Math.max(0, lastName.length + 1))
}
}
var position: String? = null,
) : TimeBaseEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import javax.persistence.*

@Entity
class ShortFormQuestionFeedback(
id: Long? = null,
id: Long,
formQuestionId: Long,
isRead: Boolean = false,
bookmark: Bookmark,
Expand All @@ -13,5 +13,5 @@ class ShortFormQuestionFeedback(
@ElementCollection
@CollectionTable(name = "reply", joinColumns = [JoinColumn(name = "form_feedback_id")])
@Column(name = "replies")
private val replies: MutableList<String>,
val replies: MutableList<String>,
) : FormQuestionFeedbackable(id, formQuestionId, isRead, bookmark, feedback)
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ class Choice(

@Id
@Column(name = "choice_id")
private var id: Long? = null,
val id: Long,

@Column(name = "content", length = 18, nullable = false)
private val content: String,
val content: String,

@Column(name = "orders", nullable = false)
val order: Int,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "form_question_id", nullable = false)
private val choiceFormQuestion: ChoiceFormQuestion,
val choiceFormQuestion: ChoiceFormQuestion,
) : Comparable<Choice> {

override fun compareTo(other: Choice): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import javax.persistence.*

@Entity
class ChoiceFormQuestion(
id: Long? = null,
id: Long,
title: String,
order: Int,
questionType: QuestionType,
Expand All @@ -16,14 +16,14 @@ class ChoiceFormQuestion(
fetch = FetchType.LAZY,
cascade = [CascadeType.PERSIST, CascadeType.MERGE],
)
private val choices: MutableList<Choice>,
val choices: MutableList<Choice>,

@Column(name = "max_selection_count")
private val maxSelectableCount: Int,
val maxSelectableCount: Int,

@Enumerated(EnumType.STRING)
@Column(name = "choice_question_type")
private val choiceFormQuestionType: ChoiceFormQuestionType,
val choiceFormQuestionType: ChoiceFormQuestionType,
) : FormQuestionable(id, title, order, questionType, survey) {

init {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package me.nalab.survey.domain.survey

import me.nalab.core.data.common.TimeBaseEntity
import java.util.function.LongSupplier
import javax.persistence.*

@Entity
@Table(name = "form_question")
abstract class FormQuestionable(
@Id
@Column(name = "form_question_id")
open var id: Long? = null,
open val id: Long,

@Column(name = "title", nullable = false, length = 45)
protected open val title: String,
open val title: String,

@Column(name = "orders", nullable = false)
open val order: Int,

@Enumerated(EnumType.STRING)
@Column(name = "question_type")
protected open val questionType: QuestionType,
open val questionType: QuestionType,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "survey_id", nullable = false)
open val survey: Survey,
) : Comparable<FormQuestionable>, TimeBaseEntity() {

protected open fun cascadeId(idSupplier: LongSupplier) {
return
}

override fun compareTo(other: FormQuestionable): Int {
return Comparator.comparingInt { obj: FormQuestionable -> obj.order }
.compare(this, other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import javax.persistence.*

@Entity
class ShortFormQuestion(
id: Long? = null,
id: Long,
title: String,
order: Int,
questionType: QuestionType,
survey: Survey,

@Enumerated(EnumType.STRING)
@Column(name = "short_form_question_type")
private val shortFormQuestionType: ShortFormQuestionType,
val shortFormQuestionType: ShortFormQuestionType,
) : FormQuestionable(id, title, order, questionType, survey)
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import javax.persistence.*
class Survey(
@Id
@Column(name = "gallery_id")
private var id: Long? = null,
val id: Long,

@OneToMany(
mappedBy = "survey",
fetch = FetchType.LAZY,
cascade = [CascadeType.PERSIST, CascadeType.MERGE]
)
private val formQuestionables: MutableList<FormQuestionable>,
val formQuestionables: MutableList<FormQuestionable>,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_id")
private val target: Target,
val target: Target,
) : TimeBaseEntity() {

init {
Expand Down
15 changes: 9 additions & 6 deletions survey/src/main/kotlin/me/nalab/survey/domain/survey/Target.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ import javax.persistence.*
class Target(
@Id
@Column(name = "target_id")
private var id: Long? = null,
val id: Long,

@Column(name = "target_name", nullable = false)
private val nickname: String,
val nickname: String,

@Column(name = "job", columnDefinition = "TEXT")
private val job: String,
val job: String,

@Column(name = "image_url", columnDefinition = "TEXT")
private val imageUrl: String,
val imageUrl: String,

@Column(name = "position")
private var position: String? = null,
var position: String? = null,

@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, cascade = [CascadeType.ALL])
val survey: Survey,

@ElementCollection
@CollectionTable(name = "bookmarked_survey", joinColumns = [JoinColumn(name = "target_id")])
private val bookmarkedSurveys: MutableSet<SurveyBookmark> = NONE_BOOKMARKED_SURVEYS,
val bookmarkedSurveys: MutableSet<SurveyBookmark> = NONE_BOOKMARKED_SURVEYS,

@Version
@Column(name = "version")
Expand Down

0 comments on commit 535459f

Please sign in to comment.