vor Import/Export

This commit is contained in:
2025-10-24 12:39:10 +02:00
parent 77ad6b3823
commit 8abe0ca966
6 changed files with 214 additions and 113 deletions
+36 -12
View File
@@ -1,3 +1,4 @@
// lib/features/igel/data/igel_repository.dart
import '../../../shared/api_client.dart';
import '../domain/igel.dart';
@@ -12,24 +13,27 @@ class IgelRepository {
}
Future<Igel> create(String name,
{String? note, String? gender, String? feature}) async {
{String? note,
String? gender,
String? feature,
DateTime? rescuedAt,
String? location}) async {
String? fmtDate(DateTime? d) =>
d == null ? null : d.toIso8601String().split('T').first;
final res = await api.post<dynamic>('/igel', {
'name': name,
'note': note,
'gender': gender,
'feature': feature,
'rescued_at': fmtDate(rescuedAt),
'location': (location?.trim().isEmpty ?? true) ? null : location!.trim(),
});
return Igel.fromMap(res as Map<String, dynamic>);
}
Future<void> update(int id, String name,
{String? note, String? gender, String? feature}) async {
await api.put<dynamic>('/igel/$id', {
'name': name,
'note': note,
'gender': gender,
'feature': feature,
});
try {
final id = (res['id'] as num).toInt();
return await get(id);
} catch (_) {
return Igel.fromMap((res as Map).cast<String, dynamic>());
}
}
Future<void> delete(int id) async {
@@ -40,4 +44,24 @@ class IgelRepository {
final map = await api.get<Map<String, dynamic>>('/igel/$id');
return Igel.fromMap(map);
}
/// Update hedgehog data. Backend requires name; other fields optional.
Future<void> update(int id, String name,
{String? note,
String? gender,
String? feature,
DateTime? rescuedAt,
String? location}) async {
String? fmtDate(DateTime? d) =>
d == null ? null : d.toIso8601String().split('T').first;
final body = {
'name': name,
'note': note,
'gender': gender,
'feature': feature,
'rescued_at': fmtDate(rescuedAt),
'location': (location?.trim().isEmpty ?? true) ? null : location!.trim(),
};
await api.put<dynamic>('/igel/$id', body);
}
}