- Remove @Valid/@NotBlank/@Size/@Email/@NotNull from all Java record DTOs (incompatible with Jackson deserialization in Spring Boot 3.x) - Add manual validation in controllers instead - Add database reset with data preservation to reset container feature (exports core config tables, drops all tables, Hibernate recreates on startup, then restores preserved data) - Update nginx timeout regex to cover all system endpoints Affected services: tenant-service, license-service, im-service, push-service Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
96 行
3.8 KiB
Java
96 行
3.8 KiB
Java
package com.xuqm.push.controller;
|
|
|
|
import com.xuqm.common.exception.BusinessException;
|
|
import com.xuqm.common.model.ApiResponse;
|
|
import com.xuqm.push.entity.DeviceTokenEntity;
|
|
import com.xuqm.push.service.PushDispatcher;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
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(
|
|
@RequestParam String appKey,
|
|
@RequestParam String userId,
|
|
@RequestParam DeviceTokenEntity.Vendor vendor,
|
|
@RequestParam 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) {
|
|
requireNonBlank(appKey, "appKey");
|
|
requireNonBlank(userId, "userId");
|
|
requireNonNull(vendor, "vendor");
|
|
requireNonBlank(token, "token");
|
|
pushDispatcher.registerToken(appKey, userId, vendor, token, platform, deviceId, brand, model, osVersion, appVersion);
|
|
return ResponseEntity.ok(ApiResponse.ok());
|
|
}
|
|
|
|
@PostMapping("/receive-push")
|
|
public ResponseEntity<ApiResponse<Void>> receivePush(
|
|
@RequestParam String appKey,
|
|
@RequestParam String userId,
|
|
@RequestParam(required = false) String deviceId,
|
|
@RequestParam boolean enabled) {
|
|
requireNonBlank(appKey, "appKey");
|
|
requireNonBlank(userId, "userId");
|
|
pushDispatcher.setReceivePush(appKey, userId, deviceId, enabled);
|
|
return ResponseEntity.ok(ApiResponse.ok());
|
|
}
|
|
|
|
@PostMapping("/send")
|
|
public ResponseEntity<ApiResponse<Void>> send(
|
|
@RequestParam String appKey,
|
|
@RequestParam String userId,
|
|
@RequestParam String title,
|
|
@RequestParam String body,
|
|
@RequestParam(required = false) String payload) {
|
|
requireNonBlank(appKey, "appKey");
|
|
requireNonBlank(userId, "userId");
|
|
requireNonBlank(title, "title");
|
|
requireNonBlank(body, "body");
|
|
pushDispatcher.pushToUser(appKey, userId, title, body, payload);
|
|
return ResponseEntity.ok(ApiResponse.ok());
|
|
}
|
|
|
|
@DeleteMapping("/unregister")
|
|
public ResponseEntity<ApiResponse<Void>> unregister(
|
|
@RequestParam String appKey,
|
|
@RequestParam String userId,
|
|
@RequestParam DeviceTokenEntity.Vendor vendor,
|
|
@RequestParam(required = false) String deviceId) {
|
|
requireNonBlank(appKey, "appKey");
|
|
requireNonBlank(userId, "userId");
|
|
requireNonNull(vendor, "vendor");
|
|
pushDispatcher.unregisterToken(appKey, userId, vendor, deviceId);
|
|
return ResponseEntity.ok(ApiResponse.ok());
|
|
}
|
|
|
|
private static void requireNonBlank(String value, String field) {
|
|
if (value == null || value.isBlank()) {
|
|
throw new BusinessException(400, field + " 不能为空");
|
|
}
|
|
}
|
|
|
|
private static void requireNonNull(Object value, String field) {
|
|
if (value == null) {
|
|
throw new BusinessException(400, field + " 不能为空");
|
|
}
|
|
}
|
|
}
|