From daccfcd4534badbd21644bf1dccf306cd9ce1e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B5=AC=ED=99=98=EC=A4=80/=EB=AA=A8=EA=B1=B4?= Date: Sun, 11 Feb 2024 15:36:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEAT]:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 9 +++++++ .../dto/NotificationResponseDTO.java | 8 ++++++ .../notification/entity/Notification.java | 25 +++++++++++++++++++ .../notification/entity/NotificationType.java | 5 ++++ .../repository/NotificationRepository.java | 9 +++++++ .../service/NotificationService.java | 9 +++++++ 6 files changed, 65 insertions(+) create mode 100644 src/main/java/org/example/tree/domain/notification/controller/NotificationController.java create mode 100644 src/main/java/org/example/tree/domain/notification/dto/NotificationResponseDTO.java create mode 100644 src/main/java/org/example/tree/domain/notification/entity/Notification.java create mode 100644 src/main/java/org/example/tree/domain/notification/entity/NotificationType.java create mode 100644 src/main/java/org/example/tree/domain/notification/repository/NotificationRepository.java create mode 100644 src/main/java/org/example/tree/domain/notification/service/NotificationService.java diff --git a/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java b/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java new file mode 100644 index 0000000..88638fb --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java @@ -0,0 +1,9 @@ +package org.example.tree.domain.notification.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class NotificationController { +} diff --git a/src/main/java/org/example/tree/domain/notification/dto/NotificationResponseDTO.java b/src/main/java/org/example/tree/domain/notification/dto/NotificationResponseDTO.java new file mode 100644 index 0000000..510b546 --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/dto/NotificationResponseDTO.java @@ -0,0 +1,8 @@ +package org.example.tree.domain.notification.dto; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class NotificationResponseDTO { +} diff --git a/src/main/java/org/example/tree/domain/notification/entity/Notification.java b/src/main/java/org/example/tree/domain/notification/entity/Notification.java new file mode 100644 index 0000000..c02242c --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/entity/Notification.java @@ -0,0 +1,25 @@ +package org.example.tree.domain.notification.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Notification { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private NotificationType type; + + private String title; + + private String message; +} diff --git a/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java b/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java new file mode 100644 index 0000000..bd77c79 --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java @@ -0,0 +1,5 @@ +package org.example.tree.domain.notification.entity; + +public enum NotificationType { + INVITATION, COMMENT, LIKE +} diff --git a/src/main/java/org/example/tree/domain/notification/repository/NotificationRepository.java b/src/main/java/org/example/tree/domain/notification/repository/NotificationRepository.java new file mode 100644 index 0000000..aaba283 --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/repository/NotificationRepository.java @@ -0,0 +1,9 @@ +package org.example.tree.domain.notification.repository; + +import org.example.tree.domain.notification.entity.Notification; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface NotificationRepository extends JpaRepository { +} diff --git a/src/main/java/org/example/tree/domain/notification/service/NotificationService.java b/src/main/java/org/example/tree/domain/notification/service/NotificationService.java new file mode 100644 index 0000000..c5827ab --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/service/NotificationService.java @@ -0,0 +1,9 @@ +package org.example.tree.domain.notification.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class NotificationService { +} From c37cc8eff878860e17e0c513dc7295a42aaff726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B5=AC=ED=99=98=EC=A4=80/=EB=AA=A8=EA=B1=B4?= Date: Fri, 1 Mar 2024 17:07:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FEAT]/#35-=EC=95=8C=EB=A6=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=B3=B8=20=ED=8B=80=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 35 ++++++++++++++++++- .../converter/NotificationConverter.java | 19 ++++++++++ .../dto/NotificationRequestDTO.java | 9 +++++ .../notification/entity/Notification.java | 10 +++++- .../notification/entity/NotificationType.java | 2 +- .../service/NotificationCommandService.java | 4 +++ .../service/NotificationQueryService.java | 4 +++ .../service/NotificationService.java | 17 +++++++++ 8 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/example/tree/domain/notification/converter/NotificationConverter.java create mode 100644 src/main/java/org/example/tree/domain/notification/dto/NotificationRequestDTO.java create mode 100644 src/main/java/org/example/tree/domain/notification/service/NotificationCommandService.java create mode 100644 src/main/java/org/example/tree/domain/notification/service/NotificationQueryService.java diff --git a/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java b/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java index 88638fb..0589cc0 100644 --- a/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java +++ b/src/main/java/org/example/tree/domain/notification/controller/NotificationController.java @@ -1,9 +1,42 @@ package org.example.tree.domain.notification.controller; +import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RestController; +import org.example.tree.domain.notification.dto.NotificationResponseDTO; +import org.example.tree.domain.notification.service.NotificationService; +import org.example.tree.global.common.ApiResponse; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor +@RequestMapping("/notifications") public class NotificationController { + + private final NotificationService notificationService; + + @Operation(summary = "알림 생성 테스트") + @PostMapping("/test") + public ApiResponse sendNotification( + @RequestBody final NotificationRequestDTO.sendNotification request) + { + return ApiResponse.onSuccess(notificationService.sendNotification(request)); + } + + @Operation(summary = "전체 알림 조회", description = "유저가 받은 알림들을 조회합니다.") + @GetMapping + public ApiResponse> getNotifications( + @RequestHeader("Authorization") final String header) + { + String token = header.replace("Bearer ", ""); + return ApiResponse.onSuccess(notificationService.getUserNotifications(token)); + } + + @Operation(summary = "특정 알림 조회", description = "유저가 받은 알림 중 하나를 조회합니다.") + @GetMapping("/{notificationId}") + public ApiResponse getNotification( + @PathVariable final Long notificationId) + { + return ApiResponse.onSuccess(notificationService.getNotification(notificationId)); + } + } diff --git a/src/main/java/org/example/tree/domain/notification/converter/NotificationConverter.java b/src/main/java/org/example/tree/domain/notification/converter/NotificationConverter.java new file mode 100644 index 0000000..48a037b --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/converter/NotificationConverter.java @@ -0,0 +1,19 @@ +package org.example.tree.domain.notification.converter; + +import org.example.tree.domain.member.entity.Member; +import org.example.tree.domain.notification.entity.Notification; +import org.example.tree.domain.notification.entity.NotificationType; +import org.springframework.stereotype.Component; + +@Component +public class NotificationConverter { + + public Notification toNotification(String title, String message, String type, Member receiver) { + return Notification.builder() + .title(title) + .message(message) + .type(NotificationType.valueOf(type)) + .receiver(receiver) + .build(); + } +} diff --git a/src/main/java/org/example/tree/domain/notification/dto/NotificationRequestDTO.java b/src/main/java/org/example/tree/domain/notification/dto/NotificationRequestDTO.java new file mode 100644 index 0000000..7a24880 --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/dto/NotificationRequestDTO.java @@ -0,0 +1,9 @@ +package org.example.tree.domain.notification.dto; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) + +public class NotificationRequestDTO { +} diff --git a/src/main/java/org/example/tree/domain/notification/entity/Notification.java b/src/main/java/org/example/tree/domain/notification/entity/Notification.java index c02242c..8b9c9aa 100644 --- a/src/main/java/org/example/tree/domain/notification/entity/Notification.java +++ b/src/main/java/org/example/tree/domain/notification/entity/Notification.java @@ -5,13 +5,15 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.example.tree.common.BaseDateTimeEntity; +import org.example.tree.domain.member.entity.Member; @Entity @Getter @Builder @AllArgsConstructor @NoArgsConstructor -public class Notification { +public class Notification extends BaseDateTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -22,4 +24,10 @@ public class Notification { private String title; private String message; + + private boolean readStatus = false; + + @ManyToOne + @JoinColumn(name = "receiver_id") + private Member receiver; // 알림을 받는 사용자 } diff --git a/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java b/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java index bd77c79..f1e9fb9 100644 --- a/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java +++ b/src/main/java/org/example/tree/domain/notification/entity/NotificationType.java @@ -1,5 +1,5 @@ package org.example.tree.domain.notification.entity; public enum NotificationType { - INVITATION, COMMENT, LIKE + INVITATION, COMMENT, REACTION } diff --git a/src/main/java/org/example/tree/domain/notification/service/NotificationCommandService.java b/src/main/java/org/example/tree/domain/notification/service/NotificationCommandService.java new file mode 100644 index 0000000..fd0eaef --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/service/NotificationCommandService.java @@ -0,0 +1,4 @@ +package org.example.tree.domain.notification.service; + +public class NotificationCommandService { +} diff --git a/src/main/java/org/example/tree/domain/notification/service/NotificationQueryService.java b/src/main/java/org/example/tree/domain/notification/service/NotificationQueryService.java new file mode 100644 index 0000000..99de49e --- /dev/null +++ b/src/main/java/org/example/tree/domain/notification/service/NotificationQueryService.java @@ -0,0 +1,4 @@ +package org.example.tree.domain.notification.service; + +public class NotificationQueryService { +} diff --git a/src/main/java/org/example/tree/domain/notification/service/NotificationService.java b/src/main/java/org/example/tree/domain/notification/service/NotificationService.java index c5827ab..44af8d0 100644 --- a/src/main/java/org/example/tree/domain/notification/service/NotificationService.java +++ b/src/main/java/org/example/tree/domain/notification/service/NotificationService.java @@ -1,9 +1,26 @@ package org.example.tree.domain.notification.service; import lombok.RequiredArgsConstructor; +import org.example.tree.domain.member.entity.Member; +import org.example.tree.domain.notification.converter.NotificationConverter; +import org.example.tree.domain.notification.entity.Notification; +import org.example.tree.domain.notification.repository.NotificationRepository; import org.springframework.stereotype.Component; +import java.util.List; + @Component @RequiredArgsConstructor public class NotificationService { + + private final NotificationRepository notificationRepository; + private final NotificationCommandService notificationCommandService; + private final NotificationQueryService notificationQueryService; + private final NotificationConverter notificationConverter; + + public Notification sendNotification(String title, String message, String type, Member receiver) { + } + + public List getUserNotifications(String token) { + } }