blob: f550bebad1395316b388166fe7d8fb34d34b83b8 [file] [log] [blame]
22301138f6824512025-06-04 02:03:13 +08001package com.example.myproject.controller;
2
3import com.example.myproject.service.UserFollowService;
4import org.springframework.beans.factory.annotation.Autowired;
5import org.springframework.http.ResponseEntity;
6import org.springframework.web.bind.annotation.*;
7
8import java.util.Map;
9
10@RestController
11@RequestMapping("/echo/users")
12public class UserFollowController {
13
14 @Autowired
15 private UserFollowService userFollowService;
16
17 // 用户关注接口
18 @PostMapping("/{followed_id}/follow")
19 public ResponseEntity<Map<String, Object>> follow(@PathVariable("followed_id") Long followedId,
20 @RequestBody Map<String, Long> request) {
21 Long followerId = request.get("follower_id");
22 Map<String, Object> response = userFollowService.follow(followerId, followedId);
23 return ResponseEntity.ok(response);
24 }
25
26 // 取消关注接口
27 @PostMapping("/{followed_id}/unfollow")
28 public ResponseEntity<Map<String, Object>> unfollow(@PathVariable("followed_id") Long followedId,
29 @RequestBody Map<String, Long> request) {
30 Long followerId = request.get("follower_id");
31 Map<String, Object> response = userFollowService.unfollow(followerId, followedId);
32 return ResponseEntity.ok(response);
33 }
34
35 // 获取某个用户的粉丝列表
36 @GetMapping("/{user_id}/followers")
37 public ResponseEntity<Map<String, Object>> getFollowers(@PathVariable("user_id") Long userId) {
38 Map<String, Object> response = userFollowService.getFollowers(userId);
39 return ResponseEntity.ok(response);
40 }
41
42 @GetMapping("/{user_id}/following")
43 public ResponseEntity<Map<String, Object>> getFollowing(@PathVariable("user_id") Long userId) {
44 Map<String, Object> response = userFollowService.getFollowing(userId);
45 return ResponseEntity.ok(response);
46 }
47}