diff --git a/src/main/java/io/oeid/mogakgo/domain/notification/application/NotificationService.java b/src/main/java/io/oeid/mogakgo/domain/notification/application/NotificationService.java new file mode 100644 index 00000000..7f3a7338 --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/domain/notification/application/NotificationService.java @@ -0,0 +1,30 @@ +package io.oeid.mogakgo.domain.notification.application; + +import io.oeid.mogakgo.domain.notification.application.dto.req.NotificationCreateRequest; +import io.oeid.mogakgo.domain.notification.application.dto.res.NotificationCreateResponse; +import io.oeid.mogakgo.domain.notification.domain.Notification; +import io.oeid.mogakgo.domain.notification.infrastructure.NotificationJpaRepository; +import io.oeid.mogakgo.domain.user.application.UserCommonService; +import io.oeid.mogakgo.domain.user.domain.User; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class NotificationService { + + private final UserCommonService userCommonService; + private final NotificationJpaRepository notificationRepository; + + @Transactional + public NotificationCreateResponse createNotification(NotificationCreateRequest request) { + log.info("createNotification request: {}", request); + User user = userCommonService.getUserById(request.getUserId()); + Notification notification = notificationRepository.save(request.toEntity(user)); + return NotificationCreateResponse.from(notification); + } +} diff --git a/src/main/java/io/oeid/mogakgo/domain/notification/application/dto/req/NotificationCreateRequest.java b/src/main/java/io/oeid/mogakgo/domain/notification/application/dto/req/NotificationCreateRequest.java new file mode 100644 index 00000000..6992d4d2 --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/domain/notification/application/dto/req/NotificationCreateRequest.java @@ -0,0 +1,26 @@ +package io.oeid.mogakgo.domain.notification.application.dto.req; + +import io.oeid.mogakgo.domain.notification.domain.Notification; +import io.oeid.mogakgo.domain.notification.domain.enums.NotificationTag; +import io.oeid.mogakgo.domain.user.domain.User; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class NotificationCreateRequest { + + private final Long userId; + private final NotificationTag notificationTag; + private final String detailData; + + public static NotificationCreateRequest of(Long userId, NotificationTag notificationTag, + String detailData) { + return new NotificationCreateRequest(userId, notificationTag, detailData); + } + + public Notification toEntity(User user) { + return Notification.of(user, notificationTag, detailData); + } +} diff --git a/src/main/java/io/oeid/mogakgo/domain/notification/application/dto/res/NotificationCreateResponse.java b/src/main/java/io/oeid/mogakgo/domain/notification/application/dto/res/NotificationCreateResponse.java new file mode 100644 index 00000000..c5b597ae --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/domain/notification/application/dto/res/NotificationCreateResponse.java @@ -0,0 +1,30 @@ +package io.oeid.mogakgo.domain.notification.application.dto.res; + +import io.oeid.mogakgo.domain.notification.domain.Notification; +import io.oeid.mogakgo.domain.notification.domain.enums.NotificationTag; +import java.time.LocalDateTime; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class NotificationCreateResponse { + + private final Long id; + private final Long userId; + private final NotificationTag notificationTag; + private final String detailData; + private final LocalDateTime createdAt; + private final Boolean checkedYn; + + public static NotificationCreateResponse from(Notification notification) { + return new NotificationCreateResponse( + notification.getId(), + notification.getUser().getId(), + notification.getNotificationTag(), + notification.getDetailData(), + notification.getCreatedAt(), + notification.getCheckedYn()); + } +} diff --git a/src/main/java/io/oeid/mogakgo/domain/notification/domain/Notification.java b/src/main/java/io/oeid/mogakgo/domain/notification/domain/Notification.java index 8df69683..5f39cd8c 100644 --- a/src/main/java/io/oeid/mogakgo/domain/notification/domain/Notification.java +++ b/src/main/java/io/oeid/mogakgo/domain/notification/domain/Notification.java @@ -43,6 +43,9 @@ public class Notification { @Column(name = "detail_data") private String detailData; + @Column(name = "checked_yn") + private Boolean checkedYn; + @CreationTimestamp @Column(name = "created_at") private LocalDateTime createdAt; @@ -51,6 +54,7 @@ private Notification(User user, NotificationTag notificationTag, String detailDa this.user = user; this.notificationTag = validateNotificationTag(notificationTag); this.detailData = validateDetailData(detailData); + this.checkedYn = false; } public static Notification of(User user, NotificationTag notificationTag, String detail) {