From 03a8a31d28a53c66865f11432694fb6f3d4c79a4 Mon Sep 17 00:00:00 2001 From: hej090224 Date: Wed, 8 Jul 2026 10:29:19 +0900 Subject: [PATCH 1/3] feat: #10 :: add time capsule domain entities and repositories --- .../mudda/domain/block/domain/entity/Block.kt | 55 +++++++ .../domain/repository/BlockRepository.kt | 9 ++ .../domain/friend/domain/entity/Friend.kt | 65 ++++++++ .../domain/repository/FriendRepository.kt | 11 ++ .../domain/friend/domain/type/FriendStatus.kt | 7 + .../mudda/domain/media/domain/entity/Media.kt | 76 +++++++++ .../domain/repository/MediaRepository.kt | 6 + .../domain/media/domain/type/MediaType.kt | 7 + .../domain/member/domain/entity/Member.kt | 63 ++++++++ .../domain/repository/MemberRepository.kt | 12 ++ .../member/domain/type/ProfileVisibility.kt | 7 + .../domain/entity/Notification.kt | 59 +++++++ .../repository/NotificationRepository.kt | 9 ++ .../domain/type/NotificationType.kt | 12 ++ .../domain/report/domain/entity/Report.kt | 65 ++++++++ .../domain/repository/ReportRepository.kt | 13 ++ .../domain/report/domain/type/ReportReason.kt | 9 ++ .../report/domain/type/ReportTargetType.kt | 7 + .../domain/entity/CapsuleHistory.kt | 75 +++++++++ .../timecapsule/domain/entity/CapsuleOpen.kt | 74 +++++++++ .../domain/entity/CapsuleRecipient.kt | 83 ++++++++++ .../timecapsule/domain/entity/Guestbook.kt | 76 +++++++++ .../timecapsule/domain/entity/TimeCapsule.kt | 125 +++++++++++++++ .../repository/CapsuleHistoryRepository.kt | 6 + .../repository/CapsuleOpenRepository.kt | 10 ++ .../repository/CapsuleRecipientRepository.kt | 11 ++ .../domain/repository/GuestbookRepository.kt | 8 + .../repository/TimeCapsuleRepository.kt | 10 ++ .../domain/type/CapsuleEventType.kt | 10 ++ .../domain/type/CapsuleLockType.kt | 8 + .../domain/type/CapsuleVisibility.kt | 7 + .../domain/type/TimeCapsuleType.kt | 8 + .../V2__create_time_capsule_domain_tables.sql | 150 ++++++++++++++++++ 33 files changed, 1153 insertions(+) create mode 100644 src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/block/domain/repository/BlockRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/friend/domain/repository/FriendRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/media/domain/repository/MediaRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/member/domain/repository/MemberRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/notification/domain/repository/NotificationRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleHistoryRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleOpenRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleRecipientRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/GuestbookRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/TimeCapsuleRepository.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleVisibility.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt create mode 100644 src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql diff --git a/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt b/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt new file mode 100644 index 0000000..5121d79 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt @@ -0,0 +1,55 @@ +package team.cklob.mudda.domain.block.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import jakarta.persistence.UniqueConstraint +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import java.time.LocalDateTime + +@Entity +@Table( + name = "tbl_block", + uniqueConstraints = [ + UniqueConstraint( + name = "uq_block_blocker_blocked", + columnNames = ["blocker_id", "blocked_id"], + ), + ], +) +class Block( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "blocker_id", nullable = false) + val blocker: Member, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "blocked_id", nullable = false) + val blocked: Member, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(emptyMember(), emptyMember()) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } + + companion object { + private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/block/domain/repository/BlockRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/block/domain/repository/BlockRepository.kt new file mode 100644 index 0000000..982d782 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/block/domain/repository/BlockRepository.kt @@ -0,0 +1,9 @@ +package team.cklob.mudda.domain.block.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.block.domain.entity.Block + +interface BlockRepository : JpaRepository { + fun existsByBlockerIdAndBlockedId(blockerId: Long, blockedId: Long): Boolean + fun findByBlockerId(blockerId: Long): List +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt new file mode 100644 index 0000000..c2936af --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt @@ -0,0 +1,65 @@ +package team.cklob.mudda.domain.friend.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import jakarta.persistence.UniqueConstraint +import team.cklob.mudda.domain.friend.domain.type.FriendStatus +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import java.time.LocalDateTime + +@Entity +@Table( + name = "tbl_friend", + uniqueConstraints = [ + UniqueConstraint( + name = "uq_friend_requester_receiver", + columnNames = ["requester_id", "receiver_id"], + ), + ], +) +class Friend( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "requester_id", nullable = false) + val requester: Member, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "receiver_id", nullable = false) + val receiver: Member, + + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 20) + val status: FriendStatus, + + @Column(name = "accepted_at") + val acceptedAt: LocalDateTime? = null, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(emptyMember(), emptyMember(), FriendStatus.PENDING, null) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } + + companion object { + private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/repository/FriendRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/repository/FriendRepository.kt new file mode 100644 index 0000000..54d59d4 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/repository/FriendRepository.kt @@ -0,0 +1,11 @@ +package team.cklob.mudda.domain.friend.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.friend.domain.entity.Friend +import java.util.Optional + +interface FriendRepository : JpaRepository { + fun findByRequesterIdOrReceiverId(requesterId: Long, receiverId: Long): List + fun findByRequesterIdAndReceiverId(requesterId: Long, receiverId: Long): Optional + fun existsByRequesterIdAndReceiverId(requesterId: Long, receiverId: Long): Boolean +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt new file mode 100644 index 0000000..42a3160 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.friend.domain.type + +enum class FriendStatus { + PENDING, + ACCEPTED, + REJECTED, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt b/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt new file mode 100644 index 0000000..d04ff3d --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt @@ -0,0 +1,76 @@ +package team.cklob.mudda.domain.media.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import team.cklob.mudda.domain.media.domain.type.MediaType +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType +import java.time.LocalDateTime + +@Entity +@Table(name = "tbl_media") +class Media( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "time_capsule_id", nullable = false) + val timeCapsule: TimeCapsule, + + @Enumerated(EnumType.STRING) + @Column(name = "media_type", nullable = false, length = 20) + val mediaType: MediaType, + + @Column(name = "media_url", nullable = false, length = 255) + val mediaUrl: String, + + @Column(name = "s3_key", nullable = false, length = 255) + val s3Key: String, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(emptyTimeCapsule(), MediaType.IMAGE, "", "") + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } + + companion object { + private fun emptyTimeCapsule() = TimeCapsule( + Member("", "", "", null, null, ProfileVisibility.PRIVATE), + "", + null, + TimeCapsuleType.NORMAL, + CapsuleVisibility.PRIVATE, + CapsuleLockType.NONE, + null, + null, + null, + org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), + null, + 0, + LocalDateTime.now(), + false, + false, + false, + ) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/media/domain/repository/MediaRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/media/domain/repository/MediaRepository.kt new file mode 100644 index 0000000..8264d89 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/media/domain/repository/MediaRepository.kt @@ -0,0 +1,6 @@ +package team.cklob.mudda.domain.media.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.media.domain.entity.Media + +interface MediaRepository : JpaRepository diff --git a/src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaType.kt b/src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaType.kt new file mode 100644 index 0000000..3935c25 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaType.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.media.domain.type + +enum class MediaType { + IMAGE, + VIDEO, + VOICE, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt new file mode 100644 index 0000000..4ef37fe --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt @@ -0,0 +1,63 @@ +package team.cklob.mudda.domain.member.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.PrePersist +import jakarta.persistence.PreUpdate +import jakarta.persistence.Table +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import java.time.LocalDateTime + +@Entity +@Table(name = "tbl_member") +class Member( + @Column(nullable = false, length = 30) + val name: String, + + @Column(nullable = false, unique = true, length = 30) + val nickname: String, + + @Column(nullable = false, unique = true, length = 255) + val email: String, + + @Column(name = "profile_image_url", length = 255) + val profileImageUrl: String? = null, + + @Column(length = 100) + val bio: String? = null, + + @Enumerated(EnumType.STRING) + @Column(name = "profile_visibility", nullable = false, length = 20) + val profileVisibility: ProfileVisibility, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + @Column(name = "updated_at", nullable = false) + var updatedAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this("", "", "", null, null, ProfileVisibility.PRIVATE) + + @PrePersist + fun prePersist() { + val now = LocalDateTime.now() + createdAt = now + updatedAt = now + } + + @PreUpdate + fun preUpdate() { + updatedAt = LocalDateTime.now() + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/repository/MemberRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/repository/MemberRepository.kt new file mode 100644 index 0000000..ee87ca2 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/repository/MemberRepository.kt @@ -0,0 +1,12 @@ +package team.cklob.mudda.domain.member.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.member.domain.entity.Member +import java.util.Optional + +interface MemberRepository : JpaRepository { + fun existsByEmail(email: String): Boolean + fun existsByNickname(nickname: String): Boolean + fun findByEmail(email: String): Optional + fun findByNickname(nickname: String): Optional +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt new file mode 100644 index 0000000..5b76ffd --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.member.domain.type + +enum class ProfileVisibility { + PRIVATE, + FRIEND, + PUBLIC, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt new file mode 100644 index 0000000..e60bd97 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt @@ -0,0 +1,59 @@ +package team.cklob.mudda.domain.notification.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.notification.domain.type.NotificationType +import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule +import java.time.LocalDateTime + +@Entity +@Table(name = "tbl_notification") +class Notification( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "recipient_id", nullable = false) + val recipient: Member, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "time_capsule_id") + val timeCapsule: TimeCapsule? = null, + + @Enumerated(EnumType.STRING) + @Column(name = "notification_type", nullable = false, length = 30) + val notificationType: NotificationType, + + @Column(nullable = false, length = 255) + val title: String, + + @Column(nullable = false, length = 255) + val body: String, + + @Column(name = "is_read", nullable = false) + val isRead: Boolean = false, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(Member("", "", "", null, null, ProfileVisibility.PRIVATE), null, NotificationType.SYSTEM, "", "", false) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/repository/NotificationRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/repository/NotificationRepository.kt new file mode 100644 index 0000000..095f6f0 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/repository/NotificationRepository.kt @@ -0,0 +1,9 @@ +package team.cklob.mudda.domain.notification.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.notification.domain.entity.Notification + +interface NotificationRepository : JpaRepository { + fun findByRecipientIdOrderByCreatedAtDesc(recipientId: Long): List + fun findByRecipientIdAndIsReadFalseOrderByCreatedAtDesc(recipientId: Long): List +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt new file mode 100644 index 0000000..f03e80a --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt @@ -0,0 +1,12 @@ +package team.cklob.mudda.domain.notification.domain.type + +enum class NotificationType { + FRIEND_REQUEST, + FRIEND_ACCEPTED, + CAPSULE_RECEIVED, + CAPSULE_OPENED, + CAPSULE_FOUND, + CAPSULE_EXPIRED, + GUESTBOOK_CREATED, + SYSTEM, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt new file mode 100644 index 0000000..5f528b8 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt @@ -0,0 +1,65 @@ +package team.cklob.mudda.domain.report.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import jakarta.persistence.UniqueConstraint +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.report.domain.type.ReportReason +import team.cklob.mudda.domain.report.domain.type.ReportTargetType +import java.time.LocalDateTime + +@Entity +@Table( + name = "tbl_report", + uniqueConstraints = [ + UniqueConstraint( + name = "uq_report_reporter_target", + columnNames = ["reporter_id", "target_type", "target_id"], + ), + ], +) +class Report( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "reporter_id", nullable = false) + val reporter: Member, + + @Enumerated(EnumType.STRING) + @Column(name = "target_type", nullable = false, length = 30) + val targetType: ReportTargetType, + + @Column(name = "target_id", nullable = false) + val targetId: Long, + + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 30) + val reason: ReportReason, + + @Column(length = 500) + val description: String? = null, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(Member("", "", "", null, null, ProfileVisibility.PRIVATE), ReportTargetType.MEMBER, 0L, ReportReason.OTHER, null) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt new file mode 100644 index 0000000..6f95fae --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt @@ -0,0 +1,13 @@ +package team.cklob.mudda.domain.report.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.report.domain.entity.Report +import team.cklob.mudda.domain.report.domain.type.ReportTargetType + +interface ReportRepository : JpaRepository { + fun existsByReporterIdAndTargetTypeAndTargetId( + reporterId: Long, + targetType: ReportTargetType, + targetId: Long, + ): Boolean +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt new file mode 100644 index 0000000..4f3bf17 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt @@ -0,0 +1,9 @@ +package team.cklob.mudda.domain.report.domain.type + +enum class ReportReason { + SPAM, + HARASSMENT, + INAPPROPRIATE, + PRIVACY, + OTHER, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt new file mode 100644 index 0000000..a2ec6e9 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.report.domain.type + +enum class ReportTargetType { + TIME_CAPSULE, + GUESTBOOK, + MEMBER, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt new file mode 100644 index 0000000..45b292d --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt @@ -0,0 +1,75 @@ +package team.cklob.mudda.domain.timecapsule.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleEventType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType +import java.time.LocalDateTime + +@Entity +@Table(name = "tbl_capsule_history") +class CapsuleHistory( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "time_capsule_id", nullable = false) + val timeCapsule: TimeCapsule, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + val member: Member, + + @Enumerated(EnumType.STRING) + @Column(name = "event_type", nullable = false, length = 20) + val eventType: CapsuleEventType, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(emptyTimeCapsule(), emptyMember(), CapsuleEventType.CREATED) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } + + companion object { + private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + + private fun emptyTimeCapsule() = TimeCapsule( + emptyMember(), + "", + null, + TimeCapsuleType.NORMAL, + CapsuleVisibility.PRIVATE, + CapsuleLockType.NONE, + null, + null, + null, + org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), + null, + 0, + LocalDateTime.now(), + false, + false, + false, + ) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt new file mode 100644 index 0000000..20676a2 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt @@ -0,0 +1,74 @@ +package team.cklob.mudda.domain.timecapsule.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.Table +import jakarta.persistence.UniqueConstraint +import org.locationtech.jts.geom.Point +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType +import java.time.LocalDateTime + +@Entity +@Table( + name = "tbl_capsule_open", + uniqueConstraints = [ + UniqueConstraint( + name = "uq_capsule_open_time_capsule_member", + columnNames = ["time_capsule_id", "member_id"], + ), + ], +) +class CapsuleOpen( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "time_capsule_id", nullable = false) + val timeCapsule: TimeCapsule, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + val member: Member, + + @Column(name = "opened_at", nullable = false) + val openedAt: LocalDateTime, + + @Column(name = "open_location", columnDefinition = "geometry(Point,4326)") + val openLocation: Point? = null, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + protected constructor() : this(emptyTimeCapsule(), emptyMember(), LocalDateTime.now(), null) + + companion object { + private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + + private fun emptyTimeCapsule() = TimeCapsule( + emptyMember(), + "", + null, + TimeCapsuleType.NORMAL, + CapsuleVisibility.PRIVATE, + CapsuleLockType.NONE, + null, + null, + null, + org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), + null, + 0, + LocalDateTime.now(), + false, + false, + false, + ) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt new file mode 100644 index 0000000..e30d4e0 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt @@ -0,0 +1,83 @@ +package team.cklob.mudda.domain.timecapsule.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import jakarta.persistence.UniqueConstraint +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType +import java.time.LocalDateTime + +@Entity +@Table( + name = "tbl_capsule_recipient", + uniqueConstraints = [ + UniqueConstraint( + name = "uq_capsule_recipient_time_capsule_member", + columnNames = ["time_capsule_id", "member_id"], + ), + ], +) +class CapsuleRecipient( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + val member: Member, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "time_capsule_id", nullable = false) + val timeCapsule: TimeCapsule, + + @Column(name = "has_opened", nullable = false) + val hasOpened: Boolean = false, + + @Column(name = "opened_at") + val openedAt: LocalDateTime? = null, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(emptyMember(), emptyTimeCapsule(), false, null) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } + + companion object { + private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + + private fun emptyTimeCapsule() = TimeCapsule( + emptyMember(), + "", + null, + TimeCapsuleType.NORMAL, + CapsuleVisibility.PRIVATE, + CapsuleLockType.NONE, + null, + null, + null, + org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), + null, + 0, + LocalDateTime.now(), + false, + false, + false, + ) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt new file mode 100644 index 0000000..b24ba23 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt @@ -0,0 +1,76 @@ +package team.cklob.mudda.domain.timecapsule.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.Lob +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.Table +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType +import java.time.LocalDateTime + +@Entity +@Table(name = "tbl_guestbook") +class Guestbook( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "time_capsule_id", nullable = false) + val timeCapsule: TimeCapsule, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + val member: Member, + + @Lob + @Column(nullable = false, columnDefinition = "TEXT") + val content: String, + + @Column(name = "is_deleted", nullable = false) + val isDeleted: Boolean = false, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this(emptyTimeCapsule(), emptyMember(), "", false) + + @PrePersist + fun prePersist() { + createdAt = LocalDateTime.now() + } + + companion object { + private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + + private fun emptyTimeCapsule() = TimeCapsule( + emptyMember(), + "", + null, + TimeCapsuleType.NORMAL, + CapsuleVisibility.PRIVATE, + CapsuleLockType.NONE, + null, + null, + null, + org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), + null, + 0, + LocalDateTime.now(), + false, + false, + false, + ) + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt new file mode 100644 index 0000000..7b954ec --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt @@ -0,0 +1,125 @@ +package team.cklob.mudda.domain.timecapsule.domain.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.FetchType +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.Lob +import jakarta.persistence.ManyToOne +import jakarta.persistence.PrePersist +import jakarta.persistence.PreUpdate +import jakarta.persistence.Table +import org.locationtech.jts.geom.Coordinate +import org.locationtech.jts.geom.GeometryFactory +import org.locationtech.jts.geom.Point +import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.domain.member.domain.type.ProfileVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType +import java.time.LocalDateTime + +@Entity +@Table(name = "tbl_time_capsule") +class TimeCapsule( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + val member: Member, + + @Column(nullable = false, length = 255) + val name: String, + + @Lob + @Column(columnDefinition = "TEXT") + val content: String? = null, + + @Enumerated(EnumType.STRING) + @Column(name = "time_capsule_type", nullable = false, length = 20) + val timeCapsuleType: TimeCapsuleType, + + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 20) + val visibility: CapsuleVisibility, + + @Enumerated(EnumType.STRING) + @Column(name = "lock_type", nullable = false, length = 20) + val lockType: CapsuleLockType, + + @Column(name = "password_hash", length = 255) + val passwordHash: String? = null, + + @Column(length = 255) + val question: String? = null, + + @Column(name = "answer_hash", length = 255) + val answerHash: String? = null, + + @Column(nullable = false, columnDefinition = "geometry(Point,4326)") + val location: Point, + + @Column(name = "location_name", length = 255) + val locationName: String? = null, + + @Column(name = "open_radius_meter", nullable = false) + val openRadiusMeter: Int, + + @Column(name = "expires_at", nullable = false) + val expiresAt: LocalDateTime, + + @Column(name = "is_anonymous", nullable = false) + val isAnonymous: Boolean, + + @Column(name = "is_feed_public", nullable = false) + val isFeedPublic: Boolean, + + @Column(name = "is_deleted", nullable = false) + val isDeleted: Boolean = false, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long? = null, +) { + @Column(name = "created_at", nullable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + @Column(name = "updated_at", nullable = false) + var updatedAt: LocalDateTime = LocalDateTime.now() + protected set + + protected constructor() : this( + Member("", "", "", null, null, ProfileVisibility.PRIVATE), + "", + null, + TimeCapsuleType.NORMAL, + CapsuleVisibility.PRIVATE, + CapsuleLockType.NONE, + null, + null, + null, + GeometryFactory().createPoint(Coordinate(0.0, 0.0)), + null, + 0, + LocalDateTime.now(), + false, + false, + false, + ) + + @PrePersist + fun prePersist() { + val now = LocalDateTime.now() + createdAt = now + updatedAt = now + } + + @PreUpdate + fun preUpdate() { + updatedAt = LocalDateTime.now() + } +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleHistoryRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleHistoryRepository.kt new file mode 100644 index 0000000..1029d54 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleHistoryRepository.kt @@ -0,0 +1,6 @@ +package team.cklob.mudda.domain.timecapsule.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.timecapsule.domain.entity.CapsuleHistory + +interface CapsuleHistoryRepository : JpaRepository diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleOpenRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleOpenRepository.kt new file mode 100644 index 0000000..8b3f8de --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleOpenRepository.kt @@ -0,0 +1,10 @@ +package team.cklob.mudda.domain.timecapsule.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.timecapsule.domain.entity.CapsuleOpen +import java.util.Optional + +interface CapsuleOpenRepository : JpaRepository { + fun findByTimeCapsuleIdAndMemberId(timeCapsuleId: Long, memberId: Long): Optional + fun existsByTimeCapsuleIdAndMemberId(timeCapsuleId: Long, memberId: Long): Boolean +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleRecipientRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleRecipientRepository.kt new file mode 100644 index 0000000..3b46af4 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/CapsuleRecipientRepository.kt @@ -0,0 +1,11 @@ +package team.cklob.mudda.domain.timecapsule.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.timecapsule.domain.entity.CapsuleRecipient +import java.util.Optional + +interface CapsuleRecipientRepository : JpaRepository { + fun findByMemberId(memberId: Long): List + fun findByTimeCapsuleIdAndMemberId(timeCapsuleId: Long, memberId: Long): Optional + fun existsByTimeCapsuleIdAndMemberId(timeCapsuleId: Long, memberId: Long): Boolean +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/GuestbookRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/GuestbookRepository.kt new file mode 100644 index 0000000..66ed702 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/GuestbookRepository.kt @@ -0,0 +1,8 @@ +package team.cklob.mudda.domain.timecapsule.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.timecapsule.domain.entity.Guestbook + +interface GuestbookRepository : JpaRepository { + fun findByTimeCapsuleIdAndIsDeletedFalseOrderByCreatedAtDesc(timeCapsuleId: Long): List +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/TimeCapsuleRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/TimeCapsuleRepository.kt new file mode 100644 index 0000000..f2bc349 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/repository/TimeCapsuleRepository.kt @@ -0,0 +1,10 @@ +package team.cklob.mudda.domain.timecapsule.domain.repository + +import org.springframework.data.jpa.repository.JpaRepository +import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule +import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility + +interface TimeCapsuleRepository : JpaRepository { + fun findByMemberIdAndIsDeletedFalse(memberId: Long): List + fun findByVisibilityAndIsDeletedFalse(visibility: CapsuleVisibility): List +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt new file mode 100644 index 0000000..254f886 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt @@ -0,0 +1,10 @@ +package team.cklob.mudda.domain.timecapsule.domain.type + +enum class CapsuleEventType { + CREATED, + UPDATED, + OPENED, + FOUND, + EXPIRED, + DELETED, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt new file mode 100644 index 0000000..8492e39 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt @@ -0,0 +1,8 @@ +package team.cklob.mudda.domain.timecapsule.domain.type + +enum class CapsuleLockType { + NONE, + PASSWORD, + QUESTION, + LOCATION, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleVisibility.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleVisibility.kt new file mode 100644 index 0000000..62be607 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleVisibility.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.timecapsule.domain.type + +enum class CapsuleVisibility { + PRIVATE, + FRIEND, + PUBLIC, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt new file mode 100644 index 0000000..da8674e --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt @@ -0,0 +1,8 @@ +package team.cklob.mudda.domain.timecapsule.domain.type + +enum class TimeCapsuleType { + NORMAL, + GROUP, + ANONYMITY, + PROMISE, +} diff --git a/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql b/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql new file mode 100644 index 0000000..b0b0266 --- /dev/null +++ b/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql @@ -0,0 +1,150 @@ +CREATE TABLE tbl_member ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name VARCHAR(30) NOT NULL, + nickname VARCHAR(30) NOT NULL, + email VARCHAR(255) NOT NULL, + profile_image_url VARCHAR(255), + bio VARCHAR(100), + profile_visibility VARCHAR(20) NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + updated_at TIMESTAMP(6) NOT NULL, + CONSTRAINT uq_member_nickname UNIQUE (nickname), + CONSTRAINT uq_member_email UNIQUE (email) +); + +CREATE TABLE tbl_time_capsule ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + member_id BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + content TEXT, + time_capsule_type VARCHAR(20) NOT NULL, + visibility VARCHAR(20) NOT NULL, + lock_type VARCHAR(20) NOT NULL, + password_hash VARCHAR(255), + question VARCHAR(255), + answer_hash VARCHAR(255), + location GEOMETRY(Point, 4326) NOT NULL, + location_name VARCHAR(255), + open_radius_meter INTEGER NOT NULL, + expires_at TIMESTAMP(6) NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + updated_at TIMESTAMP(6) NOT NULL, + is_anonymous BOOLEAN NOT NULL, + is_feed_public BOOLEAN NOT NULL, + is_deleted BOOLEAN NOT NULL, + CONSTRAINT fk_time_capsule_member FOREIGN KEY (member_id) REFERENCES tbl_member (id) +); + +CREATE TABLE tbl_media ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + time_capsule_id BIGINT NOT NULL, + media_type VARCHAR(20) NOT NULL, + media_url VARCHAR(255) NOT NULL, + s3_key VARCHAR(255) NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + CONSTRAINT fk_media_time_capsule FOREIGN KEY (time_capsule_id) REFERENCES tbl_time_capsule (id) +); + +CREATE TABLE tbl_capsule_recipient ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + member_id BIGINT NOT NULL, + time_capsule_id BIGINT NOT NULL, + has_opened BOOLEAN NOT NULL, + opened_at TIMESTAMP(6), + created_at TIMESTAMP(6) NOT NULL, + CONSTRAINT fk_capsule_recipient_member FOREIGN KEY (member_id) REFERENCES tbl_member (id), + CONSTRAINT fk_capsule_recipient_time_capsule FOREIGN KEY (time_capsule_id) REFERENCES tbl_time_capsule (id), + CONSTRAINT uq_capsule_recipient_time_capsule_member UNIQUE (time_capsule_id, member_id) +); + +CREATE TABLE tbl_capsule_open ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + time_capsule_id BIGINT NOT NULL, + member_id BIGINT NOT NULL, + opened_at TIMESTAMP(6) NOT NULL, + open_location GEOMETRY(Point, 4326), + CONSTRAINT fk_capsule_open_time_capsule FOREIGN KEY (time_capsule_id) REFERENCES tbl_time_capsule (id), + CONSTRAINT fk_capsule_open_member FOREIGN KEY (member_id) REFERENCES tbl_member (id), + CONSTRAINT uq_capsule_open_time_capsule_member UNIQUE (time_capsule_id, member_id) +); + +CREATE TABLE tbl_capsule_history ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + time_capsule_id BIGINT NOT NULL, + member_id BIGINT NOT NULL, + event_type VARCHAR(20) NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + CONSTRAINT fk_capsule_history_time_capsule FOREIGN KEY (time_capsule_id) REFERENCES tbl_time_capsule (id), + CONSTRAINT fk_capsule_history_member FOREIGN KEY (member_id) REFERENCES tbl_member (id) +); + +CREATE TABLE tbl_guestbook ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + time_capsule_id BIGINT NOT NULL, + member_id BIGINT NOT NULL, + content TEXT NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + is_deleted BOOLEAN NOT NULL, + CONSTRAINT fk_guestbook_time_capsule FOREIGN KEY (time_capsule_id) REFERENCES tbl_time_capsule (id), + CONSTRAINT fk_guestbook_member FOREIGN KEY (member_id) REFERENCES tbl_member (id) +); + +CREATE TABLE tbl_friend ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + requester_id BIGINT NOT NULL, + receiver_id BIGINT NOT NULL, + status VARCHAR(20) NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + accepted_at TIMESTAMP(6), + CONSTRAINT fk_friend_requester FOREIGN KEY (requester_id) REFERENCES tbl_member (id), + CONSTRAINT fk_friend_receiver FOREIGN KEY (receiver_id) REFERENCES tbl_member (id), + CONSTRAINT uq_friend_requester_receiver UNIQUE (requester_id, receiver_id) +); + +CREATE TABLE tbl_notification ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + recipient_id BIGINT NOT NULL, + time_capsule_id BIGINT, + notification_type VARCHAR(30) NOT NULL, + title VARCHAR(255) NOT NULL, + body VARCHAR(255) NOT NULL, + is_read BOOLEAN NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + CONSTRAINT fk_notification_recipient FOREIGN KEY (recipient_id) REFERENCES tbl_member (id), + CONSTRAINT fk_notification_time_capsule FOREIGN KEY (time_capsule_id) REFERENCES tbl_time_capsule (id) +); + +CREATE TABLE tbl_report ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + reporter_id BIGINT NOT NULL, + target_type VARCHAR(30) NOT NULL, + target_id BIGINT NOT NULL, + reason VARCHAR(30) NOT NULL, + description VARCHAR(500), + created_at TIMESTAMP(6) NOT NULL, + CONSTRAINT fk_report_reporter FOREIGN KEY (reporter_id) REFERENCES tbl_member (id), + CONSTRAINT uq_report_reporter_target UNIQUE (reporter_id, target_type, target_id) +); + +CREATE TABLE tbl_block ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + blocker_id BIGINT NOT NULL, + blocked_id BIGINT NOT NULL, + created_at TIMESTAMP(6) NOT NULL, + CONSTRAINT fk_block_blocker FOREIGN KEY (blocker_id) REFERENCES tbl_member (id), + CONSTRAINT fk_block_blocked FOREIGN KEY (blocked_id) REFERENCES tbl_member (id), + CONSTRAINT uq_block_blocker_blocked UNIQUE (blocker_id, blocked_id) +); + +CREATE INDEX idx_time_capsule_member ON tbl_time_capsule (member_id); +CREATE INDEX idx_time_capsule_visibility_deleted ON tbl_time_capsule (visibility, is_deleted); +CREATE INDEX idx_time_capsule_location ON tbl_time_capsule USING GIST (location); +CREATE INDEX idx_media_time_capsule ON tbl_media (time_capsule_id); +CREATE INDEX idx_capsule_recipient_member ON tbl_capsule_recipient (member_id); +CREATE INDEX idx_capsule_open_member ON tbl_capsule_open (member_id); +CREATE INDEX idx_capsule_history_time_capsule ON tbl_capsule_history (time_capsule_id); +CREATE INDEX idx_guestbook_time_capsule_deleted_created ON tbl_guestbook (time_capsule_id, is_deleted, created_at DESC); +CREATE INDEX idx_friend_receiver ON tbl_friend (receiver_id); +CREATE INDEX idx_notification_recipient_created ON tbl_notification (recipient_id, created_at DESC); +CREATE INDEX idx_report_reporter ON tbl_report (reporter_id); +CREATE INDEX idx_block_blocker ON tbl_block (blocker_id); From 28d7e8f8ba08dc823704f6946d13fa28966ccd50 Mon Sep 17 00:00:00 2001 From: hej090224 Date: Wed, 8 Jul 2026 10:39:31 +0900 Subject: [PATCH 2/3] refactor: #10 :: align domain enums with shared definitions --- .../mudda/domain/block/domain/entity/Block.kt | 3 +-- .../mudda/domain/friend/domain/entity/Friend.kt | 9 ++++----- .../friend/domain/type/FriendRequestStatus.kt | 7 +++++++ .../domain/friend/domain/type/FriendRequestType.kt | 6 ++++++ .../domain/friend/domain/type/FriendStatus.kt | 7 ++++--- .../mudda/domain/media/domain/entity/Media.kt | 6 ++---- .../domain/media/domain/type/MediaTargetType.kt | 6 ++++++ .../mudda/domain/member/domain/entity/Member.kt | 8 ++------ .../mudda/domain/member/domain/type/Gender.kt | 6 ++++++ .../domain/member/domain/type/OAuthProvider.kt | 7 +++++++ .../domain/member/domain/type/ProfileVisibility.kt | 7 ------- .../notification/domain/entity/Notification.kt | 3 +-- .../domain/type/NotificationTargetType.kt | 7 +++++++ .../notification/domain/type/NotificationType.kt | 10 +++------- .../mudda/domain/report/domain/entity/Report.kt | 13 +++---------- .../report/domain/repository/ReportRepository.kt | 3 +-- .../domain/report/domain/type/ReportReason.kt | 9 --------- .../domain/report/domain/type/ReportTargetType.kt | 7 ------- .../timecapsule/domain/entity/CapsuleHistory.kt | 14 ++++---------- .../timecapsule/domain/entity/CapsuleOpen.kt | 6 ++---- .../timecapsule/domain/entity/CapsuleRecipient.kt | 6 ++---- .../domain/timecapsule/domain/entity/Guestbook.kt | 6 ++---- .../timecapsule/domain/entity/TimeCapsule.kt | 9 +++------ .../timecapsule/domain/type/CapsuleEventType.kt | 10 ---------- .../timecapsule/domain/type/CapsuleLockType.kt | 1 - .../timecapsule/domain/type/TimeCapsuleType.kt | 8 -------- 26 files changed, 73 insertions(+), 111 deletions(-) create mode 100644 src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestStatus.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaTargetType.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/member/domain/type/Gender.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/member/domain/type/OAuthProvider.kt delete mode 100644 src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt create mode 100644 src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationTargetType.kt delete mode 100644 src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt delete mode 100644 src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt delete mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt delete mode 100644 src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt diff --git a/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt b/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt index 5121d79..dd4b4ea 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt @@ -12,7 +12,6 @@ import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import java.time.LocalDateTime @Entity @@ -50,6 +49,6 @@ class Block( } companion object { - private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + private fun emptyMember() = Member("", "", "", null, null, "") } } diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt index c2936af..ad3a402 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt @@ -13,9 +13,8 @@ import jakarta.persistence.ManyToOne import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint -import team.cklob.mudda.domain.friend.domain.type.FriendStatus +import team.cklob.mudda.domain.friend.domain.type.FriendRequestStatus import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import java.time.LocalDateTime @Entity @@ -39,7 +38,7 @@ class Friend( @Enumerated(EnumType.STRING) @Column(nullable = false, length = 20) - val status: FriendStatus, + val status: FriendRequestStatus, @Column(name = "accepted_at") val acceptedAt: LocalDateTime? = null, @@ -52,7 +51,7 @@ class Friend( var createdAt: LocalDateTime = LocalDateTime.now() protected set - protected constructor() : this(emptyMember(), emptyMember(), FriendStatus.PENDING, null) + protected constructor() : this(emptyMember(), emptyMember(), FriendRequestStatus.PENDING, null) @PrePersist fun prePersist() { @@ -60,6 +59,6 @@ class Friend( } companion object { - private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + private fun emptyMember() = Member("", "", "", null, null, "") } } diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestStatus.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestStatus.kt new file mode 100644 index 0000000..5f23284 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestStatus.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.friend.domain.type + +enum class FriendRequestStatus { + PENDING, + ACCEPTED, + REJECTED, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestType.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestType.kt new file mode 100644 index 0000000..decdf88 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendRequestType.kt @@ -0,0 +1,6 @@ +package team.cklob.mudda.domain.friend.domain.type + +enum class FriendRequestType { + RECEIVED, + SENT, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt index 42a3160..4e8bff9 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/type/FriendStatus.kt @@ -1,7 +1,8 @@ package team.cklob.mudda.domain.friend.domain.type enum class FriendStatus { - PENDING, - ACCEPTED, - REJECTED, + NONE, + FRIEND, + REQUESTED, + RECEIVED, } diff --git a/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt b/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt index d04ff3d..0534d48 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt @@ -14,11 +14,9 @@ import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.media.domain.type.MediaType import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType import java.time.LocalDateTime @Entity @@ -55,10 +53,10 @@ class Media( companion object { private fun emptyTimeCapsule() = TimeCapsule( - Member("", "", "", null, null, ProfileVisibility.PRIVATE), + Member("", "", "", null, null, ""), "", null, - TimeCapsuleType.NORMAL, + "", CapsuleVisibility.PRIVATE, CapsuleLockType.NONE, null, diff --git a/src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaTargetType.kt b/src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaTargetType.kt new file mode 100644 index 0000000..1431cde --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/media/domain/type/MediaTargetType.kt @@ -0,0 +1,6 @@ +package team.cklob.mudda.domain.media.domain.type + +enum class MediaTargetType { + PROFILE, + CAPSULE, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt index 4ef37fe..d0f741e 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt @@ -2,15 +2,12 @@ package team.cklob.mudda.domain.member.domain.entity import jakarta.persistence.Column import jakarta.persistence.Entity -import jakarta.persistence.EnumType -import jakarta.persistence.Enumerated import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.PrePersist import jakarta.persistence.PreUpdate import jakarta.persistence.Table -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import java.time.LocalDateTime @Entity @@ -31,9 +28,8 @@ class Member( @Column(length = 100) val bio: String? = null, - @Enumerated(EnumType.STRING) @Column(name = "profile_visibility", nullable = false, length = 20) - val profileVisibility: ProfileVisibility, + val profileVisibility: String, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -47,7 +43,7 @@ class Member( var updatedAt: LocalDateTime = LocalDateTime.now() protected set - protected constructor() : this("", "", "", null, null, ProfileVisibility.PRIVATE) + protected constructor() : this("", "", "", null, null, "") @PrePersist fun prePersist() { diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/Gender.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/Gender.kt new file mode 100644 index 0000000..c9f17df --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/Gender.kt @@ -0,0 +1,6 @@ +package team.cklob.mudda.domain.member.domain.type + +enum class Gender { + MALE, + FEMALE, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/OAuthProvider.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/OAuthProvider.kt new file mode 100644 index 0000000..38cd3c5 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/OAuthProvider.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.member.domain.type + +enum class OAuthProvider { + KAKAO, + GOOGLE, + APPLE, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt deleted file mode 100644 index 5b76ffd..0000000 --- a/src/main/kotlin/team/cklob/mudda/domain/member/domain/type/ProfileVisibility.kt +++ /dev/null @@ -1,7 +0,0 @@ -package team.cklob.mudda.domain.member.domain.type - -enum class ProfileVisibility { - PRIVATE, - FRIEND, - PUBLIC, -} diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt index e60bd97..d2eb38a 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt @@ -13,7 +13,6 @@ import jakarta.persistence.ManyToOne import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import team.cklob.mudda.domain.notification.domain.type.NotificationType import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule import java.time.LocalDateTime @@ -50,7 +49,7 @@ class Notification( var createdAt: LocalDateTime = LocalDateTime.now() protected set - protected constructor() : this(Member("", "", "", null, null, ProfileVisibility.PRIVATE), null, NotificationType.SYSTEM, "", "", false) + protected constructor() : this(Member("", "", "", null, null, ""), null, NotificationType.FRIEND_REQUESTED, "", "", false) @PrePersist fun prePersist() { diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationTargetType.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationTargetType.kt new file mode 100644 index 0000000..f238276 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationTargetType.kt @@ -0,0 +1,7 @@ +package team.cklob.mudda.domain.notification.domain.type + +enum class NotificationTargetType { + CAPSULE, + MEMBER, + FRIEND_REQUEST, +} diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt index f03e80a..0290892 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/type/NotificationType.kt @@ -1,12 +1,8 @@ package team.cklob.mudda.domain.notification.domain.type enum class NotificationType { - FRIEND_REQUEST, - FRIEND_ACCEPTED, - CAPSULE_RECEIVED, CAPSULE_OPENED, - CAPSULE_FOUND, - CAPSULE_EXPIRED, - GUESTBOOK_CREATED, - SYSTEM, + CAPSULE_RECEIVED, + FRIEND_REQUESTED, + FRIEND_ACCEPTED, } diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt index 5f528b8..d75975b 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt @@ -2,8 +2,6 @@ package team.cklob.mudda.domain.report.domain.entity import jakarta.persistence.Column import jakarta.persistence.Entity -import jakarta.persistence.EnumType -import jakarta.persistence.Enumerated import jakarta.persistence.FetchType import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType @@ -14,9 +12,6 @@ import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility -import team.cklob.mudda.domain.report.domain.type.ReportReason -import team.cklob.mudda.domain.report.domain.type.ReportTargetType import java.time.LocalDateTime @Entity @@ -34,16 +29,14 @@ class Report( @JoinColumn(name = "reporter_id", nullable = false) val reporter: Member, - @Enumerated(EnumType.STRING) @Column(name = "target_type", nullable = false, length = 30) - val targetType: ReportTargetType, + val targetType: String, @Column(name = "target_id", nullable = false) val targetId: Long, - @Enumerated(EnumType.STRING) @Column(nullable = false, length = 30) - val reason: ReportReason, + val reason: String, @Column(length = 500) val description: String? = null, @@ -56,7 +49,7 @@ class Report( var createdAt: LocalDateTime = LocalDateTime.now() protected set - protected constructor() : this(Member("", "", "", null, null, ProfileVisibility.PRIVATE), ReportTargetType.MEMBER, 0L, ReportReason.OTHER, null) + protected constructor() : this(Member("", "", "", null, null, ""), "", 0L, "", null) @PrePersist fun prePersist() { diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt index 6f95fae..44eb2db 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/repository/ReportRepository.kt @@ -2,12 +2,11 @@ package team.cklob.mudda.domain.report.domain.repository import org.springframework.data.jpa.repository.JpaRepository import team.cklob.mudda.domain.report.domain.entity.Report -import team.cklob.mudda.domain.report.domain.type.ReportTargetType interface ReportRepository : JpaRepository { fun existsByReporterIdAndTargetTypeAndTargetId( reporterId: Long, - targetType: ReportTargetType, + targetType: String, targetId: Long, ): Boolean } diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt deleted file mode 100644 index 4f3bf17..0000000 --- a/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportReason.kt +++ /dev/null @@ -1,9 +0,0 @@ -package team.cklob.mudda.domain.report.domain.type - -enum class ReportReason { - SPAM, - HARASSMENT, - INAPPROPRIATE, - PRIVACY, - OTHER, -} diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt deleted file mode 100644 index a2ec6e9..0000000 --- a/src/main/kotlin/team/cklob/mudda/domain/report/domain/type/ReportTargetType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package team.cklob.mudda.domain.report.domain.type - -enum class ReportTargetType { - TIME_CAPSULE, - GUESTBOOK, - MEMBER, -} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt index 45b292d..81902fa 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt @@ -2,8 +2,6 @@ package team.cklob.mudda.domain.timecapsule.domain.entity import jakarta.persistence.Column import jakarta.persistence.Entity -import jakarta.persistence.EnumType -import jakarta.persistence.Enumerated import jakarta.persistence.FetchType import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType @@ -13,11 +11,8 @@ import jakarta.persistence.ManyToOne import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleEventType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType import java.time.LocalDateTime @Entity @@ -31,9 +26,8 @@ class CapsuleHistory( @JoinColumn(name = "member_id", nullable = false) val member: Member, - @Enumerated(EnumType.STRING) @Column(name = "event_type", nullable = false, length = 20) - val eventType: CapsuleEventType, + val eventType: String, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -43,7 +37,7 @@ class CapsuleHistory( var createdAt: LocalDateTime = LocalDateTime.now() protected set - protected constructor() : this(emptyTimeCapsule(), emptyMember(), CapsuleEventType.CREATED) + protected constructor() : this(emptyTimeCapsule(), emptyMember(), "") @PrePersist fun prePersist() { @@ -51,13 +45,13 @@ class CapsuleHistory( } companion object { - private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + private fun emptyMember() = Member("", "", "", null, null, "") private fun emptyTimeCapsule() = TimeCapsule( emptyMember(), "", null, - TimeCapsuleType.NORMAL, + "", CapsuleVisibility.PRIVATE, CapsuleLockType.NONE, null, diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt index 20676a2..f3392b0 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt @@ -12,10 +12,8 @@ import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import org.locationtech.jts.geom.Point import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType import java.time.LocalDateTime @Entity @@ -50,13 +48,13 @@ class CapsuleOpen( protected constructor() : this(emptyTimeCapsule(), emptyMember(), LocalDateTime.now(), null) companion object { - private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + private fun emptyMember() = Member("", "", "", null, null, "") private fun emptyTimeCapsule() = TimeCapsule( emptyMember(), "", null, - TimeCapsuleType.NORMAL, + "", CapsuleVisibility.PRIVATE, CapsuleLockType.NONE, null, diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt index e30d4e0..337bb22 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt @@ -12,10 +12,8 @@ import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType import java.time.LocalDateTime @Entity @@ -59,13 +57,13 @@ class CapsuleRecipient( } companion object { - private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + private fun emptyMember() = Member("", "", "", null, null, "") private fun emptyTimeCapsule() = TimeCapsule( emptyMember(), "", null, - TimeCapsuleType.NORMAL, + "", CapsuleVisibility.PRIVATE, CapsuleLockType.NONE, null, diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt index b24ba23..1671fab 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt @@ -12,10 +12,8 @@ import jakarta.persistence.ManyToOne import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType import java.time.LocalDateTime @Entity @@ -52,13 +50,13 @@ class Guestbook( } companion object { - private fun emptyMember() = Member("", "", "", null, null, ProfileVisibility.PRIVATE) + private fun emptyMember() = Member("", "", "", null, null, "") private fun emptyTimeCapsule() = TimeCapsule( emptyMember(), "", null, - TimeCapsuleType.NORMAL, + "", CapsuleVisibility.PRIVATE, CapsuleLockType.NONE, null, diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt index 7b954ec..f34fcad 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt @@ -18,10 +18,8 @@ import org.locationtech.jts.geom.Coordinate import org.locationtech.jts.geom.GeometryFactory import org.locationtech.jts.geom.Point import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.member.domain.type.ProfileVisibility import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import team.cklob.mudda.domain.timecapsule.domain.type.TimeCapsuleType import java.time.LocalDateTime @Entity @@ -38,9 +36,8 @@ class TimeCapsule( @Column(columnDefinition = "TEXT") val content: String? = null, - @Enumerated(EnumType.STRING) @Column(name = "time_capsule_type", nullable = false, length = 20) - val timeCapsuleType: TimeCapsuleType, + val timeCapsuleType: String, @Enumerated(EnumType.STRING) @Column(nullable = false, length = 20) @@ -93,10 +90,10 @@ class TimeCapsule( protected set protected constructor() : this( - Member("", "", "", null, null, ProfileVisibility.PRIVATE), + Member("", "", "", null, null, ""), "", null, - TimeCapsuleType.NORMAL, + "", CapsuleVisibility.PRIVATE, CapsuleLockType.NONE, null, diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt deleted file mode 100644 index 254f886..0000000 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleEventType.kt +++ /dev/null @@ -1,10 +0,0 @@ -package team.cklob.mudda.domain.timecapsule.domain.type - -enum class CapsuleEventType { - CREATED, - UPDATED, - OPENED, - FOUND, - EXPIRED, - DELETED, -} diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt index 8492e39..ae105c2 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/CapsuleLockType.kt @@ -4,5 +4,4 @@ enum class CapsuleLockType { NONE, PASSWORD, QUESTION, - LOCATION, } diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt deleted file mode 100644 index da8674e..0000000 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/type/TimeCapsuleType.kt +++ /dev/null @@ -1,8 +0,0 @@ -package team.cklob.mudda.domain.timecapsule.domain.type - -enum class TimeCapsuleType { - NORMAL, - GROUP, - ANONYMITY, - PROMISE, -} From 1af70ed1d08fe7b35a1c80ee07580c91ee786d7a Mon Sep 17 00:00:00 2001 From: hej090224 Date: Wed, 8 Jul 2026 10:45:47 +0900 Subject: [PATCH 3/3] refactor: #10 :: address entity review feedback --- .../team/cklob/mudda/MuddaApplication.kt | 2 + .../mudda/domain/block/domain/entity/Block.kt | 20 +------- .../domain/friend/domain/entity/Friend.kt | 23 ++------- .../mudda/domain/media/domain/entity/Media.kt | 40 +--------------- .../domain/member/domain/entity/Member.kt | 38 +++------------ .../domain/entity/Notification.kt | 18 ++----- .../domain/report/domain/entity/Report.kt | 16 +------ .../domain/entity/CapsuleHistory.kt | 41 +--------------- .../timecapsule/domain/entity/CapsuleOpen.kt | 29 +---------- .../domain/entity/CapsuleRecipient.kt | 44 ++--------------- .../timecapsule/domain/entity/Guestbook.kt | 43 ++--------------- .../timecapsule/domain/entity/TimeCapsule.kt | 48 ++----------------- .../common/entity/BaseCreatedAtEntity.kt | 18 +++++++ .../global/common/entity/BaseTimeEntity.kt | 24 ++++++++++ .../V2__create_time_capsule_domain_tables.sql | 2 - 15 files changed, 77 insertions(+), 329 deletions(-) create mode 100644 src/main/kotlin/team/cklob/mudda/global/common/entity/BaseCreatedAtEntity.kt create mode 100644 src/main/kotlin/team/cklob/mudda/global/common/entity/BaseTimeEntity.kt diff --git a/src/main/kotlin/team/cklob/mudda/MuddaApplication.kt b/src/main/kotlin/team/cklob/mudda/MuddaApplication.kt index 06cf583..1173478 100644 --- a/src/main/kotlin/team/cklob/mudda/MuddaApplication.kt +++ b/src/main/kotlin/team/cklob/mudda/MuddaApplication.kt @@ -2,7 +2,9 @@ package team.cklob.mudda import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.data.jpa.repository.config.EnableJpaAuditing +@EnableJpaAuditing @SpringBootApplication class MuddaApplication diff --git a/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt b/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt index dd4b4ea..cdb7165 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/block/domain/entity/Block.kt @@ -8,11 +8,10 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.member.domain.entity.Member -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity @Entity @Table( @@ -36,19 +35,4 @@ class Block( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(emptyMember(), emptyMember()) - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } - - companion object { - private fun emptyMember() = Member("", "", "", null, null, "") - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt index ad3a402..75b7595 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/friend/domain/entity/Friend.kt @@ -10,11 +10,11 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.friend.domain.type.FriendRequestStatus import team.cklob.mudda.domain.member.domain.entity.Member +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity import java.time.LocalDateTime @Entity @@ -38,27 +38,12 @@ class Friend( @Enumerated(EnumType.STRING) @Column(nullable = false, length = 20) - val status: FriendRequestStatus, + var status: FriendRequestStatus, @Column(name = "accepted_at") - val acceptedAt: LocalDateTime? = null, + var acceptedAt: LocalDateTime? = null, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(emptyMember(), emptyMember(), FriendRequestStatus.PENDING, null) - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } - - companion object { - private fun emptyMember() = Member("", "", "", null, null, "") - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt b/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt index 0534d48..e291822 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/media/domain/entity/Media.kt @@ -10,14 +10,10 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.media.domain.type.MediaType -import team.cklob.mudda.domain.member.domain.entity.Member import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity @Entity @Table(name = "tbl_media") @@ -39,36 +35,4 @@ class Media( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(emptyTimeCapsule(), MediaType.IMAGE, "", "") - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } - - companion object { - private fun emptyTimeCapsule() = TimeCapsule( - Member("", "", "", null, null, ""), - "", - null, - "", - CapsuleVisibility.PRIVATE, - CapsuleLockType.NONE, - null, - null, - null, - org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), - null, - 0, - LocalDateTime.now(), - false, - false, - false, - ) - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt b/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt index d0f741e..07b1cef 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/member/domain/entity/Member.kt @@ -5,55 +5,31 @@ import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType import jakarta.persistence.Id -import jakarta.persistence.PrePersist -import jakarta.persistence.PreUpdate import jakarta.persistence.Table -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseTimeEntity @Entity @Table(name = "tbl_member") class Member( @Column(nullable = false, length = 30) - val name: String, + var name: String, @Column(nullable = false, unique = true, length = 30) - val nickname: String, + var nickname: String, @Column(nullable = false, unique = true, length = 255) val email: String, @Column(name = "profile_image_url", length = 255) - val profileImageUrl: String? = null, + var profileImageUrl: String? = null, @Column(length = 100) - val bio: String? = null, + var bio: String? = null, @Column(name = "profile_visibility", nullable = false, length = 20) - val profileVisibility: String, + var profileVisibility: String, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - @Column(name = "updated_at", nullable = false) - var updatedAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this("", "", "", null, null, "") - - @PrePersist - fun prePersist() { - val now = LocalDateTime.now() - createdAt = now - updatedAt = now - } - - @PreUpdate - fun preUpdate() { - updatedAt = LocalDateTime.now() - } -} +) : BaseTimeEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt index d2eb38a..2cdf764 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/notification/domain/entity/Notification.kt @@ -10,12 +10,11 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.member.domain.entity.Member import team.cklob.mudda.domain.notification.domain.type.NotificationType import team.cklob.mudda.domain.timecapsule.domain.entity.TimeCapsule -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity @Entity @Table(name = "tbl_notification") @@ -39,20 +38,9 @@ class Notification( val body: String, @Column(name = "is_read", nullable = false) - val isRead: Boolean = false, + var isRead: Boolean = false, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(Member("", "", "", null, null, ""), null, NotificationType.FRIEND_REQUESTED, "", "", false) - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt b/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt index d75975b..7e727ff 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/report/domain/entity/Report.kt @@ -8,11 +8,10 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.member.domain.entity.Member -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity @Entity @Table( @@ -44,15 +43,4 @@ class Report( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(Member("", "", "", null, null, ""), "", 0L, "", null) - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt index 81902fa..9c57ddd 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleHistory.kt @@ -8,12 +8,9 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity @Entity @Table(name = "tbl_capsule_history") @@ -32,38 +29,4 @@ class CapsuleHistory( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(emptyTimeCapsule(), emptyMember(), "") - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } - - companion object { - private fun emptyMember() = Member("", "", "", null, null, "") - - private fun emptyTimeCapsule() = TimeCapsule( - emptyMember(), - "", - null, - "", - CapsuleVisibility.PRIVATE, - CapsuleLockType.NONE, - null, - null, - null, - org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), - null, - 0, - LocalDateTime.now(), - false, - false, - false, - ) - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt index f3392b0..8c34e8a 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleOpen.kt @@ -12,8 +12,6 @@ import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import org.locationtech.jts.geom.Point import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility import java.time.LocalDateTime @Entity @@ -44,29 +42,4 @@ class CapsuleOpen( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - protected constructor() : this(emptyTimeCapsule(), emptyMember(), LocalDateTime.now(), null) - - companion object { - private fun emptyMember() = Member("", "", "", null, null, "") - - private fun emptyTimeCapsule() = TimeCapsule( - emptyMember(), - "", - null, - "", - CapsuleVisibility.PRIVATE, - CapsuleLockType.NONE, - null, - null, - null, - org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), - null, - 0, - LocalDateTime.now(), - false, - false, - false, - ) - } -} +) diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt index 337bb22..b029aef 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/CapsuleRecipient.kt @@ -8,12 +8,10 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import jakarta.persistence.UniqueConstraint import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity import java.time.LocalDateTime @Entity @@ -36,46 +34,12 @@ class CapsuleRecipient( val timeCapsule: TimeCapsule, @Column(name = "has_opened", nullable = false) - val hasOpened: Boolean = false, + var hasOpened: Boolean = false, @Column(name = "opened_at") - val openedAt: LocalDateTime? = null, + var openedAt: LocalDateTime? = null, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(emptyMember(), emptyTimeCapsule(), false, null) - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } - - companion object { - private fun emptyMember() = Member("", "", "", null, null, "") - - private fun emptyTimeCapsule() = TimeCapsule( - emptyMember(), - "", - null, - "", - CapsuleVisibility.PRIVATE, - CapsuleLockType.NONE, - null, - null, - null, - org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), - null, - 0, - LocalDateTime.now(), - false, - false, - false, - ) - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt index 1671fab..528627a 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/Guestbook.kt @@ -9,12 +9,9 @@ import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.Lob import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist import jakarta.persistence.Table import team.cklob.mudda.domain.member.domain.entity.Member -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType -import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility -import java.time.LocalDateTime +import team.cklob.mudda.global.common.entity.BaseCreatedAtEntity @Entity @Table(name = "tbl_guestbook") @@ -32,43 +29,9 @@ class Guestbook( val content: String, @Column(name = "is_deleted", nullable = false) - val isDeleted: Boolean = false, + var isDeleted: Boolean = false, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this(emptyTimeCapsule(), emptyMember(), "", false) - - @PrePersist - fun prePersist() { - createdAt = LocalDateTime.now() - } - - companion object { - private fun emptyMember() = Member("", "", "", null, null, "") - - private fun emptyTimeCapsule() = TimeCapsule( - emptyMember(), - "", - null, - "", - CapsuleVisibility.PRIVATE, - CapsuleLockType.NONE, - null, - null, - null, - org.locationtech.jts.geom.GeometryFactory().createPoint(org.locationtech.jts.geom.Coordinate(0.0, 0.0)), - null, - 0, - LocalDateTime.now(), - false, - false, - false, - ) - } -} +) : BaseCreatedAtEntity() diff --git a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt index f34fcad..11af3d5 100644 --- a/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt +++ b/src/main/kotlin/team/cklob/mudda/domain/timecapsule/domain/entity/TimeCapsule.kt @@ -11,15 +11,12 @@ import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.Lob import jakarta.persistence.ManyToOne -import jakarta.persistence.PrePersist -import jakarta.persistence.PreUpdate import jakarta.persistence.Table -import org.locationtech.jts.geom.Coordinate -import org.locationtech.jts.geom.GeometryFactory import org.locationtech.jts.geom.Point import team.cklob.mudda.domain.member.domain.entity.Member import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleLockType import team.cklob.mudda.domain.timecapsule.domain.type.CapsuleVisibility +import team.cklob.mudda.global.common.entity.BaseTimeEntity import java.time.LocalDateTime @Entity @@ -75,48 +72,9 @@ class TimeCapsule( val isFeedPublic: Boolean, @Column(name = "is_deleted", nullable = false) - val isDeleted: Boolean = false, + var isDeleted: Boolean = false, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, -) { - @Column(name = "created_at", nullable = false) - var createdAt: LocalDateTime = LocalDateTime.now() - protected set - - @Column(name = "updated_at", nullable = false) - var updatedAt: LocalDateTime = LocalDateTime.now() - protected set - - protected constructor() : this( - Member("", "", "", null, null, ""), - "", - null, - "", - CapsuleVisibility.PRIVATE, - CapsuleLockType.NONE, - null, - null, - null, - GeometryFactory().createPoint(Coordinate(0.0, 0.0)), - null, - 0, - LocalDateTime.now(), - false, - false, - false, - ) - - @PrePersist - fun prePersist() { - val now = LocalDateTime.now() - createdAt = now - updatedAt = now - } - - @PreUpdate - fun preUpdate() { - updatedAt = LocalDateTime.now() - } -} +) : BaseTimeEntity() diff --git a/src/main/kotlin/team/cklob/mudda/global/common/entity/BaseCreatedAtEntity.kt b/src/main/kotlin/team/cklob/mudda/global/common/entity/BaseCreatedAtEntity.kt new file mode 100644 index 0000000..1b50b8d --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/global/common/entity/BaseCreatedAtEntity.kt @@ -0,0 +1,18 @@ +package team.cklob.mudda.global.common.entity + +import jakarta.persistence.Column +import jakarta.persistence.EntityListeners +import jakarta.persistence.MappedSuperclass +import org.springframework.data.annotation.CreatedDate +import org.springframework.data.jpa.domain.support.AuditingEntityListener +import java.time.LocalDateTime + +@MappedSuperclass +@EntityListeners(AuditingEntityListener::class) +abstract class BaseCreatedAtEntity { + + @CreatedDate + @Column(name = "created_at", nullable = false, updatable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set +} diff --git a/src/main/kotlin/team/cklob/mudda/global/common/entity/BaseTimeEntity.kt b/src/main/kotlin/team/cklob/mudda/global/common/entity/BaseTimeEntity.kt new file mode 100644 index 0000000..7d6af39 --- /dev/null +++ b/src/main/kotlin/team/cklob/mudda/global/common/entity/BaseTimeEntity.kt @@ -0,0 +1,24 @@ +package team.cklob.mudda.global.common.entity + +import jakarta.persistence.Column +import jakarta.persistence.EntityListeners +import jakarta.persistence.MappedSuperclass +import org.springframework.data.annotation.CreatedDate +import org.springframework.data.annotation.LastModifiedDate +import org.springframework.data.jpa.domain.support.AuditingEntityListener +import java.time.LocalDateTime + +@MappedSuperclass +@EntityListeners(AuditingEntityListener::class) +abstract class BaseTimeEntity { + + @CreatedDate + @Column(name = "created_at", nullable = false, updatable = false) + var createdAt: LocalDateTime = LocalDateTime.now() + protected set + + @LastModifiedDate + @Column(name = "updated_at", nullable = false) + var updatedAt: LocalDateTime = LocalDateTime.now() + protected set +} diff --git a/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql b/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql index b0b0266..9e35937 100644 --- a/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql +++ b/src/main/resources/db/migration/V2__create_time_capsule_domain_tables.sql @@ -146,5 +146,3 @@ CREATE INDEX idx_capsule_history_time_capsule ON tbl_capsule_history (time_capsu CREATE INDEX idx_guestbook_time_capsule_deleted_created ON tbl_guestbook (time_capsule_id, is_deleted, created_at DESC); CREATE INDEX idx_friend_receiver ON tbl_friend (receiver_id); CREATE INDEX idx_notification_recipient_created ON tbl_notification (recipient_id, created_at DESC); -CREATE INDEX idx_report_reporter ON tbl_report (reporter_id); -CREATE INDEX idx_block_blocker ON tbl_block (blocker_id);