generated from josiadmin/flutter-template-getx-provider
mod repository appwrite
This commit is contained in:
107
lib/models/tank_model.dart
Normal file
107
lib/models/tank_model.dart
Normal file
@@ -0,0 +1,107 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
class TankModel {
|
||||
final String documentId;
|
||||
final String userId;
|
||||
final String date;
|
||||
final String odometer;
|
||||
final String liters;
|
||||
final String pricePerLiter;
|
||||
final String location;
|
||||
final String totalPrice;
|
||||
TankModel({
|
||||
required this.documentId,
|
||||
required this.userId,
|
||||
required this.date,
|
||||
required this.odometer,
|
||||
required this.liters,
|
||||
required this.pricePerLiter,
|
||||
required this.location,
|
||||
required this.totalPrice,
|
||||
});
|
||||
|
||||
TankModel copyWith({
|
||||
String? documentId,
|
||||
String? userId,
|
||||
String? date,
|
||||
String? odometer,
|
||||
String? liters,
|
||||
String? pricePerLiter,
|
||||
String? location,
|
||||
String? totalPrice,
|
||||
}) {
|
||||
return TankModel(
|
||||
documentId: documentId ?? this.documentId,
|
||||
userId: userId ?? this.userId,
|
||||
date: date ?? this.date,
|
||||
odometer: odometer ?? this.odometer,
|
||||
liters: liters ?? this.liters,
|
||||
pricePerLiter: pricePerLiter ?? this.pricePerLiter,
|
||||
location: location ?? this.location,
|
||||
totalPrice: totalPrice ?? this.totalPrice,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return <String, dynamic>{
|
||||
'documentId': documentId,
|
||||
'userId': userId,
|
||||
'date': date,
|
||||
'odometer': odometer,
|
||||
'liters': liters,
|
||||
'pricePerLiter': pricePerLiter,
|
||||
'location': location,
|
||||
'totalPrice': totalPrice,
|
||||
};
|
||||
}
|
||||
|
||||
factory TankModel.fromMap(Map<String, dynamic> map) {
|
||||
return TankModel(
|
||||
documentId: map['documentId'] as String,
|
||||
userId: map['userId'] as String,
|
||||
date: map['date'] as String,
|
||||
odometer: map['odometer'] as String,
|
||||
liters: map['liters'] as String,
|
||||
pricePerLiter: map['pricePerLiter'] as String,
|
||||
location: map['location'] as String,
|
||||
totalPrice: map['totalPrice'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory TankModel.fromJson(String source) => TankModel.fromMap(json.decode(source) as Map<String, dynamic>);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TankModel(documentId: $documentId, userId: $userId, date: $date, odometer: $odometer, liters: $liters, pricePerLiter: $pricePerLiter, location: $location, totalPrice: $totalPrice)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant TankModel other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return
|
||||
other.documentId == documentId &&
|
||||
other.userId == userId &&
|
||||
other.date == date &&
|
||||
other.odometer == odometer &&
|
||||
other.liters == liters &&
|
||||
other.pricePerLiter == pricePerLiter &&
|
||||
other.location == location &&
|
||||
other.totalPrice == totalPrice;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return documentId.hashCode ^
|
||||
userId.hashCode ^
|
||||
date.hashCode ^
|
||||
odometer.hashCode ^
|
||||
liters.hashCode ^
|
||||
pricePerLiter.hashCode ^
|
||||
location.hashCode ^
|
||||
totalPrice.hashCode;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ class AppWriteProvider {
|
||||
}
|
||||
|
||||
Future<models.Session> login(Map map) async {
|
||||
await logout();
|
||||
final response = await account!.createEmailPasswordSession(
|
||||
email: map['email'],
|
||||
password: map['password'],
|
||||
@@ -89,52 +90,52 @@ class AppWriteProvider {
|
||||
|
||||
// Tank Stop CRUD operations
|
||||
// Create, Update, Get, List Tank Stops
|
||||
// Future<models.Document> createTankStop(Map map) async {
|
||||
// final response = await database!.createDocument(
|
||||
// databaseId: kAppWriteDatabaseID,
|
||||
// collectionId: kAppWriteCollectionID,
|
||||
// documentId: ID.unique(),
|
||||
// data: map,
|
||||
// );
|
||||
// return response;
|
||||
// }
|
||||
Future<models.Document> createTankStop(Map map) async {
|
||||
final response = await database!.createDocument(
|
||||
databaseId: szDatabaseID,
|
||||
collectionId: szCollectionID,
|
||||
documentId: ID.unique(),
|
||||
data: map,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
// Future<models.Document> updateTankStop(String documentId, Map map) async {
|
||||
// final response = await database!.updateDocument(
|
||||
// databaseId: kAppWriteDatabaseID,
|
||||
// collectionId: kAppWriteCollectionID,
|
||||
// documentId: documentId,
|
||||
// data: map,
|
||||
// );
|
||||
// return response;
|
||||
// }
|
||||
Future<models.Document> updateTankStop(String documentId, Map map) async {
|
||||
final response = await database!.updateDocument(
|
||||
databaseId: szDatabaseID,
|
||||
collectionId: szCollectionID,
|
||||
documentId: documentId,
|
||||
data: map,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
// Future<models.Document> getTankStopById(String documentId) async {
|
||||
// final response = await database!.getDocument(
|
||||
// databaseId: kAppWriteDatabaseID,
|
||||
// collectionId: kAppWriteCollectionID,
|
||||
// documentId: documentId,
|
||||
// );
|
||||
// return response;
|
||||
// }
|
||||
Future<models.Document> getTankStopById(String documentId) async {
|
||||
final response = await database!.getDocument(
|
||||
databaseId: szDatabaseID,
|
||||
collectionId: szCollectionID,
|
||||
documentId: documentId,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
// Future<models.DocumentList> listTankStops(String userId) async {
|
||||
// final response = await database!.listDocuments(
|
||||
// databaseId: kAppWriteDatabaseID,
|
||||
// collectionId: kAppWriteCollectionID,
|
||||
// queries: [Query.equal('userId', userId)],
|
||||
// );
|
||||
// return response;
|
||||
// }
|
||||
Future<models.DocumentList> listTankStops(String userId) async {
|
||||
final response = await database!.listDocuments(
|
||||
databaseId: szDatabaseID,
|
||||
collectionId: szCollectionID,
|
||||
queries: [Query.equal('userId', userId)],
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
// Future<models.Document> deleteTankStop(String documentId) async {
|
||||
// final response = await database!.deleteDocument(
|
||||
// databaseId: kAppWriteDatabaseID,
|
||||
// collectionId: kAppWriteCollectionID,
|
||||
// documentId: documentId,
|
||||
// );
|
||||
// return response;
|
||||
// }
|
||||
Future<models.Document> deleteTankStop(String documentId) async {
|
||||
final response = await database!.deleteDocument(
|
||||
databaseId: szDatabaseID,
|
||||
collectionId: szCollectionID,
|
||||
documentId: documentId,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
// Future<models.Document> createTrackPoint(map) async {
|
||||
// final response = await database!.createDocument(
|
||||
|
||||
Reference in New Issue
Block a user