54 行
2.1 KiB
Java
54 行
2.1 KiB
Java
|
|
package com.xuqm.im.controller;
|
||
|
|
|
||
|
|
import com.xuqm.common.model.ApiResponse;
|
||
|
|
import com.xuqm.im.entity.ImMessageEntity;
|
||
|
|
import com.xuqm.im.model.SendMessageRequest;
|
||
|
|
import com.xuqm.im.service.MessageService;
|
||
|
|
import io.jsonwebtoken.Claims;
|
||
|
|
import jakarta.validation.Valid;
|
||
|
|
import org.springframework.http.ResponseEntity;
|
||
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
||
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
|
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/im/messages")
|
||
|
|
public class MessageController {
|
||
|
|
|
||
|
|
private final MessageService messageService;
|
||
|
|
|
||
|
|
public MessageController(MessageService messageService) {
|
||
|
|
this.messageService = messageService;
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/send")
|
||
|
|
public ResponseEntity<ApiResponse<ImMessageEntity>> send(
|
||
|
|
@Valid @RequestBody SendMessageRequest req,
|
||
|
|
@AuthenticationPrincipal String userId,
|
||
|
|
@RequestParam String appId) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(messageService.send(appId, userId, req)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/{id}/revoke")
|
||
|
|
public ResponseEntity<ApiResponse<ImMessageEntity>> revoke(
|
||
|
|
@PathVariable String id,
|
||
|
|
@AuthenticationPrincipal String userId,
|
||
|
|
@RequestParam String appId) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(messageService.revoke(appId, id, userId)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/history/{toId}")
|
||
|
|
public ResponseEntity<ApiResponse<?>> history(
|
||
|
|
@PathVariable String toId,
|
||
|
|
@RequestParam String appId,
|
||
|
|
@RequestParam(defaultValue = "0") int page,
|
||
|
|
@RequestParam(defaultValue = "20") int size) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(messageService.history(appId, toId, page, size)));
|
||
|
|
}
|
||
|
|
}
|