import 'package:rasadyar_auth/data/utils/safe_call.dart'; import 'package:rasadyar_chicken/chicken.dart'; import 'package:rasadyar_chicken/data/models/response/bar_information/bar_information.dart'; import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart'; import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart'; import 'package:rasadyar_chicken/presentation/utils/utils.dart'; import 'package:rasadyar_core/core.dart'; class HomeLogic extends GetxController { RootLogic root = Get.find(); RxnInt totalWeightTodayBars = RxnInt(); Rxn inventoryModel = Rxn(); Rxn killHouseDistributionInfo = Rxn(); @override void onInit() { super.onInit(); getTodayBars(); getInventory(); getDistributionInformation(); } Future getTodayBars() async { await safeCall( call: () async => await root.chickenRepository.getGeneralBarInformation( token: root.tokenService.accessToken.value!, queryParameters: buildQueryParams(fromDate: DateTime.now(), toDate: DateTime.now()), ), onSuccess: (result) { if (result != null) { totalWeightTodayBars.value = result.totalBarsWeight?.toInt(); } }, onError: (error, stackTrace) { switch (error.response?.statusCode) { case 401: errorHandler(error); break; case 403: errorHandler(error); break; default: errorHandler(error); } }, ); } Future getInventory() async { await safeCall?>( call: () async => await root.chickenRepository.getInventory(token: root.tokenService.accessToken.value!), onSuccess: (result) { if (result != null) { inventoryModel.value = result.first; } }, onError: (error, stackTrace) { switch (error.response?.statusCode) { case 401: errorHandler(error); break; case 403: errorHandler(error); break; default: errorHandler(error); } }, ); } Future getDistributionInformation() async { await safeCall( call: () async => await root.chickenRepository.getIKillHouseDistributionInfo(token: root.tokenService.accessToken.value!), onSuccess: (result) { if (result != null) { iLog(result); killHouseDistributionInfo.value = result; iLog(killHouseDistributionInfo.value); } }, onError: (error, stackTrace) {}, ); } void errorHandler(DioException error) { handleGeneric(error, () { root.tokenService.deleteTokens(); }); } @override void onReady() { super.onReady(); } @override void onClose() { super.onClose(); } }