Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT/#51 Pull Notification 생성 구현 #85

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading