feat: Add User and UserBalance models with serialization methods
feat: Implement BalanceRepository for group balance calculations feat: Create ExpenseRepository for managing expenses feat: Add services for handling expenses and storage operations fix: Update import paths for models in repositories and services refactor: Rename CountContent to AccountContent in HomePage chore: Add StorageService for image upload and management
This commit is contained in:
79
lib/models/user.dart
Normal file
79
lib/models/user.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class User {
|
||||
final String? id;
|
||||
final String nom;
|
||||
final String prenom;
|
||||
final String email;
|
||||
|
||||
User({
|
||||
this.id,
|
||||
required this.nom,
|
||||
required this.prenom,
|
||||
required this.email,
|
||||
});
|
||||
|
||||
// Constructeur pour créer un User depuis un Map (utile pour Firebase)
|
||||
factory User.fromMap(Map<String, dynamic> map) {
|
||||
return User(
|
||||
id: map['id'],
|
||||
nom: map['nom'] ?? '',
|
||||
prenom: map['prenom'] ?? '',
|
||||
email: map['email'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
// Constructeur pour créer un User depuis JSON
|
||||
factory User.fromJson(String jsonStr) {
|
||||
Map<String, dynamic> map = json.decode(jsonStr);
|
||||
return User.fromMap(map);
|
||||
}
|
||||
|
||||
// Méthode pour convertir un User en Map (utile pour Firebase)
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'nom': nom,
|
||||
'prenom': prenom,
|
||||
'email': email,
|
||||
};
|
||||
}
|
||||
|
||||
// Méthode pour convertir un User en JSON
|
||||
String toJson() {
|
||||
return json.encode(toMap());
|
||||
}
|
||||
|
||||
// Méthode pour obtenir le nom complet
|
||||
String get fullName => '$prenom $nom';
|
||||
|
||||
// Méthode pour créer une copie avec des modifications
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? nom,
|
||||
String? prenom,
|
||||
String? email,
|
||||
}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
nom: nom ?? this.nom,
|
||||
prenom: prenom ?? this.prenom,
|
||||
email: email ?? this.email,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'User(id: $id, nom: $nom, prenom: $prenom, email: $email)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other is User && other.email == email;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => email.hashCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user