-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFriendController.java
More file actions
97 lines (87 loc) · 2.98 KB
/
FriendController.java
File metadata and controls
97 lines (87 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.jiang.test.backend.controller;
import com.jiang.test.backend.annotation.Authorized;
import com.jiang.test.backend.constant.ApiConstants;
import com.jiang.test.backend.entity.User;
import com.jiang.test.backend.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(ApiConstants.COMMON_URL)
public class FriendController {
@Autowired
FriendService friendService;
/**
* 获取用户的所有关注者
* @param userId
* @return List<User>
*/
@GetMapping(ApiConstants.GET_FOLLOWERS_URL)
@Authorized
public ResponseEntity<List<User>> getFollowers(@PathVariable int userId) {
List<User> followers = friendService.getFollowers(userId);
return ResponseEntity.ok(followers);
}
/**
* 添加关注者
* 请求体中包含要添加的关注者的ID。
* @param userId
* @param followerId
* @return
*/
@PostMapping(ApiConstants.ADD_FOLLOWERS_URL)
@Authorized
public ResponseEntity<String> addFollower(@RequestParam int userId, @RequestParam int followerId) {
friendService.addFollower(userId,followerId);
return ResponseEntity.ok("Follower added successfully.");
}
/**
* 删除关注者
* @param userId
* @param followerId
* @return
*/
@DeleteMapping(ApiConstants.REMOVE_FOLLOWERS_URL)
@Authorized
public ResponseEntity<String> removeFollower(@RequestParam int userId, @RequestParam int followerId) {
friendService.removeFollower(userId,followerId);
return ResponseEntity.ok("Follower removed successfully.");
}
/**
* 获取用户的所有好友
* @param userId
* @return
*/
@GetMapping(ApiConstants.GET_FRIENDS_URL)
@Authorized
public ResponseEntity<List<User>> getFriends(@PathVariable int userId) {
List<User> friends = friendService.getFriends(userId);
return ResponseEntity.ok(friends);
}
/**
* 获取共同的朋友
* @param userId
* @param otherUserId
* @return
*/
@GetMapping(ApiConstants.GET_COMMON_FRIENDS_URL)
@Authorized
public ResponseEntity<List<User>> getCommonFriends(@PathVariable int userId, @PathVariable int otherUserId) {
List<User> commonFriends = friendService.getCommonFriends(userId,otherUserId);
return ResponseEntity.ok(commonFriends);
}
/**
* 获取最近的朋友信息
* @param userId
* @param distance
* @return
*/
@GetMapping(ApiConstants.GET_NEARBY_FRIENDS_URL)
@Authorized
public ResponseEntity<List<User>> getNearbyFriends(@PathVariable int userId,
@PathVariable double distance) {
List<User> nearbyFriends = friendService.getNearbyFriends(userId,distance);
return ResponseEntity.ok(nearbyFriends);
}
}