Change PIN to 1451
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
55
apps/captain-mobile-v2/flutter/lib/services/api_service.dart
Normal file
55
apps/captain-mobile-v2/flutter/lib/services/api_service.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../config/api_config.dart';
|
||||
import '../models/conversation.dart';
|
||||
import '../models/message.dart';
|
||||
|
||||
class ApiService {
|
||||
String? _token;
|
||||
|
||||
void setToken(String? token) {
|
||||
_token = token;
|
||||
}
|
||||
|
||||
Map<String, String> get _headers => {
|
||||
'Content-Type': 'application/json',
|
||||
if (_token != null) 'Authorization': 'Bearer $_token',
|
||||
};
|
||||
|
||||
Future<List<Conversation>> getConversations() async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}/conversations'),
|
||||
headers: _headers,
|
||||
).timeout(ApiConfig.connectionTimeout);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = jsonDecode(response.body);
|
||||
return data.map((e) => Conversation.fromJson(e)).toList();
|
||||
}
|
||||
throw Exception('Failed to load conversations');
|
||||
}
|
||||
|
||||
Future<List<Message>> getConversationMessages(String conversationId) async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}/conversations/$conversationId'),
|
||||
headers: _headers,
|
||||
).timeout(ApiConfig.connectionTimeout);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = jsonDecode(response.body);
|
||||
return data.map((e) => Message.fromJson(e)).toList();
|
||||
}
|
||||
throw Exception('Failed to load messages');
|
||||
}
|
||||
|
||||
Future<void> deleteConversation(String conversationId) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse('${ApiConfig.baseUrl}/conversations/$conversationId'),
|
||||
headers: _headers,
|
||||
).timeout(ApiConfig.connectionTimeout);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to delete conversation');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user