用户,社交接口
Change-Id: I10d13773cbe4bbcf3b69a2038cdf7aa9ba54b6df
diff --git a/src/main/java/com/example/myproject/controller/UserFollowController.java b/src/main/java/com/example/myproject/controller/UserFollowController.java
new file mode 100644
index 0000000..f550beb
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/UserFollowController.java
@@ -0,0 +1,47 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.service.UserFollowService;
+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/users")
+public class UserFollowController {
+
+ @Autowired
+ private UserFollowService userFollowService;
+
+ // 用户关注接口
+ @PostMapping("/{followed_id}/follow")
+ public ResponseEntity<Map<String, Object>> follow(@PathVariable("followed_id") Long followedId,
+ @RequestBody Map<String, Long> request) {
+ Long followerId = request.get("follower_id");
+ Map<String, Object> response = userFollowService.follow(followerId, followedId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 取消关注接口
+ @PostMapping("/{followed_id}/unfollow")
+ public ResponseEntity<Map<String, Object>> unfollow(@PathVariable("followed_id") Long followedId,
+ @RequestBody Map<String, Long> request) {
+ Long followerId = request.get("follower_id");
+ Map<String, Object> response = userFollowService.unfollow(followerId, followedId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 获取某个用户的粉丝列表
+ @GetMapping("/{user_id}/followers")
+ public ResponseEntity<Map<String, Object>> getFollowers(@PathVariable("user_id") Long userId) {
+ Map<String, Object> response = userFollowService.getFollowers(userId);
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping("/{user_id}/following")
+ public ResponseEntity<Map<String, Object>> getFollowing(@PathVariable("user_id") Long userId) {
+ Map<String, Object> response = userFollowService.getFollowing(userId);
+ return ResponseEntity.ok(response);
+ }
+}