Skip to content

Commit

Permalink
Add sorting to list items
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jan 1, 2024
1 parent f92d1c9 commit 5c23d02
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/api/apis/basket_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class BasketApi {
BasketApi({final AppDatabase? db}) : _db = db ?? AppDatabase.instance;

Future<List<BasketDO>> getBaskets() async {
return _db.select(_db.basketTable).get();
return (_db.select(_db.basketTable)
..orderBy([(t) => OrderingTerm(expression: t.name)]))
.get();
}

Future<int> createBasket({required final String name}) async {
Expand Down
7 changes: 5 additions & 2 deletions lib/api/apis/goal_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ class GoalApi {
GoalApi({final AppDatabase? db}) : _db = db ?? AppDatabase.instance;

Future<List<GoalDO>> getGoals() async {
return _db.select(_db.goalTable).get();
return (_db.select(_db.goalTable)
..orderBy([(t) => OrderingTerm.asc(t.targetDate)]))
.get();
}

Future<GoalDO> getGoal({required final int id}) async {
return (_db.select(_db.goalTable)..where((t) => t.id.equals(id))).getSingle();
return (_db.select(_db.goalTable)..where((t) => t.id.equals(id)))
.getSingle();
}

Future<int> createGoal(
Expand Down
15 changes: 11 additions & 4 deletions lib/api/apis/investment_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ class InvestmentApi {
InvestmentApi({final AppDatabase? db}) : _db = db ?? AppDatabase.instance;

Future<List<InvestmentDO>> getInvestments() async {
return _db.select(_db.investmentTable).get();
return (_db.select(_db.investmentTable)
..orderBy([(t) => OrderingTerm.asc(t.name)]))
.get();
}

Future<List<InvestmentEnrichedDO>> getEnrichedInvestments() async {
return _db.select(_db.investmentEnrichedView).get();
return (_db.select(_db.investmentEnrichedView)
..orderBy([(t) => OrderingTerm.asc(t.name)]))
.get();
}

Future<List<TransactionDO>> getTransactions({final int? investmentId}) async {
if (investmentId == null) {
return _db.select(_db.transactionTable).get();
return (_db.select(_db.transactionTable)
..orderBy([(t) => OrderingTerm.desc(t.amountInvestedOn)]))
.get();
} else {
return (_db.select(_db.transactionTable)
..where((t) => t.investmentId.equals(investmentId)))
..where((t) => t.investmentId.equals(investmentId))
..orderBy([(t) => OrderingTerm.desc(t.amountInvestedOn)]))
.get();
}
}
Expand Down

0 comments on commit 5c23d02

Please sign in to comment.