46d0427901
- Parse metadata field on Message model (weather, rss_item_ids) - Add WeatherCard widget: location, current temp, condition, today hi/lo, delta from yesterday, scrollable 3-day forecast strip - BriefingScreen shows WeatherCard above the first assistant message that carries weather metadata (mirrors web BriefingView.vue behaviour) - RSS reaction buttons (👍/👎) shown below assistant messages with rss_item_ids; optimistic toggle with rollback on failure - Add postRssReaction / deleteRssReaction to BriefingApi Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
82 lines
2.6 KiB
Dart
82 lines
2.6 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);
|
|
}
|
|
}
|
|
|
|
/// POST /api/briefing/rss-reactions body: {rss_item_id, reaction: "up"|"down"}
|
|
Future<void> postRssReaction(int rssItemId, String reaction) async {
|
|
try {
|
|
await _dio.post('/api/briefing/rss-reactions',
|
|
data: {'rss_item_id': rssItemId, 'reaction': reaction});
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// DELETE /api/briefing/rss-reactions/{rssItemId}
|
|
Future<void> deleteRssReaction(int rssItemId) async {
|
|
try {
|
|
await _dio.delete('/api/briefing/rss-reactions/$rssItemId');
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
}
|