blob: 55a30f34f465f6c834bca57acf282bbc86692f14 [file] [log] [blame]
xiukira687b9cb2025-05-29 15:15:02 +08001package com.g9.g9backend.controller;
2
Seamher176d3312025-06-06 16:57:34 +08003import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4import com.baomidou.mybatisplus.core.metadata.IPage;
5import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6import com.g9.g9backend.pojo.Notification;
7import com.g9.g9backend.service.NotificationService;
xiukira687b9cb2025-05-29 15:15:02 +08008import org.slf4j.Logger;
9import org.slf4j.LoggerFactory;
Seamher176d3312025-06-06 16:57:34 +080010import org.springframework.http.HttpStatus;
11import org.springframework.http.ResponseEntity;
12import org.springframework.web.bind.annotation.*;
xiukira687b9cb2025-05-29 15:15:02 +080013
14/**
15 * NotificationController 通知控制器类,处理与通知相关的请求
16 *
17 * @author Seamher
18 */
19@RestController
20@RequestMapping("/notification")
21public class NotificationController {
22
Seamher176d3312025-06-06 16:57:34 +080023 private final NotificationService notificationService;
24
25 public NotificationController(NotificationService notificationService) {
26 this.notificationService = notificationService;
27 }
28
xiukira687b9cb2025-05-29 15:15:02 +080029 private final Logger logger = LoggerFactory.getLogger(NotificationController.class);
Seamher176d3312025-06-06 16:57:34 +080030
31 @PostMapping(value = "/read")
32 public ResponseEntity<String> getNotificationRead(@RequestBody Notification notification) {
33 Integer notificationId = notification.getNotificationId();
34 System.out.println(notificationId);
35 Notification notificationUpdate = notificationService.getById(notificationId);
36 notificationUpdate.setRead(true);
37 notificationService.updateById(notificationUpdate);
38
39 return ResponseEntity.ok("");
40 }
41
42 @DeleteMapping
43 @ResponseStatus(HttpStatus.NO_CONTENT)
44 public ResponseEntity<String> deleteNotification(@RequestParam Integer notificationId) {
45 notificationService.removeById(notificationId);
46
47 return ResponseEntity.noContent().build();
48 }
49
50 @GetMapping
51 public ResponseEntity<IPage<Notification>> getNotification(@RequestParam Integer userId,
52 @RequestParam Integer pageNumber,
53 @RequestParam Integer rows) {
54 Page<Notification> pageNotification = new Page<>(pageNumber, rows);
55 LambdaQueryWrapper<Notification> query = new LambdaQueryWrapper<Notification>()
56 .eq(Notification::getUserId, userId)
57 .orderByDesc(Notification::getCreateAt);
58
59 IPage<Notification> result = notificationService.page(pageNotification, query);
60 logger.info("通知已返回");
61
62 return ResponseEntity.ok(result);
63 }
64
xiukira687b9cb2025-05-29 15:15:02 +080065}