feat: login api
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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(),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
part of '../auth_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class UserDto with _$UserDto {
|
||||
const UserDto._();
|
||||
|
||||
const factory UserDto({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'organization_id') String? organizationId,
|
||||
@JsonKey(name: 'outlet_id') String? outletId,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'email') String? email,
|
||||
@JsonKey(name: 'role') String? role,
|
||||
@JsonKey(name: 'permissions') Map<String, dynamic>? permissions,
|
||||
@JsonKey(name: 'is_active') bool? isActive,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
}) = _UserDto;
|
||||
|
||||
factory UserDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$UserDtoFromJson(json);
|
||||
|
||||
User toDomain() => User(
|
||||
id: id ?? '',
|
||||
organizationId: organizationId ?? '',
|
||||
outletId: outletId ?? '',
|
||||
name: name ?? '',
|
||||
email: email ?? '',
|
||||
role: role ?? '',
|
||||
permissions: permissions ?? {},
|
||||
isActive: isActive ?? false,
|
||||
createdAt: createdAt != null
|
||||
? DateTime.parse(createdAt ?? "")
|
||||
: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
updatedAt: updatedAt != null
|
||||
? DateTime.parse(updatedAt ?? "")
|
||||
: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user