Phase 3 completed: Flutter MVP with live streaming and auto-refresh
This commit is contained in:
45
frontend/lib/services/api_service.dart
Normal file
45
frontend/lib/services/api_service.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../providers/settings_provider.dart';
|
||||
|
||||
class ApiService {
|
||||
final SettingsProvider settings;
|
||||
final String? token;
|
||||
|
||||
ApiService(this.settings, this.token);
|
||||
|
||||
Map<String, String> get _headers => {
|
||||
'Content-Type': 'application/json',
|
||||
if (token != null) 'Authorization': 'Bearer $token',
|
||||
};
|
||||
|
||||
Future<http.Response> register(String username, String password) async {
|
||||
return await http.post(
|
||||
Uri.parse("${settings.baseUrl}/api/register"),
|
||||
headers: _headers,
|
||||
body: jsonEncode({"username": username, "password": password}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<http.Response> login(String username, String password) async {
|
||||
return await http.post(
|
||||
Uri.parse("${settings.baseUrl}/api/login"),
|
||||
headers: _headers,
|
||||
body: jsonEncode({"username": username, "password": password}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<http.Response> getMyRoom() async {
|
||||
return await http.get(
|
||||
Uri.parse("${settings.baseUrl}/api/room/my"),
|
||||
headers: _headers,
|
||||
);
|
||||
}
|
||||
|
||||
Future<http.Response> getActiveRooms() async {
|
||||
return await http.get(
|
||||
Uri.parse("${settings.baseUrl}/api/rooms/active"),
|
||||
headers: _headers,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user