|
| 1 | +package com.back.domain.notification.controller; |
| 2 | + |
| 3 | +import com.back.domain.notification.dto.NotificationGoResponseDto; |
| 4 | +import com.back.domain.notification.dto.NotificationListResponseDto; |
| 5 | +import com.back.domain.notification.service.NotificationService; |
| 6 | +import com.back.global.rsData.RsData; |
| 7 | +import jakarta.validation.constraints.Max; |
| 8 | +import jakarta.validation.constraints.Min; |
| 9 | +import lombok.RequiredArgsConstructor; |
| 10 | +import org.springframework.format.annotation.DateTimeFormat; |
| 11 | +import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 12 | +import org.springframework.validation.annotation.Validated; |
| 13 | +import org.springframework.web.bind.annotation.*; |
| 14 | + |
| 15 | +import java.time.LocalDateTime; |
| 16 | + |
| 17 | +@RestController |
| 18 | +@RequestMapping("/api/me") |
| 19 | +@RequiredArgsConstructor |
| 20 | +@Validated |
| 21 | +public class NotificationController { |
| 22 | + |
| 23 | + private final NotificationService notificationService; |
| 24 | + |
| 25 | + @GetMapping("/notifications") |
| 26 | + public RsData<NotificationListResponseDto> getNotifications( |
| 27 | + @AuthenticationPrincipal(expression = "id") Long userId, |
| 28 | + @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime lastCreatedAt, |
| 29 | + @RequestParam(required = false) Long lastId, |
| 30 | + @RequestParam(defaultValue = "20") @Min(1) @Max(100) int limit |
| 31 | + ) { |
| 32 | + NotificationListResponseDto body = notificationService.getNotifications(userId, lastCreatedAt, lastId, limit); |
| 33 | + return RsData.successOf(body); |
| 34 | + } |
| 35 | + |
| 36 | + @PostMapping("/notifications/{id}") |
| 37 | + public RsData<NotificationGoResponseDto> goPostLink( |
| 38 | + @AuthenticationPrincipal(expression = "id") Long userId, |
| 39 | + @PathVariable("id") Long notificationId |
| 40 | + ) { |
| 41 | + var body = notificationService.markAsReadAndGetPostLink(userId, notificationId); |
| 42 | + return RsData.successOf(body); |
| 43 | + } |
| 44 | +} |
0 commit comments