-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/io/oeid/mogakgo/domain/notification/application/NotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...va/io/oeid/mogakgo/domain/notification/application/dto/req/NotificationCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...a/io/oeid/mogakgo/domain/notification/application/dto/res/NotificationCreateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters