feat: 增强日历功能并集成 AgentScope 代理服务
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
|
||||
import 'models/schedule_item_model.dart';
|
||||
|
||||
class CalendarApi {
|
||||
final IApiClient _client;
|
||||
static const _prefix = '/api/v1/schedule-items';
|
||||
|
||||
CalendarApi(this._client);
|
||||
|
||||
Future<List<ScheduleItemModel>> listByRange({
|
||||
required DateTime startAt,
|
||||
required DateTime endAt,
|
||||
}) async {
|
||||
final response = await _client.get(
|
||||
'$_prefix?start_at=${Uri.encodeQueryComponent(startAt.toUtc().toIso8601String())}&end_at=${Uri.encodeQueryComponent(endAt.toUtc().toIso8601String())}',
|
||||
);
|
||||
final data = response.data;
|
||||
if (data is! List) {
|
||||
return const [];
|
||||
}
|
||||
return data
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(ScheduleItemModel.fromJson)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel> getById(String id) async {
|
||||
final response = await _client.get('$_prefix/$id');
|
||||
return ScheduleItemModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel> create(ScheduleItemModel request) async {
|
||||
final response = await _client.post(_prefix, data: request.toCreateJson());
|
||||
return ScheduleItemModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel> update(ScheduleItemModel request) async {
|
||||
final response = await _client.patch(
|
||||
'$_prefix/${request.id}',
|
||||
data: request.toUpdateJson(),
|
||||
);
|
||||
return ScheduleItemModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Future<void> delete(String id) async {
|
||||
await _client.delete('$_prefix/$id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user