apskel-pos-flutter/lib/data/models/response/auth_response_model.dart

84 lines
2.0 KiB
Dart
Raw Permalink Normal View History

2025-07-30 22:38:44 +07:00
import 'dart:convert';
class AuthResponseModel {
2025-08-02 23:10:48 +07:00
final String? token;
final User? user;
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
AuthResponseModel({
this.token,
this.user,
});
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
factory AuthResponseModel.fromJson(String str) =>
AuthResponseModel.fromMap(json.decode(str));
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
String toJson() => json.encode(toMap());
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
factory AuthResponseModel.fromMap(Map<String, dynamic> json) =>
AuthResponseModel(
2025-07-30 22:38:44 +07:00
token: json["token"],
user: json["user"] == null ? null : User.fromMap(json["user"]),
2025-08-02 23:10:48 +07:00
);
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
Map<String, dynamic> toMap() => {
2025-07-30 22:38:44 +07:00
"token": token,
"user": user?.toMap(),
2025-08-02 23:10:48 +07:00
};
2025-07-30 22:38:44 +07:00
}
class User {
2025-08-02 23:10:48 +07:00
final String? id;
final String? organizationId;
2025-08-05 15:25:10 +07:00
String? outletId;
2025-08-02 23:10:48 +07:00
final String? name;
final String? email;
final String? role;
final bool? isActive;
final DateTime? createdAt;
final DateTime? updatedAt;
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
User({
this.id,
this.organizationId,
this.outletId,
this.name,
this.role,
this.isActive,
this.email,
this.createdAt,
this.updatedAt,
});
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
factory User.fromJson(String str) => User.fromMap(json.decode(str));
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
String toJson() => json.encode(toMap());
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
factory User.fromMap(Map<String, dynamic> json) => User(
2025-07-30 22:38:44 +07:00
id: json["id"],
2025-08-02 23:10:48 +07:00
organizationId: json["organization_id"],
outletId: json["outlet_id"],
2025-07-30 22:38:44 +07:00
name: json["name"],
email: json["email"],
role: json["role"],
2025-08-02 23:10:48 +07:00
isActive: json["is_active"],
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
2025-07-30 22:38:44 +07:00
2025-08-02 23:10:48 +07:00
Map<String, dynamic> toMap() => {
2025-07-30 22:38:44 +07:00
"id": id,
2025-08-02 23:10:48 +07:00
"organization_id": organizationId,
"outlet_id": outletId,
2025-07-30 22:38:44 +07:00
"name": name,
"email": email,
2025-08-02 23:10:48 +07:00
"role": role,
"is_active": isActive,
2025-07-30 22:38:44 +07:00
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
2025-08-02 23:10:48 +07:00
};
2025-07-30 22:38:44 +07:00
}