159 lines
4.6 KiB
Dart
159 lines
4.6 KiB
Dart
|
|
|
|
import 'package:appwrite/appwrite.dart';
|
|
import 'package:appwrite/models.dart' as models;
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
|
|
class AppWriteProvider {
|
|
final szEndpoint = dotenv.env['APPWRITE_ENDPOINT_URL'] ?? '';
|
|
final szProjectID = dotenv.env['APPWRITE_PROJECT_ID'] ?? '';
|
|
final szDatabaseID = dotenv.env['APPWRITE_DATABASE_ID'] ?? '';
|
|
final szCollectionID = dotenv.env['APPWRITE_COLLECTION_ID'] ?? '';
|
|
final bSelfSignd = dotenv.env['APPWRITE_SELF_SIGNED'] == 'true';
|
|
|
|
|
|
|
|
Client client = Client();
|
|
Account? account;
|
|
Storage? storage;
|
|
Databases? database;
|
|
|
|
AppWriteProvider() {
|
|
client
|
|
..setEndpoint(szEndpoint) // Set your Appwrite endpoint
|
|
..setProject(szProjectID)
|
|
..setSelfSigned(status: bSelfSignd);
|
|
account = Account(client); // Set your Appwrite project ID
|
|
storage = Storage(client);
|
|
database = Databases(client);
|
|
}
|
|
|
|
Future<models.Session> login(Map map) async {
|
|
final response = await account!.createEmailPasswordSession(
|
|
email: map['email'],
|
|
password: map['password'],
|
|
);
|
|
return response;
|
|
}
|
|
|
|
Future<models.User> signup(Map map) async {
|
|
final response = await account!.create(
|
|
userId: ID.unique(),
|
|
email: map['email'],
|
|
password: map['password'],
|
|
name: map['name'],
|
|
);
|
|
return response;
|
|
}
|
|
|
|
Future<bool> logout() async {
|
|
try {
|
|
await account!.deleteSession(sessionId: 'current');
|
|
return true;
|
|
} catch (e) {
|
|
print('Fehler beim Ausloggen: $e');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// // Tank Stop Image Upload
|
|
// Future<models.File> uploadTankStopImage(String imagePath) async {
|
|
// String fileName =
|
|
// '${DateTime.now().millisecondsSinceEpoch}_${imagePath.split('.').last}';
|
|
|
|
// final response = await storage!.createFile(
|
|
// bucketId: kAppWriteBucket,
|
|
// fileId: ID.unique(),
|
|
// file: InputFile.fromPath(path: fileName, filename: fileName),
|
|
// );
|
|
// return response;
|
|
// }
|
|
|
|
// // Tank Stop Image get by fileID
|
|
// Future<models.File> getTankStopImage(String fileID) async {
|
|
// final response = await storage!.getFile(
|
|
// bucketId: kAppWriteBucket,
|
|
// fileId: fileID,
|
|
// );
|
|
// return response;
|
|
// }
|
|
|
|
// // Tank Stop Image delete by fileID
|
|
// Future<dynamic> deleteTankStopImage(String fileID) async {
|
|
// final response = await storage!.deleteFile(
|
|
// bucketId: kAppWriteBucket,
|
|
// fileId: fileID,
|
|
// );
|
|
// return response;
|
|
// }
|
|
|
|
// 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> updateTankStop(String documentId, Map map) async {
|
|
// final response = await database!.updateDocument(
|
|
// databaseId: kAppWriteDatabaseID,
|
|
// collectionId: kAppWriteCollectionID,
|
|
// 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.DocumentList> listTankStops(String userId) async {
|
|
// final response = await database!.listDocuments(
|
|
// databaseId: kAppWriteDatabaseID,
|
|
// collectionId: kAppWriteCollectionID,
|
|
// 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> createTrackPoint(map) async {
|
|
// final response = await database!.createDocument(
|
|
// databaseId: kAppWriteDatabaseID,
|
|
// collectionId: kAppWriteTrackPointsCollectionID,
|
|
// documentId: ID.unique(),
|
|
// data: map,
|
|
// );
|
|
// return response;
|
|
// }
|
|
|
|
// Future<models.Document> saveFullTrack(map) async {
|
|
// final response = await database!.createDocument(
|
|
// databaseId: kAppWriteDatabaseID,
|
|
// collectionId: kAppWriteTracksCollectionId,
|
|
// documentId: ID.unique(),
|
|
// data: map,
|
|
// );
|
|
// return response;
|
|
// }
|
|
}
|