blob: c7014a7daa343838b67b7d892557cbc1391e8001 [file] [log] [blame]
package com.example.myproject.controller;
import com.example.myproject.service.UserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/echo/message")
public class UserMessageController {
@Autowired
private UserMessageService userMessageService;
@PostMapping("/sendMessages")
public ResponseEntity<Map<String, Object>> sendMessage(@RequestBody Map<String, Object> params) {
// 将参数转换为 Long 类型
Long senderId = Long.valueOf(params.get("sender_id").toString());
Long receiverId = Long.valueOf(params.get("receiver_id").toString());
String content = (String) params.get("content");
Map<String, Object> response = userMessageService.sendMessage(senderId, receiverId, content);
return ResponseEntity.ok(response);
}
@GetMapping("/{user_id}/getUserMessages")
public ResponseEntity<Map<String, Object>> getUserMessages(@PathVariable("user_id") Long userId) {
Map<String, Object> response = userMessageService.getUserMessages(userId);
return ResponseEntity.ok(response);
}
// 获取单条消息的详情
@GetMapping("/{message_id}/getAMessage")
public ResponseEntity<Map<String, Object>> getMessage(@PathVariable("message_id") Long messageId) {
Map<String, Object> response = userMessageService.getMessage(messageId);
return ResponseEntity.ok(response);
}
}