import 'package:rasadyar_chicken/data/models/response/bar_information/bar_information.dart'; import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart'; import 'package:rasadyar_chicken/presentation/pages/steward/root/logic.dart'; import 'package:rasadyar_core/core.dart'; class HomeLogic extends GetxController { StewardRootLogic rootLogic = Get.find(); RxnInt totalWeightTodayBars = RxnInt(); Rxn killHouseDistributionInfo = Rxn(); Rxn barInformation = Rxn(); RxBool isExpanded = false.obs; @override void onReady() { super.onReady(); refreshData(); } Future refreshData() async { await Future.wait([getGeneralBarsInformation(), getTodayBars(), getDistributionInformation()]); } Future getGeneralBarsInformation() async { await safeCall( call: () async => await rootLogic.chickenRepository.getGeneralBarInformation( token: rootLogic.tokenService.accessToken.value!, queryParameters: buildQueryParams(role: 'Steward'), ), onSuccess: (result) { if (result != null) { barInformation.value = result; } }, onError: (error, stackTrace) {}, ); } Future getTodayBars() async { await safeCall( call: () async => await rootLogic.chickenRepository.getGeneralBarInformation( token: rootLogic.tokenService.accessToken.value!, queryParameters: buildQueryParams( fromDate: DateTime.now(), toDate: DateTime.now(), role: 'Steward', ), ), onSuccess: (result) { if (result != null) { totalWeightTodayBars.value = result.totalBarsWeight?.toInt(); } }, onError: (error, stackTrace) {}, ); } Future getDistributionInformation() async { await safeCall( call: () async => await rootLogic.chickenRepository.getKillHouseDistributionInfo( token: rootLogic.tokenService.accessToken.value!, ), onSuccess: (result) { if (result != null) { killHouseDistributionInfo.value = result; } }, onError: (error, stackTrace) {}, ); } }