Skip to content

Commit

Permalink
[FEAT] Notification 생성 로직 구현 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
tidavid1 committed Feb 19, 2024
1 parent c108e17 commit ff01fda
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit ff01fda

Please sign in to comment.