package com.designhub.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.designhub.common.Result; import com.designhub.entity.Notification; import com.designhub.service.NotificationService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; /** * 通知消息Controller */ @Tag(name = "通知消息", description = "通知消息相关API") @RestController @RequestMapping("/api/notifications") @RequiredArgsConstructor public class NotificationController { private final NotificationService notificationService; @Operation(summary = "获取用户通知列表(分页)") @GetMapping public Result> getUserNotifications( @RequestParam Long receiverId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize, @RequestParam(required = false) Boolean unreadOnly ) { Page page = notificationService.getUserNotifications(receiverId, pageNum, pageSize, unreadOnly); return Result.success(page); } @Operation(summary = "获取未读数量") @GetMapping("/unread-count") public Result getUnreadCount(@RequestParam Long receiverId) { long count = notificationService.getUnreadCount(receiverId); return Result.success(count); } @Operation(summary = "标记通知为已读") @PutMapping("/{id}/read") public Result markAsRead(@PathVariable Long id, @RequestParam Long receiverId) { boolean success = notificationService.markAsRead(id, receiverId); return Result.success(success); } @Operation(summary = "批量标记所有通知为已读") @PutMapping("/read-all") public Result markAllAsRead(@RequestParam Long receiverId) { int count = notificationService.markAllAsRead(receiverId); return Result.success(count); } @Operation(summary = "删除通知") @DeleteMapping("/{id}") public Result deleteNotification(@PathVariable Long id, @RequestParam Long receiverId) { boolean success = notificationService.deleteNotification(id, receiverId); return Result.success(success); } @Operation(summary = "发送通知(管理员)") @PostMapping public Result sendNotification(@RequestBody Notification notification) { Notification result = notificationService.sendNotification(notification); return Result.success(result); } }