add notification API
GET /notification
DELETE /notification
POST /notification/read
Change-Id: I06f28ce188049015cb6a0fe221caf2f784687db5
diff --git a/src/main/java/com/g9/g9backend/controller/NotificationController.java b/src/main/java/com/g9/g9backend/controller/NotificationController.java
index c774041..55a30f3 100644
--- a/src/main/java/com/g9/g9backend/controller/NotificationController.java
+++ b/src/main/java/com/g9/g9backend/controller/NotificationController.java
@@ -1,9 +1,15 @@
package com.g9.g9backend.controller;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.g9.g9backend.pojo.Notification;
+import com.g9.g9backend.service.NotificationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
/**
* NotificationController 通知控制器类,处理与通知相关的请求
@@ -14,5 +20,46 @@
@RequestMapping("/notification")
public class NotificationController {
+ private final NotificationService notificationService;
+
+ public NotificationController(NotificationService notificationService) {
+ this.notificationService = notificationService;
+ }
+
private final Logger logger = LoggerFactory.getLogger(NotificationController.class);
+
+ @PostMapping(value = "/read")
+ public ResponseEntity<String> getNotificationRead(@RequestBody Notification notification) {
+ Integer notificationId = notification.getNotificationId();
+ System.out.println(notificationId);
+ Notification notificationUpdate = notificationService.getById(notificationId);
+ notificationUpdate.setRead(true);
+ notificationService.updateById(notificationUpdate);
+
+ return ResponseEntity.ok("");
+ }
+
+ @DeleteMapping
+ @ResponseStatus(HttpStatus.NO_CONTENT)
+ public ResponseEntity<String> deleteNotification(@RequestParam Integer notificationId) {
+ notificationService.removeById(notificationId);
+
+ return ResponseEntity.noContent().build();
+ }
+
+ @GetMapping
+ public ResponseEntity<IPage<Notification>> getNotification(@RequestParam Integer userId,
+ @RequestParam Integer pageNumber,
+ @RequestParam Integer rows) {
+ Page<Notification> pageNotification = new Page<>(pageNumber, rows);
+ LambdaQueryWrapper<Notification> query = new LambdaQueryWrapper<Notification>()
+ .eq(Notification::getUserId, userId)
+ .orderByDesc(Notification::getCreateAt);
+
+ IPage<Notification> result = notificationService.page(pageNotification, query);
+ logger.info("通知已返回");
+
+ return ResponseEntity.ok(result);
+ }
+
}