Docs: Schreib Docs
This commit is contained in:
@@ -14,16 +14,14 @@ class TransactionRepository {
|
||||
}
|
||||
|
||||
/// Entfernt eine Transaktion aus der Datenbank
|
||||
Future<int> remove(final Transaction transaction) async {
|
||||
return (_db.delete(_db.transactions)
|
||||
..where((t) => t.id.equals(transaction.id))).go();
|
||||
}
|
||||
Future<int> remove(final Transaction transaction) => (_db.delete(
|
||||
_db.transactions,
|
||||
)..where((final t) => t.id.equals(transaction.id))).go();
|
||||
|
||||
/// Sucht eine Transaktion anhand seiner Id aus der Datenbank
|
||||
Future<Transaction?> find(final int id) async {
|
||||
return (_db.select(_db.transactions)
|
||||
..where((t) => t.id.equals(id))).getSingleOrNull();
|
||||
}
|
||||
Future<Transaction?> find(final int id) => (_db.select(
|
||||
_db.transactions,
|
||||
)..where((final t) => t.id.equals(id))).getSingleOrNull();
|
||||
|
||||
/// Sucht Transaktionen anhand der gegebenen Parameter aus der Datenbank
|
||||
Future<List<Transaction>> findBy({
|
||||
@@ -36,61 +34,56 @@ class TransactionRepository {
|
||||
final double? amountMin,
|
||||
final double? amountMax,
|
||||
final String? orderBy,
|
||||
}) async {
|
||||
final query = _db.select(_db.transactions);
|
||||
}) {
|
||||
final SimpleSelectStatement<$TransactionsTable, Transaction> query = _db
|
||||
.select(_db.transactions);
|
||||
|
||||
if (id != null) {
|
||||
query.where((t) => t.id.equals(id));
|
||||
query.where((final t) => t.id.equals(id));
|
||||
}
|
||||
|
||||
if (name != null && name.isNotEmpty) {
|
||||
query.where((t) => t.name.like('%$name%'));
|
||||
query.where((final t) => t.name.like('%$name%'));
|
||||
}
|
||||
|
||||
if (date != null) {
|
||||
query.where((t) => t.date.equals(date));
|
||||
query.where((final t) => t.date.equals(date));
|
||||
}
|
||||
|
||||
if (dateBefore != null) {
|
||||
query.where((t) => t.date.isBiggerThanValue(dateBefore));
|
||||
query.where((final t) => t.date.isBiggerThanValue(dateBefore));
|
||||
}
|
||||
|
||||
if (dateAfter != null) {
|
||||
query.where((t) => t.date.isSmallerThanValue(dateAfter));
|
||||
query.where((final t) => t.date.isSmallerThanValue(dateAfter));
|
||||
}
|
||||
|
||||
if (amount != null) {
|
||||
query.where((t) => t.amount.equals(amount));
|
||||
query.where((final t) => t.amount.equals(amount));
|
||||
}
|
||||
|
||||
if (amountMin != null) {
|
||||
query.where((t) => t.amount.isBiggerThanValue(amountMin));
|
||||
query.where((final t) => t.amount.isBiggerThanValue(amountMin));
|
||||
}
|
||||
|
||||
if (amountMax != null) {
|
||||
query.where((t) => t.amount.isSmallerThanValue(amountMax));
|
||||
query.where((final t) => t.amount.isSmallerThanValue(amountMax));
|
||||
}
|
||||
|
||||
if (orderBy != null) {
|
||||
switch (orderBy) {
|
||||
case 'nameAsc':
|
||||
query.orderBy([(t) => OrderingTerm.asc(t.name)]);
|
||||
break;
|
||||
query.orderBy([(final t) => OrderingTerm.asc(t.name)]);
|
||||
case 'nameDesc':
|
||||
query.orderBy([(t) => OrderingTerm.desc(t.name)]);
|
||||
break;
|
||||
query.orderBy([(final t) => OrderingTerm.desc(t.name)]);
|
||||
case 'dateAsc':
|
||||
query.orderBy([(t) => OrderingTerm.asc(t.date)]);
|
||||
break;
|
||||
query.orderBy([(final t) => OrderingTerm.asc(t.date)]);
|
||||
case 'dateDesc':
|
||||
query.orderBy([(t) => OrderingTerm.desc(t.date)]);
|
||||
break;
|
||||
query.orderBy([(final t) => OrderingTerm.desc(t.date)]);
|
||||
case 'amountAsc':
|
||||
query.orderBy([(t) => OrderingTerm.asc(t.amount)]);
|
||||
break;
|
||||
query.orderBy([(final t) => OrderingTerm.asc(t.amount)]);
|
||||
case 'amountDesc':
|
||||
query.orderBy([(t) => OrderingTerm.desc(t.amount)]);
|
||||
break;
|
||||
query.orderBy([(final t) => OrderingTerm.desc(t.amount)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user