XuqmGroup-Server/push-service/src/main/java/com/xuqm/push/controller/PushController.java

72 行
3.0 KiB
Java

2026-04-21 22:07:29 +08:00
package com.xuqm.push.controller;
import com.xuqm.common.model.ApiResponse;
import com.xuqm.push.entity.DeviceTokenEntity;
import com.xuqm.push.service.PushDispatcher;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
2026-04-21 22:07:29 +08:00
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/push")
public class PushController {
private final PushDispatcher pushDispatcher;
public PushController(PushDispatcher pushDispatcher) {
this.pushDispatcher = pushDispatcher;
}
@PostMapping("/register")
public ResponseEntity<ApiResponse<Void>> register(
2026-05-07 19:39:42 +08:00
@RequestParam @NotBlank String appKey,
2026-04-21 22:07:29 +08:00
@RequestParam @NotBlank String userId,
@RequestParam @NotNull DeviceTokenEntity.Vendor vendor,
@RequestParam @NotBlank String token,
@RequestParam(required = false) String platform,
@RequestParam(required = false) String deviceId,
@RequestParam(required = false) String brand,
@RequestParam(required = false) String model,
@RequestParam(required = false) String osVersion,
@RequestParam(required = false) String appVersion) {
2026-05-07 19:39:42 +08:00
pushDispatcher.registerToken(appKey, userId, vendor, token, platform, deviceId, brand, model, osVersion, appVersion);
2026-04-21 22:07:29 +08:00
return ResponseEntity.ok(ApiResponse.ok());
}
@PostMapping("/receive-push")
public ResponseEntity<ApiResponse<Void>> receivePush(
2026-05-07 19:39:42 +08:00
@RequestParam @NotBlank String appKey,
@RequestParam @NotBlank String userId,
@RequestParam(required = false) String deviceId,
@RequestParam boolean enabled) {
2026-05-07 19:39:42 +08:00
pushDispatcher.setReceivePush(appKey, userId, deviceId, enabled);
return ResponseEntity.ok(ApiResponse.ok());
}
2026-04-21 22:07:29 +08:00
@PostMapping("/send")
public ResponseEntity<ApiResponse<Void>> send(
2026-05-07 19:39:42 +08:00
@RequestParam @NotBlank String appKey,
2026-04-21 22:07:29 +08:00
@RequestParam @NotBlank String userId,
@RequestParam @NotBlank String title,
@RequestParam @NotBlank String body,
@RequestParam(required = false) String payload) {
2026-05-07 19:39:42 +08:00
pushDispatcher.pushToUser(appKey, userId, title, body, payload);
2026-04-21 22:07:29 +08:00
return ResponseEntity.ok(ApiResponse.ok());
}
@DeleteMapping("/unregister")
public ResponseEntity<ApiResponse<Void>> unregister(
2026-05-07 19:39:42 +08:00
@RequestParam @NotBlank String appKey,
@RequestParam @NotBlank String userId,
@RequestParam @NotNull DeviceTokenEntity.Vendor vendor,
@RequestParam(required = false) String deviceId) {
2026-05-07 19:39:42 +08:00
pushDispatcher.unregisterToken(appKey, userId, vendor, deviceId);
return ResponseEntity.ok(ApiResponse.ok());
}
2026-04-21 22:07:29 +08:00
}