From a63b02e74734c258b6bbb40f4fa2b5519044e628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=B0=AC=EA=B8=B0?= Date: Sat, 28 Sep 2024 00:27:34 +0900 Subject: [PATCH] feat: mock api notification (#180) --- .../org/example/config/SecurityConfig.java | 4 +- .../controller/UserAlarmController.java | 72 +++++++++++++++++++ .../dto/param/SimpleNotificationApiParam.java | 21 ++++++ .../HasUnreadNotificationApiResponse.java | 12 ++++ .../response/NotificationsApiResponse.java | 12 ++++ 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 app/api/user-api/src/main/java/org/example/controller/UserAlarmController.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/param/SimpleNotificationApiParam.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/response/HasUnreadNotificationApiResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/response/NotificationsApiResponse.java diff --git a/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java b/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java index 2135f7f4..c4742906 100644 --- a/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java +++ b/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java @@ -107,7 +107,9 @@ private RequestMatcher getMatcherForUserAndAdmin() { antMatcher(HttpMethod.GET, "/api/v1/genres/unsubscriptions"), antMatcher(HttpMethod.POST, "/api/v1/artists/subscribe"), antMatcher(HttpMethod.POST, "/api/v1/artists/unsubscribe"), - antMatcher(HttpMethod.GET, "/api/v1/artists/subscriptions") + antMatcher(HttpMethod.GET, "/api/v1/artists/subscriptions"), + antMatcher(HttpMethod.GET, "/api/v1/users/notifications"), + antMatcher(HttpMethod.GET, "/api/v1/users/notifications/unread") ); } } diff --git a/app/api/user-api/src/main/java/org/example/controller/UserAlarmController.java b/app/api/user-api/src/main/java/org/example/controller/UserAlarmController.java new file mode 100644 index 00000000..97b4c131 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/UserAlarmController.java @@ -0,0 +1,72 @@ +package org.example.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.time.LocalDateTime; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.example.controller.dto.param.SimpleNotificationApiParam; +import org.example.controller.dto.response.HasUnreadNotificationApiResponse; +import org.example.controller.dto.response.NotificationsApiResponse; +import org.example.security.dto.AuthenticatedInfo; +import org.example.util.DateTimeUtil; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "유저 알림") +@RestController +@RequestMapping("/api/v1/users") +@RequiredArgsConstructor +public class UserAlarmController { + + @GetMapping("/notifications/unread") + @Operation(summary = "안 읽은 알림 존재 여부") + public ResponseEntity hasUnreadNotifications( + @AuthenticationPrincipal AuthenticatedInfo info + ) { + return ResponseEntity.ok( + HasUnreadNotificationApiResponse.builder() + .hasUnreadNotification(true) + .build() + ); + } + + @GetMapping("/notifications") + @Operation(summary = "알림 목록") + public ResponseEntity getNotifications( + @AuthenticationPrincipal AuthenticatedInfo info + ) { + return ResponseEntity.ok( + NotificationsApiResponse.builder() + .notifications( + List.of( + SimpleNotificationApiParam.builder() + .title("오하요 고자이마스") + .message("본문 데스") + .notifiedAt(DateTimeUtil.formatDateTime(LocalDateTime.of(2021, 9, 27, 0, 0, 0))) + .showId(java.util.UUID.randomUUID()) + .showImageURL("https://example.com/show.jpg") + .build(), + SimpleNotificationApiParam.builder() + .title("알림알림제목제목알림알림제목제목") + .message("알림본문본문알림본문본문알림본문본문") + .notifiedAt(DateTimeUtil.formatDateTime(LocalDateTime.of(2021, 9, 27, 12, 0, 0))) + .showId(java.util.UUID.randomUUID()) + .showImageURL("https://example.com/show.jpg") + .build(), + SimpleNotificationApiParam.builder() + .title("알림 제목") + .message("알림 본문") + .notifiedAt(DateTimeUtil.formatDateTime(LocalDateTime.of(2021, 9, 27, 23, 0, 0))) + .showId(java.util.UUID.randomUUID()) + .showImageURL("https://example.com/show.jpg") + .build() + ) + ) + .build() + ); + } +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/param/SimpleNotificationApiParam.java b/app/api/user-api/src/main/java/org/example/controller/dto/param/SimpleNotificationApiParam.java new file mode 100644 index 00000000..2b4370fd --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/param/SimpleNotificationApiParam.java @@ -0,0 +1,21 @@ +package org.example.controller.dto.param; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.UUID; +import lombok.Builder; + +@Builder +public record SimpleNotificationApiParam( + @Schema(description = "알림 제목") + String title, + @Schema(description = "알림 본문") + String message, + @Schema(description = "알림 시간") + String notifiedAt, + @Schema(description = "공연 ID") + UUID showId, + @Schema(description = "공연 이미지 URL") + String showImageURL +) { + +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/response/HasUnreadNotificationApiResponse.java b/app/api/user-api/src/main/java/org/example/controller/dto/response/HasUnreadNotificationApiResponse.java new file mode 100644 index 00000000..e3fb562d --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/response/HasUnreadNotificationApiResponse.java @@ -0,0 +1,12 @@ +package org.example.controller.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + +@Builder +public record HasUnreadNotificationApiResponse( + @Schema(description = "안 읽은 알림 존재 여부") + boolean hasUnreadNotification +) { + +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/response/NotificationsApiResponse.java b/app/api/user-api/src/main/java/org/example/controller/dto/response/NotificationsApiResponse.java new file mode 100644 index 00000000..f49702e3 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/response/NotificationsApiResponse.java @@ -0,0 +1,12 @@ +package org.example.controller.dto.response; + +import java.util.List; +import lombok.Builder; +import org.example.controller.dto.param.SimpleNotificationApiParam; + +@Builder +public record NotificationsApiResponse( + List notifications +) { + +}