Created
August 8, 2021 21:27
-
-
Save guilhermecarvalhocarneiro/c58ec7a91628eaa4709e5c2a080a52b6 to your computer and use it in GitHub Desktop.
Classe de modelo nullsafety
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Model do objeto Paciente | |
/// | |
/// Os Métodos padrões gerados são: | |
/// toString() -> Sobrescreve o toString para trazer todos os atributos da classe. | |
/// fromMap() -> Realiza o parser do Json para o Model. | |
/// toMap() -> Realiza o parser do Model para Json. | |
/// | |
/// [Travar o arquivo] | |
/// Caso deseje "travar" o arquivo para não ser parseado novamente | |
/// pelo manage do Django adicione um # antes da palavra abaixo | |
/// FileLocked | |
import '../../../utils/util.dart'; | |
import '../../../utils/exception.dart'; | |
class PacienteModel { | |
String? id; | |
String? nextUrl; | |
String? previousUrl; | |
bool? enabled; | |
bool? deleted; | |
DateTime? createdOn; | |
DateTime? updatedOn; | |
int? djangoUser; | |
String? cpf; | |
late String nome; | |
String? email; | |
String? telefone; | |
String? token; | |
String? firebase; | |
String? accessToken; | |
String? idToken; | |
double? latitude; | |
double? longitude; | |
String? endereco; | |
int? usuarioPtr; | |
String? sexo; | |
DateTime? dataNascimento; | |
PacienteModel({ | |
required this.nome, | |
this.id, | |
this.nextUrl, | |
this.previousUrl, | |
this.enabled, | |
this.deleted, | |
this.createdOn, | |
this.updatedOn, | |
this.djangoUser, | |
this.cpf, | |
this.email, | |
this.telefone, | |
this.token, | |
this.firebase, | |
this.accessToken, | |
this.idToken, | |
this.latitude, | |
this.longitude, | |
this.endereco, | |
this.usuarioPtr, | |
this.sexo, | |
this.dataNascimento, | |
}); | |
PacienteModel.fromMap(Map<String, dynamic> json) { | |
try { | |
id = json.containsKey('id') ? json['id'] : ""; | |
nextUrl = json.containsKey('nextUrl') ? json['nextUrl'] : ""; | |
previousUrl = json.containsKey('previousUrl') ? json['previousUrl'] : ""; | |
enabled = json['enabled'] == null ? true : json['enabled']; | |
deleted = json['deleted'] == null ? false : json['deleted']; | |
createdOn = Util.convertDate(json['created_on']) == null ? null : Util.convertDate(json['created_on']); | |
updatedOn = Util.convertDate(json['updated_on']) == null ? null : Util.convertDate(json['updated_on']); | |
djangoUser = json['django_user'] == null ? "" : json['django_user']; | |
cpf = json['cpf'] == null ? "" : json['cpf']; | |
nome = json['nome'] == null ? "" : json['nome']; | |
email = json['email'] == null ? "" : json['email']; | |
telefone = json['telefone'] == null ? "" : json['telefone']; | |
token = json['token'] == null ? "" : json['token']; | |
firebase = json['firebase'] == null ? "" : json['firebase']; | |
accessToken = json['access_token'] == null ? "" : json['access_token']; | |
idToken = json['id_token'] == null ? "" : json['id_token']; | |
latitude = json['latitude'] == null ? null : double.parse(json['latitude']); | |
longitude = json['longitude'] == null ? null : double.parse(json['longitude']); | |
endereco = json['endereco'] == null ? "" : json['endereco']; | |
usuarioPtr = json['usuario_ptr'] == null ? "" : json['usuario_ptr']; | |
sexo = json['sexo'] == null ? "" : json['sexo']; | |
dataNascimento = | |
Util.convertDate(json['data_nascimento']) == null ? null : Util.convertDate(json['data_nascimento']); | |
} catch (error) { | |
ExceptionCustom.general("Ocorreu um erro no método fromMap do PacienteModel", error.toString()); | |
} | |
} | |
Map<String, dynamic>? toMap() { | |
try { | |
return { | |
"nextUrl": nextUrl == null ? null : nextUrl, | |
"previousUrl": previousUrl == null ? null : previousUrl, | |
'enabled': this.enabled != null ? this.enabled : true, | |
'deleted': this.deleted != null ? this.deleted : false, | |
'created_on': this.createdOn.toString(), | |
'updated_on': this.updatedOn.toString(), | |
'django_user': this.djangoUser != null ? this.djangoUser : "", | |
'cpf': this.cpf != null ? this.cpf : "", | |
'nome': this.nome, | |
'email': this.email != null ? this.email : "", | |
'telefone': this.telefone != null ? this.telefone : "", | |
'token': this.token != null ? this.token : "", | |
'firebase': this.firebase != null ? this.firebase : "", | |
'access_token': this.accessToken != null ? this.accessToken : "", | |
'id_token': this.idToken != null ? this.idToken : "", | |
'latitude': this.latitude != null ? this.latitude : "", | |
'longitude': this.longitude != null ? this.longitude : "", | |
'endereco': this.endereco != null ? this.endereco : "", | |
'usuario_ptr': this.usuarioPtr != null ? this.usuarioPtr : "", | |
'sexo': this.sexo != null ? this.sexo : "", | |
'data_nascimento': | |
this.dataNascimento != null ? Util.stringDateTimeSplit(this.dataNascimento, returnType: "d") : null, | |
}; | |
} catch (error) { | |
ExceptionCustom.general("Ocorreu um erro no método toMap do PacienteModel", error.toString()); | |
} | |
return null; | |
} | |
/// Sobscrevendo o método toString para retornar todos os atributos da classe. | |
@override | |
String toString() { | |
return "ENABLED: $enabled\nDELETED: $deleted\nCREATEDON: $createdOn\nUPDATEDON: $updatedOn\nDJANGOUSER: $djangoUser\nCPF: $cpf\nNOME: $nome\nEMAIL: $email\nTELEFONE: $telefone\nTOKEN: $token\nFIREBASE: $firebase\nACCESSTOKEN: $accessToken\nIDTOKEN: $idToken\nLATITUDE: $latitude\nLONGITUDE: $longitude\nENDERECO: $endereco\nUSUARIOPTR: $usuarioPtr\nSEXO: $sexo\nDATANASCIMENTO: $dataNascimento\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment