-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcdb8b7
commit d562bd0
Showing
14 changed files
with
1,156 additions
and
786 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
final epoch = DateTime.utc(2024, 1, 1); | ||
const int DB_PAGINATION_QUERY = 50; | ||
const DB_PAGINATION_QUERY = 50; | ||
const DEFAULT_ADMIN_USERNAME = "admin"; | ||
const DEFAULT_ADMIN_PASSWORD = "NgaiLongGey"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import "snowflake.dart"; | ||
import "../utils.dart"; | ||
|
||
class Fee with Snowflake { | ||
@override | ||
final int id; | ||
|
||
final String name; | ||
final double lower; | ||
final double upper; | ||
final double perArea; | ||
final double perMotorbike; | ||
final double perCar; | ||
final Date deadline; | ||
final String description; | ||
final int flags; | ||
|
||
Fee({ | ||
required this.id, | ||
required this.name, | ||
required this.lower, | ||
required this.upper, | ||
required this.perArea, | ||
required this.perMotorbike, | ||
required this.perCar, | ||
required this.deadline, | ||
required this.description, | ||
required this.flags, | ||
}); | ||
|
||
Fee.fromJson(dynamic data) | ||
: this( | ||
id: data["id"] as int, | ||
name: data["name"] as String, | ||
lower: data["lower"] as double, | ||
upper: data["upper"] as double, | ||
perArea: data["per_area"] as double, | ||
perMotorbike: data["per_motorbike"] as double, | ||
perCar: data["per_car"] as double, | ||
deadline: Date.parse(data["deadline"] as String)!, | ||
description: data["description"] as String, | ||
flags: data["flags"] as int, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import "snowflake.dart"; | ||
|
||
class Payment with Snowflake { | ||
@override | ||
final int id; | ||
|
||
final int room; | ||
final double amount; | ||
final int feeId; | ||
|
||
Payment({ | ||
required this.id, | ||
required this.room, | ||
required this.amount, | ||
required this.feeId, | ||
}); | ||
|
||
Payment.fromJson(dynamic data) | ||
: this( | ||
id: data["id"] as int, | ||
room: data["room"] as int, | ||
amount: data["amount"] as double, | ||
feeId: data["fee_id"] as int, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import "dart:convert"; | ||
|
||
import "fee.dart"; | ||
import "payment.dart"; | ||
import "results.dart"; | ||
import "../state.dart"; | ||
|
||
class PaymentStatus { | ||
final Fee fee; | ||
final double lowerBound; | ||
final double upperBound; | ||
final Payment? payment; | ||
|
||
PaymentStatus({ | ||
required this.fee, | ||
required this.lowerBound, | ||
required this.upperBound, | ||
required this.payment, | ||
}); | ||
|
||
PaymentStatus.fromJson(dynamic data) | ||
: this( | ||
fee: Fee.fromJson(data["fee"]), | ||
lowerBound: data["lower_bound"] as double, | ||
upperBound: data["upper_bound"] as double, | ||
payment: data["payment"] == null ? null : Payment.fromJson(data["payment"]), | ||
); | ||
|
||
static Future<Result<List<PaymentStatus>?>> query({ | ||
required ApplicationState state, | ||
required int offset, | ||
required DateTime createdFrom, | ||
required DateTime createdTo, | ||
}) async { | ||
final response = await state.get( | ||
"/api/v1/residents/fee", | ||
queryParameters: { | ||
"offset": offset.toString(), | ||
"created_from": createdFrom.toUtc().toIso8601String(), | ||
"created_to": createdTo.toUtc().toIso8601String(), | ||
}, | ||
); | ||
final result = json.decode(utf8.decode(response.bodyBytes)); | ||
|
||
if (response.statusCode == 200) { | ||
final data = result["data"] as List<dynamic>; | ||
return Result(0, List<PaymentStatus>.from(data.map(PaymentStatus.fromJson))); | ||
} | ||
|
||
return Result(result["code"], null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.