Skip to content

Commit

Permalink
feat: mock api notification (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmizz authored and GaBaljaintheroom committed Oct 7, 2024
1 parent 4ecc56a commit a63b02e
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
}
Original file line number Diff line number Diff line change
@@ -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<HasUnreadNotificationApiResponse> hasUnreadNotifications(
@AuthenticationPrincipal AuthenticatedInfo info
) {
return ResponseEntity.ok(
HasUnreadNotificationApiResponse.builder()
.hasUnreadNotification(true)
.build()
);
}

@GetMapping("/notifications")
@Operation(summary = "알림 목록")
public ResponseEntity<NotificationsApiResponse> 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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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
) {

}
Original file line number Diff line number Diff line change
@@ -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
) {

}
Original file line number Diff line number Diff line change
@@ -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<SimpleNotificationApiParam> notifications
) {

}

0 comments on commit a63b02e

Please sign in to comment.