Skip to content

Commit

Permalink
fix time issue
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Aug 9, 2024
1 parent 3545705 commit 6dd78bf
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 185 deletions.
24 changes: 9 additions & 15 deletions lib/api/apis/aggregated_expense_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ class AggregatedExpenseApi {

Future<int> create(
{required final double amount,
required final int year,
required final int month,
required final DateTime month,
required final String tags}) async {
return _db.into(_db.aggregatedExpenseTable).insert(
AggregatedExpenseTableCompanion.insert(
amount: amount, tags: tags, year: year, month: month));
amount: amount, tags: tags, month: month));
}

Future<List<AggregatedExpenseDO>> get() async {
return (_db.select(_db.aggregatedExpenseTable)
..orderBy([(t) => OrderingTerm(expression: t.year)]))
..orderBy([(t) => OrderingTerm(expression: t.month)]))
.get();
}

Expand All @@ -30,26 +29,21 @@ class AggregatedExpenseApi {
}

Future<AggregatedExpenseDO?> getByMonthAndTag(
{required final int year, required final int month, required final String tags}) async {
{required final DateTime month, required final String tags}) async {
return (_db.select(_db.aggregatedExpenseTable)
..where((t) =>
t.year.equals(year) & t.month.equals(month) & t.tags.equals(tags)))
..where((t) => t.month.equals(month) & t.tags.equals(tags)))
.getSingleOrNull();
}

Future<int> update(
{required final int id,
required final double amount,
required final int year,
required final int month,
required final DateTime month,
required final String tags}) async {
return (_db.update(_db.aggregatedExpenseTable)
..where((t) => t.id.equals(id)))
.write(AggregatedExpenseTableCompanion(
amount: Value(amount),
tags: Value(tags),
year: Value(year),
month: Value(month)));
amount: Value(amount), tags: Value(tags), month: Value(month)));
}

Future<int> deleteBy({required final int id}) async {
Expand All @@ -58,9 +52,9 @@ class AggregatedExpenseApi {
.go();
}

Future<int> deleteByMonthDate({required final int year, required final int month}) async {
Future<int> deleteByMonthDate({required final DateTime month}) async {
return (_db.delete(_db.aggregatedExpenseTable)
..where((t) => t.year.equals(year) & t.month.equals(month)))
..where((t) => t.month.equals(month)))
.go();
}
}
9 changes: 4 additions & 5 deletions lib/api/apis/expense_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class ExpenseApi {
{required final int year, required final int month}) async {
return (_db.select(_db.expenseTable)
..where((t) =>
t.createdOn.year.equals(year) &
t.createdOn.month.equals(month))
t.createdOn.year.equals(year) & t.createdOn.month.equals(month))
..orderBy([(t) => OrderingTerm(expression: t.createdOn)]))
.get();
}
Expand Down Expand Up @@ -57,11 +56,11 @@ class ExpenseApi {
return (_db.delete(_db.expenseTable)..where((t) => t.id.equals(id))).go();
}

Future<int> deleteByMonthDate({required final int year, required final int month}) async {
Future<int> deleteByMonthDate({required final DateTime month}) async {
return (_db.delete(_db.expenseTable)
..where((t) =>
t.createdOn.year.equals(year) &
t.createdOn.month.equals(month)))
t.createdOn.year.equals(month.year) &
t.createdOn.month.equals(month.month)))
.go();
}
}
6 changes: 1 addition & 5 deletions lib/api/db/app_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class InvestmentTable extends Table {
DateTimeColumn get maturityDate =>
dateTime().nullable().named('MATURITY_DATE')();

DateTimeColumn get valueUpdatedDate =>
dateTime().nullable().named('VALUE_UPDATED_DATE')();

TextColumn get riskLevel => textEnum<RiskLevel>().named('RISK_LEVEL')();
}

Expand Down Expand Up @@ -273,8 +270,7 @@ class AggregatedExpenseTable extends Table {
RealColumn get amount => real().named('AMOUNT')();
TextColumn get tags => text().named('TAGS')();

IntColumn get month => integer().named('MONTH')();
IntColumn get year => integer().named('YEAR')();
DateTimeColumn get month => dateTime().named('MONTH')();
}

@DataClassName('ExpenseTagDO')
Expand Down
Loading

0 comments on commit 6dd78bf

Please sign in to comment.