feat: type schedule and auth models

This commit is contained in:
Artem Kokos
2026-04-23 20:57:15 +07:00
parent fa403bfcce
commit 0fdaf0bac4
11 changed files with 531 additions and 243 deletions

28
lib/models/auth_info.dart Normal file
View File

@@ -0,0 +1,28 @@
class AuthInfo {
final bool isAdmin;
final String? name;
const AuthInfo({required this.isAdmin, this.name});
static AuthInfo fromApi(Object? data) {
if (data is! Map) {
throw const FormatException('auth/me должен быть объектом');
}
final map = Map<String, dynamic>.from(data);
return AuthInfo(
isAdmin: _boolValue(map['is_admin']),
name: map['name']?.toString(),
);
}
}
bool _boolValue(Object? value) {
if (value is bool) return value;
if (value is num) return value != 0;
if (value is String) {
final normalized = value.trim().toLowerCase();
return normalized == 'true' || normalized == '1';
}
return false;
}