follow+sendMessage
Change-Id: I3e9bbcc89dfc53b9651fd8722da1b445a597629a
diff --git a/src/main/java/com/example/g8backend/controller/UserController.java b/src/main/java/com/example/g8backend/controller/UserController.java
index 2665b4c..3b9ec22 100644
--- a/src/main/java/com/example/g8backend/controller/UserController.java
+++ b/src/main/java/com/example/g8backend/controller/UserController.java
@@ -8,6 +8,8 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
+import java.util.Map;
+
@RestController
@RequestMapping("/user")
public class UserController {
@@ -24,4 +26,21 @@
user.setPassword(null);
return ResponseEntity.ok(user);
}
+ @PostMapping("/follow/{userId}")
+ public ResponseEntity<?> followUser(@PathVariable Long userId) {
+ Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+ Long followerId = (Long) auth.getPrincipal(); // 确保Security返回Long
+ return ResponseEntity.ok(userService.followUser(followerId, userId));
+ }
+
+ @PostMapping("/message/{receiverId}")
+ public ResponseEntity<?> sendMessage(
+ @PathVariable Long receiverId,
+ @RequestBody String content
+ ) {
+ Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+ Long senderId = (Long) auth.getPrincipal();
+ Long messageId = userService.sendMessage(senderId, receiverId, content);
+ return ResponseEntity.ok(Map.of("messageId", messageId));
+ }
}