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.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> register( @RequestParam @NotBlank String appId, @RequestParam @NotBlank String userId, @RequestParam @NotNull DeviceTokenEntity.Vendor vendor, @RequestParam @NotBlank String token) { pushDispatcher.registerToken(appId, userId, vendor, token); return ResponseEntity.ok(ApiResponse.ok()); } @PostMapping("/send") public ResponseEntity> send( @RequestParam @NotBlank String appId, @RequestParam @NotBlank String userId, @RequestParam @NotBlank String title, @RequestParam @NotBlank String body, @RequestParam(required = false) String payload) { pushDispatcher.pushToUser(appId, userId, title, body, payload); return ResponseEntity.ok(ApiResponse.ok()); } }