Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>
Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.githu b.com> correcion de errores en llenado de tablas, primeras vistas frontend
This commit is contained in:
52
recolecta_app/lib/core/models/address_create_request.dart
Normal file
52
recolecta_app/lib/core/models/address_create_request.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
class AddressCreateRequest {
|
||||
const AddressCreateRequest({
|
||||
required this.label,
|
||||
required this.street,
|
||||
required this.colonia,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String street;
|
||||
final String colonia;
|
||||
|
||||
factory AddressCreateRequest.fromJson(Map<String, dynamic> json) {
|
||||
return AddressCreateRequest(
|
||||
label: _pickString(<dynamic>[json['label'], json['alias']]) ?? '',
|
||||
street: _pickString(<dynamic>[json['calle'], json['street']]) ?? '',
|
||||
colonia: _pickString(<dynamic>[json['colonia'], json['colony']]) ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'label': label,
|
||||
'calle': street,
|
||||
'colonia': colonia,
|
||||
};
|
||||
}
|
||||
|
||||
AddressCreateRequest copyWith({
|
||||
String? label,
|
||||
String? street,
|
||||
String? colonia,
|
||||
}) {
|
||||
return AddressCreateRequest(
|
||||
label: label ?? this.label,
|
||||
street: street ?? this.street,
|
||||
colonia: colonia ?? this.colonia,
|
||||
);
|
||||
}
|
||||
|
||||
static String? _pickString(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate != null && candidate.toString().isNotEmpty) {
|
||||
return candidate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
135
recolecta_app/lib/core/models/address_response.dart
Normal file
135
recolecta_app/lib/core/models/address_response.dart
Normal file
@@ -0,0 +1,135 @@
|
||||
class AddressResponse {
|
||||
const AddressResponse({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.label,
|
||||
required this.street,
|
||||
required this.colonia,
|
||||
required this.routeId,
|
||||
required this.verified,
|
||||
this.verifiedMethod,
|
||||
this.verifiedAt,
|
||||
this.createdAt,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String userId;
|
||||
final String label;
|
||||
final String street;
|
||||
final String colonia;
|
||||
final String routeId;
|
||||
final bool verified;
|
||||
final String? verifiedMethod;
|
||||
final String? verifiedAt;
|
||||
final String? createdAt;
|
||||
|
||||
factory AddressResponse.fromJson(Map<String, dynamic> json) {
|
||||
final payload = json['data'] is Map<String, dynamic>
|
||||
? json['data'] as Map<String, dynamic>
|
||||
: json;
|
||||
|
||||
return AddressResponse(
|
||||
id: _pickString(<dynamic>[payload['id'], json['id']]) ?? '',
|
||||
userId:
|
||||
_pickString(<dynamic>[
|
||||
payload['user_id'],
|
||||
payload['userId'],
|
||||
json['user_id'],
|
||||
json['userId'],
|
||||
]) ??
|
||||
'',
|
||||
label: _pickString(<dynamic>[payload['label'], json['label']]) ?? '',
|
||||
street:
|
||||
_pickString(<dynamic>[
|
||||
payload['calle'],
|
||||
payload['street'],
|
||||
json['calle'],
|
||||
json['street'],
|
||||
]) ??
|
||||
'',
|
||||
colonia:
|
||||
_pickString(<dynamic>[
|
||||
payload['colonia'],
|
||||
payload['colony'],
|
||||
json['colonia'],
|
||||
json['colony'],
|
||||
]) ??
|
||||
'',
|
||||
routeId:
|
||||
_pickString(<dynamic>[
|
||||
payload['route_id'],
|
||||
payload['routeId'],
|
||||
json['route_id'],
|
||||
json['routeId'],
|
||||
]) ??
|
||||
'',
|
||||
verified:
|
||||
_pickBool(<dynamic>[payload['verified'], json['verified']]) ?? false,
|
||||
verifiedMethod: _pickString(<dynamic>[
|
||||
payload['verified_method'],
|
||||
payload['verifiedMethod'],
|
||||
json['verified_method'],
|
||||
json['verifiedMethod'],
|
||||
]),
|
||||
verifiedAt: _pickString(<dynamic>[
|
||||
payload['verified_at'],
|
||||
payload['verifiedAt'],
|
||||
json['verified_at'],
|
||||
json['verifiedAt'],
|
||||
]),
|
||||
createdAt: _pickString(<dynamic>[
|
||||
payload['created_at'],
|
||||
payload['createdAt'],
|
||||
json['created_at'],
|
||||
json['createdAt'],
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'user_id': userId,
|
||||
'label': label,
|
||||
'calle': street,
|
||||
'colonia': colonia,
|
||||
'route_id': routeId,
|
||||
'verified': verified,
|
||||
'verified_method': verifiedMethod,
|
||||
'verified_at': verifiedAt,
|
||||
'created_at': createdAt,
|
||||
};
|
||||
}
|
||||
|
||||
static String? _pickString(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate != null && candidate.toString().isNotEmpty) {
|
||||
return candidate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool? _pickBool(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is bool) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate is String) {
|
||||
final normalized = candidate.toLowerCase();
|
||||
if (normalized == 'true') {
|
||||
return true;
|
||||
}
|
||||
if (normalized == 'false') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -14,24 +14,50 @@ class Colonia {
|
||||
final String? turno;
|
||||
|
||||
factory Colonia.fromJson(Map<String, dynamic> json) {
|
||||
final rawId =
|
||||
json['id'] ??
|
||||
json['routeId'] ??
|
||||
json['route_id'] ??
|
||||
json['nombre'] ??
|
||||
json['name'];
|
||||
final rawNombre = json['nombre'] ?? json['name'] ?? rawId;
|
||||
final rawNombre = _pickString(<dynamic>[
|
||||
json['nombre'],
|
||||
json['colonia'],
|
||||
json['name'],
|
||||
]);
|
||||
final rawRouteId = _pickString(<dynamic>[
|
||||
json['routeId'],
|
||||
json['route_id'],
|
||||
]);
|
||||
final rawId = _pickString(<dynamic>[json['id'], rawRouteId, rawNombre]);
|
||||
|
||||
return Colonia(
|
||||
id: rawId?.toString() ?? rawNombre?.toString() ?? '',
|
||||
nombre: rawNombre?.toString() ?? '',
|
||||
routeId: (json['routeId'] ?? json['route_id'])?.toString(),
|
||||
horarioEstimado:
|
||||
(json['horario_estimado'] ??
|
||||
json['horarioEstimado'] ??
|
||||
json['schedule'])
|
||||
?.toString(),
|
||||
turno: (json['turno'] ?? json['shift'])?.toString(),
|
||||
id: rawId ?? '',
|
||||
nombre: rawNombre ?? rawId ?? '',
|
||||
routeId: rawRouteId,
|
||||
horarioEstimado: _pickString(<dynamic>[
|
||||
json['horario_estimado'],
|
||||
json['horarioEstimado'],
|
||||
json['schedule'],
|
||||
]),
|
||||
turno: _pickString(<dynamic>[json['turno'], json['shift']]),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'nombre': nombre,
|
||||
'routeId': routeId,
|
||||
'horario_estimado': horarioEstimado,
|
||||
'turno': turno,
|
||||
};
|
||||
}
|
||||
|
||||
static String? _pickString(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate != null && candidate.toString().isNotEmpty) {
|
||||
return candidate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
101
recolecta_app/lib/core/models/login_response.dart
Normal file
101
recolecta_app/lib/core/models/login_response.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'user.dart';
|
||||
|
||||
class LoginResponse {
|
||||
const LoginResponse({
|
||||
required this.accessToken,
|
||||
this.tokenType = 'bearer',
|
||||
required this.userId,
|
||||
required this.role,
|
||||
this.routeId,
|
||||
this.user,
|
||||
});
|
||||
|
||||
final String accessToken;
|
||||
final String tokenType;
|
||||
final String userId;
|
||||
final String role;
|
||||
final String? routeId;
|
||||
final User? user;
|
||||
|
||||
factory LoginResponse.fromJson(Map<String, dynamic> json) {
|
||||
final payload = json['data'] is Map<String, dynamic>
|
||||
? json['data'] as Map<String, dynamic>
|
||||
: json;
|
||||
|
||||
final userJson = payload['user'] is Map<String, dynamic>
|
||||
? payload['user'] as Map<String, dynamic>
|
||||
: null;
|
||||
|
||||
return LoginResponse(
|
||||
accessToken:
|
||||
_pickString(<dynamic>[
|
||||
payload['access_token'],
|
||||
payload['token'],
|
||||
payload['jwt'],
|
||||
json['access_token'],
|
||||
json['token'],
|
||||
json['jwt'],
|
||||
]) ??
|
||||
'',
|
||||
tokenType:
|
||||
_pickString(<dynamic>[
|
||||
payload['token_type'],
|
||||
payload['tokenType'],
|
||||
json['token_type'],
|
||||
json['tokenType'],
|
||||
]) ??
|
||||
'bearer',
|
||||
userId:
|
||||
_pickString(<dynamic>[
|
||||
payload['user_id'],
|
||||
payload['userId'],
|
||||
payload['id'],
|
||||
json['user_id'],
|
||||
json['userId'],
|
||||
json['id'],
|
||||
]) ??
|
||||
'',
|
||||
role:
|
||||
_pickString(<dynamic>[
|
||||
payload['role'],
|
||||
payload['user_role'],
|
||||
payload['userRole'],
|
||||
json['role'],
|
||||
json['user_role'],
|
||||
json['userRole'],
|
||||
]) ??
|
||||
'citizen',
|
||||
routeId: _pickString(<dynamic>[
|
||||
payload['route_id'],
|
||||
payload['routeId'],
|
||||
json['route_id'],
|
||||
json['routeId'],
|
||||
]),
|
||||
user: userJson == null ? null : User.fromJson(userJson),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'access_token': accessToken,
|
||||
'token_type': tokenType,
|
||||
'user_id': userId,
|
||||
'role': role,
|
||||
'route_id': routeId,
|
||||
if (user != null) 'user': user!.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
static String? _pickString(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate != null && candidate.toString().isNotEmpty) {
|
||||
return candidate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
8
recolecta_app/lib/core/models/models.dart
Normal file
8
recolecta_app/lib/core/models/models.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
export 'address.dart';
|
||||
export 'address_create_request.dart';
|
||||
export 'address_response.dart';
|
||||
export 'auth_session.dart';
|
||||
export 'auth_state.dart';
|
||||
export 'colonia.dart';
|
||||
export 'login_response.dart';
|
||||
export 'user.dart';
|
||||
50
recolecta_app/lib/core/models/user.dart
Normal file
50
recolecta_app/lib/core/models/user.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
class User {
|
||||
const User({
|
||||
required this.id,
|
||||
this.email,
|
||||
this.phone,
|
||||
required this.role,
|
||||
this.routeId,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String? email;
|
||||
final String? phone;
|
||||
final String role;
|
||||
final String? routeId;
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
id:
|
||||
_pickString(<dynamic>[json['id'], json['user_id'], json['userId']]) ??
|
||||
'',
|
||||
email: _pickString(<dynamic>[json['email'], json['mail']]),
|
||||
phone: _pickString(<dynamic>[json['phone'], json['telefono']]),
|
||||
role: _pickString(<dynamic>[json['role'], json['rol']]) ?? 'citizen',
|
||||
routeId: _pickString(<dynamic>[json['routeId'], json['route_id']]),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
'role': role,
|
||||
'routeId': routeId,
|
||||
};
|
||||
}
|
||||
|
||||
static String? _pickString(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate != null && candidate.toString().isNotEmpty) {
|
||||
return candidate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user