46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package com.bao.dating.controller;
|
|
|
|
import com.bao.dating.context.UserContext;
|
|
import com.bao.dating.service.ContactsService;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
public class ContactsController {
|
|
@Resource
|
|
private ContactsService contactsService;
|
|
|
|
/**
|
|
* 查询好友列表
|
|
* @return 响应结果
|
|
*/
|
|
@GetMapping("/friends")
|
|
public Map<String, Object> getFriends() {
|
|
|
|
// 从UserContext获取当前用户ID
|
|
Long userId = UserContext.getUserId();
|
|
if (userId == null) {
|
|
Map<String, Object> error = new HashMap<>();
|
|
error.put("code", 401);
|
|
error.put("msg", "用户未授权");
|
|
return error;
|
|
}
|
|
|
|
// 查询好友列表
|
|
List<Map<String, Object>> friends = contactsService.getFriendsByUserId(userId);
|
|
|
|
// 构造响应
|
|
Map<String, Object> result = new HashMap<>();
|
|
result.put("code", 200);
|
|
result.put("msg", "查询成功");
|
|
result.put("data", friends);
|
|
return result;
|
|
}
|
|
}
|