49 lines
1.5 KiB
Dart
49 lines
1.5 KiB
Dart
import '../core/network/api_client.dart';
|
|
import '../core/network/endpoints.dart';
|
|
import '../models/comment_item.dart';
|
|
|
|
/// 评论服务(《03-接口文档》6.3~6.5)
|
|
class CommentService {
|
|
CommentService._();
|
|
|
|
/// 评论列表:parentId=0 查一级评论(带 reply_count),否则查该评论的二级回复
|
|
static Future<CommentListPage> list(
|
|
int videoId, {
|
|
int page = 1,
|
|
int pageSize = 20,
|
|
int parentId = 0,
|
|
}) async {
|
|
final data = await ApiClient.get<Map<String, dynamic>>(
|
|
Endpoints.videoComments(videoId),
|
|
queryParameters: {
|
|
'page': page,
|
|
'page_size': pageSize,
|
|
'parent_id': parentId,
|
|
},
|
|
);
|
|
return CommentListPage.fromJson(data);
|
|
}
|
|
|
|
/// 发表评论(需登录):回复时传 parentId(一级评论 ID)与 replyToUserId
|
|
static Future<CommentCreateResult> create(
|
|
int videoId,
|
|
String content, {
|
|
int? parentId,
|
|
int? replyToUserId,
|
|
}) async {
|
|
final data = await ApiClient.post<Map<String, dynamic>>(
|
|
Endpoints.videoComments(videoId),
|
|
data: {
|
|
'content': content,
|
|
if (parentId != null) 'parent_id': parentId,
|
|
if (replyToUserId != null) 'reply_to_user_id': replyToUserId,
|
|
},
|
|
);
|
|
return CommentCreateResult.fromJson(data);
|
|
}
|
|
|
|
/// 删除评论(本人评论或本人视频下的评论)
|
|
static Future<void> delete(int commentId) =>
|
|
ApiClient.delete<Map<String, dynamic>>(Endpoints.commentDelete(commentId));
|
|
}
|