feat: 添加好友功能并集成 LiteLLM 代理服务
- 新增好友搜索、添加、好友列表功能 - 集成 LiteLLM 代理服务及多模型定价配置 - 更新 iOS CocoaPods 配置 - 更新 .gitignore 和环境变量配置
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
|
||||
class FriendsApi {
|
||||
final IApiClient _client;
|
||||
static const _prefix = '/api/v1/friends';
|
||||
|
||||
FriendsApi(this._client);
|
||||
|
||||
Future<List<FriendResponse>> getFriends() async {
|
||||
final response = await _client.get(_prefix);
|
||||
final List<dynamic> data = response.data;
|
||||
return data.map((json) => FriendResponse.fromJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<List<FriendResponse>> getIncomingRequests() async {
|
||||
final response = await _client.get('$_prefix/requests/inbox');
|
||||
final List<dynamic> data = response.data;
|
||||
return data.map((json) => FriendResponse.fromJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<List<FriendResponse>> getOutgoingRequests() async {
|
||||
final response = await _client.get('$_prefix/requests/outgoing');
|
||||
final List<dynamic> data = response.data;
|
||||
return data.map((json) => FriendResponse.fromJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<FriendResponse> sendRequest(String targetUserId) async {
|
||||
final response = await _client.post(
|
||||
'$_prefix/requests',
|
||||
data: {'target_user_id': targetUserId},
|
||||
);
|
||||
return FriendResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<FriendResponse> acceptRequest(String friendshipId) async {
|
||||
final response = await _client.post(
|
||||
'$_prefix/requests/$friendshipId/accept',
|
||||
);
|
||||
return FriendResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<FriendResponse> declineRequest(String friendshipId) async {
|
||||
final response = await _client.post(
|
||||
'$_prefix/requests/$friendshipId/decline',
|
||||
);
|
||||
return FriendResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<void> removeFriend(String friendshipId) async {
|
||||
await _client.delete('$_prefix/$friendshipId');
|
||||
}
|
||||
}
|
||||
|
||||
class FriendResponse {
|
||||
final String id;
|
||||
final UserBasicInfo friend;
|
||||
final String status;
|
||||
final DateTime createdAt;
|
||||
final DateTime? acceptedAt;
|
||||
|
||||
FriendResponse({
|
||||
required this.id,
|
||||
required this.friend,
|
||||
required this.status,
|
||||
required this.createdAt,
|
||||
this.acceptedAt,
|
||||
});
|
||||
|
||||
factory FriendResponse.fromJson(Map<String, dynamic> json) {
|
||||
return FriendResponse(
|
||||
id: json['id'] as String,
|
||||
friend: UserBasicInfo.fromJson(json['friend'] as Map<String, dynamic>),
|
||||
status: json['status'] as String,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
acceptedAt: json['accepted_at'] != null
|
||||
? DateTime.parse(json['accepted_at'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UserBasicInfo {
|
||||
final String id;
|
||||
final String username;
|
||||
final String? avatarUrl;
|
||||
|
||||
UserBasicInfo({required this.id, required this.username, this.avatarUrl});
|
||||
|
||||
factory UserBasicInfo.fromJson(Map<String, dynamic> json) {
|
||||
return UserBasicInfo(
|
||||
id: json['id'] as String,
|
||||
username: json['username'] as String,
|
||||
avatarUrl: json['avatar_url'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user