feat: login api

This commit is contained in:
efrilm
2025-08-16 17:27:57 +07:00
parent 6019036cd7
commit 255b10d5a9
31 changed files with 2997 additions and 86 deletions
+23
View File
@@ -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(),
);
}
+39
View File
@@ -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),
);
}