def7519feb
- app.dart: add braces to single-statement if body - briefing_api.dart: escape <id> in doc comment (unintended HTML) - notes_api.dart, tasks_api.dart, projects_api.dart: use null-aware map elements (?'key': value) instead of if-null guards - task_edit_screen.dart: remove unused tasks_api.dart import - task_edit_screen.dart, project_selector.dart: suppress deprecated_member_use on DropdownButtonFormField.value (value is the controlled-widget param; switching to initialValue would break current-selection display) - project_selector.dart: use _ instead of __ for ignored error params
63 lines
2.0 KiB
Dart
63 lines
2.0 KiB
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../models/briefing_conversation.dart';
|
|
import '../models/message.dart';
|
|
import 'api_client.dart';
|
|
|
|
class BriefingApi {
|
|
final Dio _dio;
|
|
const BriefingApi(this._dio);
|
|
|
|
/// GET /api/briefing/conversations/today
|
|
/// Returns (or creates) today's briefing conversation with messages embedded.
|
|
Future<BriefingConversation> getToday() async {
|
|
try {
|
|
final response = await _dio.get('/api/briefing/conversations/today');
|
|
return BriefingConversation.fromJson(
|
|
response.data as Map<String, dynamic>);
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// GET /api/briefing/conversations
|
|
/// Returns list of past briefing conversations (no messages embedded).
|
|
Future<List<BriefingConversation>> getHistory() async {
|
|
try {
|
|
final response = await _dio.get('/api/briefing/conversations');
|
|
final data = response.data as Map<String, dynamic>;
|
|
final list = data['conversations'] as List<dynamic>;
|
|
return list
|
|
.map((e) => BriefingConversation.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// GET /api/briefing/conversations/`<id>`/messages
|
|
Future<List<Message>> getMessages(int convId) async {
|
|
try {
|
|
final response =
|
|
await _dio.get('/api/briefing/conversations/$convId/messages');
|
|
final data = response.data as Map<String, dynamic>;
|
|
final list = data['messages'] as List<dynamic>;
|
|
return list
|
|
.map((e) => Message.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// POST /api/briefing/trigger body: {"slot": slot}
|
|
/// slot: "compilation" | "morning" | "midday" | "afternoon"
|
|
Future<void> triggerSlot(String slot) async {
|
|
try {
|
|
await _dio.post('/api/briefing/trigger', data: {'slot': slot});
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
}
|