Initial commit: family safety frontend project setup

This commit is contained in:
dmit.b
2026-05-09 12:38:19 +03:00
commit ca90c6c3fc
147 changed files with 6350 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../config/api.dart';
class AuthService {
final http.Client _client;
AuthService({http.Client? client}) : _client = client ?? http.Client();
Future<String> login(String login, String password) async {
final response = await _client.post(
Uri.parse(ApiConfig.loginUrl),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'login': login, 'password': password}),
);
if (response.statusCode == 200) {
return response.body;
} else {
throw Exception('Invalid credentials');
}
}
Future<void> register(String login, String password) async {
final response = await _client.post(
Uri.parse(ApiConfig.regUrl),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'login': login, 'password': password}),
);
if (response.statusCode != 201) {
throw Exception('Registration failed');
}
}
}
+24
View File
@@ -0,0 +1,24 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../config/api.dart';
class GeoService {
final http.Client _client;
GeoService({http.Client? client}) : _client = client ?? http.Client();
Future<void> updatePosition(String token, int id, double x, double y) async {
final response = await _client.put(
Uri.parse('${ApiConfig.geoUrl}?id=$id'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
},
body: jsonEncode({'x': x, 'y': y}),
);
if (response.statusCode != 200) {
throw Exception('Failed to update position');
}
}
}
+73
View File
@@ -0,0 +1,73 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../config/api.dart';
class ShareService {
final http.Client _client;
ShareService({http.Client? client}) : _client = client ?? http.Client();
Future<Map<String, dynamic>> createShare(String token, double x, double y) async {
final response = await _client.post(
Uri.parse(ApiConfig.shareUrl),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
},
body: jsonEncode({'x': x, 'y': y}),
);
if (response.statusCode == 201) {
final data = jsonDecode(response.body);
return {
'geo_id': data['geo_id'],
'share_id': data['share_id'],
};
} else {
throw Exception('Failed to create share link');
}
}
Future<Map<String, dynamic>> getPosition(String token, String uniqueId) async {
final response = await _client.get(
Uri.parse('${ApiConfig.watchUrl}?unique_id=$uniqueId'),
headers: {
'Authorization': 'Bearer $token',
},
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return {
'id': data['id'],
'x': data['x'],
'y': data['y'],
'created_at': data['created_at'],
'expires_at': data['expires_at'],
};
} else {
throw Exception('Share link not found or no position available');
}
}
Future<Map<String, dynamic>> getPositionByShareId(String token, String shareId) async {
final response = await _client.get(
Uri.parse('${ApiConfig.watchUrl}?share_id=$shareId'),
headers: {
'Authorization': 'Bearer $token',
},
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return {
'x': data['x'],
'y': data['y'],
'created_at': data['created_at'],
'expires_at': data['expires_at'],
};
} else {
throw Exception('Share link not found or no position available');
}
}
}