24 lines
589 B
Dart
24 lines
589 B
Dart
|
|
part of '../auth_dtos.dart';
|
||
|
|
|
||
|
|
@freezed
|
||
|
|
class AuthDto with _$AuthDto {
|
||
|
|
const AuthDto._();
|
||
|
|
|
||
|
|
const factory AuthDto({
|
||
|
|
@JsonKey(name: 'token') String? token,
|
||
|
|
@JsonKey(name: 'expires_at') String? expiresAt,
|
||
|
|
@JsonKey(name: 'user') UserDto? user,
|
||
|
|
}) = _AuthDto;
|
||
|
|
|
||
|
|
factory AuthDto.fromJson(Map<String, dynamic> json) =>
|
||
|
|
_$AuthDtoFromJson(json);
|
||
|
|
|
||
|
|
Auth toDomain() => Auth(
|
||
|
|
token: token ?? '',
|
||
|
|
expiresAt: expiresAt != null
|
||
|
|
? DateTime.parse(expiresAt ?? "")
|
||
|
|
: DateTime.fromMillisecondsSinceEpoch(0),
|
||
|
|
user: user?.toDomain() ?? User.empty(),
|
||
|
|
);
|
||
|
|
}
|