blob: f550bebad1395316b388166fe7d8fb34d34b83b8 [file] [log] [blame]
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);
}
}