first commit
This commit is contained in:
45
lib/controllers/rewards_controller.dart
Normal file
45
lib/controllers/rewards_controller.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:miler/data/miler_api.dart';
|
||||
|
||||
/// The rider's reward-points balance.
|
||||
///
|
||||
/// ── Two things this used to do and no longer does ──
|
||||
///
|
||||
/// It called a second, legacy backend (`jupiter.doormile.app/.../
|
||||
/// getuserbonussummary`) when the new-API flag was off, and it filled an empty
|
||||
/// balance with seeded demo points in debug builds. Both are gone: there is one
|
||||
/// backend now, and a points balance is a number about somebody's pay — the
|
||||
/// only honest answer to "the server said zero" is zero.
|
||||
///
|
||||
/// ── Why the number is expected to be zero ──
|
||||
///
|
||||
/// `bonuspoints` is not written by anything server-side yet. `total_bonus` on
|
||||
/// the earnings response is therefore always 0, and that is the backend's
|
||||
/// answer rather than a bug here. See [MilerApi.missingFromBackend].
|
||||
class RewardsController extends GetxController {
|
||||
final RxInt totalPoints = 0.obs;
|
||||
final RxBool isLoading = true.obs;
|
||||
final RxString error = ''.obs;
|
||||
|
||||
Future<void> fetchBonusSummary(int userId) async {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
// No dedicated bonus-summary endpoint exists; the figure rides on
|
||||
// earnings.
|
||||
final res = await MilerApi.earnings(period: 'monthly');
|
||||
if (res.ok) {
|
||||
totalPoints.value =
|
||||
int.tryParse('${res.map['total_bonus'] ?? 0}') ?? 0;
|
||||
} else {
|
||||
error.value = res.message.isEmpty
|
||||
? "Couldn't load your points"
|
||||
: res.message;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = "Couldn't load your points";
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user