Skip to content

Commit

Permalink
merge: (#260) Notification Model 설계 (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut authored Dec 30, 2022
2 parents d1976c0 + 104d758 commit 0550c90
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package team.comit.simtong.domain.notification.exception

import team.comit.simtong.global.exception.BusinessException

/**
*
* Notification Domain에서 발생하는 Exception을 관리하는 NotificationExceptions
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
sealed class NotificationExceptions(
override val status: Int,
override val message: String,
) : BusinessException(status, message) {

// 404
class NotFound(message: String = NOT_FOUND) : NotificationExceptions(404, message)

companion object {
private const val NOT_FOUND = "알림을 찾을 수 없습니다."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team.comit.simtong.domain.notification.model

import java.time.LocalDateTime
import java.util.UUID

/**
*
* 알림 Aggregate의 Root를 담당하는 Notification
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
data class Notification(
val id: UUID,

val title: String,

val content: String,

val type: NotificationType,

val identify: UUID?,

val createdAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.comit.simtong.domain.notification.model

import java.time.LocalDateTime
import java.util.UUID

/**
*
* 알림 Aggregate의 알림을 받은 수신자를 담당하는 NotificationReceiver
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
data class NotificationReceiver(
val userId: UUID,
val notificationId: UUID,
val checkedAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package team.comit.simtong.domain.notification.model

/**
*
* 알림의 종류를 구분하는 NotificationType
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
enum class NotificationType {

/**
* 메뉴 관련 알림
*/
MEAL,

/**
* 휴무일 관련 알림
*/
HOLIDAY,

/**
* 일정 관련 알림
*/
SCHEDULE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package team.comit.simtong.persistence.notification.entity

import team.comit.simtong.domain.notification.model.NotificationType
import team.comit.simtong.persistence.BaseEntity
import java.time.LocalDateTime
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.Table
import javax.validation.constraints.NotNull

/**
*
* 알림에 관해 관리하는 JPA 엔티티인 NotificationJpaEntity
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Entity
@Table(name = "tbl_notification")
class NotificationJpaEntity(
override val id: UUID,

@field:NotNull
@Column(columnDefinition = "VARCHAR(50)")
val title: String,

@field:NotNull
@Column(columnDefinition = "VARCHAR(255)")
val content: String,

@field:NotNull
@Column(columnDefinition = "VARCHAR(20)")
@Enumerated(EnumType.STRING)
val type: NotificationType,

@Column(columnDefinition = "BINARY(16)")
val identify: UUID?,

@field:NotNull
override val createdAt: LocalDateTime

) : BaseEntity(id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package team.comit.simtong.persistence.notification.entity

import team.comit.simtong.persistence.user.entity.UserJpaEntity
import java.io.Serializable
import java.time.LocalDateTime
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.persistence.EmbeddedId
import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.MapsId
import javax.persistence.Table

/**
*
* 알림 수신자에 관해 관리하는 JPA 엔티티인 NotificationReceiverJpaEntity
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Entity
@Table(name = "tbl_notification_receiver")
class NotificationReceiverJpaEntity(
@EmbeddedId
val notificationReceiverId: Id,

@MapsId("userId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", columnDefinition = "BINARY(16)", nullable = false)
val user: UserJpaEntity,

@MapsId("notificationId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "notification_id", columnDefinition = "BINARY(16)", nullable = false)
val notification: NotificationJpaEntity,

val checkedAt: LocalDateTime?
) {

/**
*
* 알림 엔티티의 기본키인 NotificationReceiver Id
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Embeddable
data class Id(
@Column(columnDefinition = "BINARY(16)", nullable = false)
val userId: UUID,

@Column(columnDefinition = "BINARY(16)", nullable = false)
val notificationId: UUID
) : Serializable
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.comit.simtong.persistence.notification.mapper

import org.mapstruct.Mapper
import team.comit.simtong.domain.notification.model.Notification
import team.comit.simtong.persistence.GenericMapper
import team.comit.simtong.persistence.notification.entity.NotificationJpaEntity

/**
*
* Notification Entity와 Notification Aggregate를 변환하는 NotificationMapper
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Mapper
abstract class NotificationMapper : GenericMapper<NotificationJpaEntity, Notification> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package team.comit.simtong.persistence.notification.mapper

import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings
import org.springframework.beans.factory.annotation.Autowired
import team.comit.simtong.domain.notification.model.NotificationReceiver
import team.comit.simtong.persistence.GenericMapper
import team.comit.simtong.persistence.notification.entity.NotificationReceiverJpaEntity
import team.comit.simtong.persistence.notification.repository.NotificationJpaRepository
import team.comit.simtong.persistence.spot.SpotJpaRepository
import team.comit.simtong.persistence.user.repository.UserJpaRepository

/**
*
* NotificationReceiver Entity와 NotificationReceiver Aggregate를 변환하는 NotificationReceiverMapper
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Mapper
abstract class NotificationReceiverMapper : GenericMapper<NotificationReceiverJpaEntity, NotificationReceiver> {

@Autowired
protected lateinit var notificationRepository: NotificationJpaRepository

@Autowired
protected lateinit var userRepository: UserJpaRepository

@Mappings(
Mapping(
target = "notificationReceiverId",
expression = "java(new NotificationReceiverJpaEntity.Id(model.getUserId(), model.getNotificationId()))"
),
Mapping(
target = "user",
expression = "java(userRepository.findById(model.getUserId()).orElse(null))"
),
Mapping(
target = "notification",
expression = "java(notificationRepository.findById(model.getNotificationId()).orElse(null))"
)
)
abstract override fun toEntity(model: NotificationReceiver): NotificationReceiverJpaEntity

@Mappings(
Mapping(target = "userId", expression = "java(entity.getNotificationReceiverId().getUserId())"),
Mapping(target = "notificationId", expression = "java(entity.getNotificationReceiverId().getNotificationId())")
)
abstract override fun toDomain(entity: NotificationReceiverJpaEntity?): NotificationReceiver?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.comit.simtong.persistence.notification.repository

import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import team.comit.simtong.persistence.notification.entity.NotificationJpaEntity
import java.util.UUID

/**
*
* 알림의 Spring Repository를 담당하는 NotificationJpaRepository
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Repository
interface NotificationJpaRepository : CrudRepository<NotificationJpaEntity, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package team.comit.simtong.persistence.notification.repository

import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import team.comit.simtong.persistence.notification.entity.NotificationReceiverJpaEntity

/**
*
* 알림 수신자의 Spring Repository를 담당하는 NotificationReceiverRepository
*
* @author kimbeomjin
* @date 2022/12/29
* @version 1.1.0
**/
@Repository
interface NotificationReceiverRepository : CrudRepository<NotificationReceiverJpaEntity, NotificationReceiverJpaEntity.Id> {
}

0 comments on commit 0550c90

Please sign in to comment.