added monthly report
parent
c9de23347a
commit
68f044de52
@ -0,0 +1,96 @@
|
|||||||
|
import 'package:dartz/dartz.dart';
|
||||||
|
import '../../core/api/api_client.dart';
|
||||||
|
import '../../core/api_consts.dart';
|
||||||
|
import '../../core/common_models/generic_api_model.dart';
|
||||||
|
import '../../core/exceptions/api_failure.dart';
|
||||||
|
import '../../services/logger_service.dart';
|
||||||
|
|
||||||
|
abstract class MonthlyReportsRepo {
|
||||||
|
Future<Either<Failure, GenericApiModel<dynamic>>> saveMonthlyReport({
|
||||||
|
String? email,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class MonthlyReportsRepoImp implements MonthlyReportsRepo {
|
||||||
|
final ApiClient apiClient;
|
||||||
|
final LoggerService loggerService;
|
||||||
|
|
||||||
|
MonthlyReportsRepoImp({
|
||||||
|
required this.loggerService,
|
||||||
|
required this.apiClient,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Either<Failure, GenericApiModel<dynamic>>> saveMonthlyReport({
|
||||||
|
String? email,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
Failure? failure;
|
||||||
|
|
||||||
|
GenericApiModel<dynamic>? reportApiResponse;
|
||||||
|
|
||||||
|
await apiClient.post(
|
||||||
|
ApiConsts.getMonthlyReports,
|
||||||
|
body: <String, dynamic>{},
|
||||||
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||||
|
failure = failureType;
|
||||||
|
},
|
||||||
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||||
|
try {
|
||||||
|
reportApiResponse = GenericApiModel<dynamic>(
|
||||||
|
messageStatus: messageStatus,
|
||||||
|
statusCode: statusCode,
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
data: response,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
failure = DataParsingFailure(e.toString());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (failure != null) return Left(failure!);
|
||||||
|
if (reportApiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||||
|
|
||||||
|
if ((reportApiResponse!.messageStatus ?? 0) != 1) {
|
||||||
|
return Right(reportApiResponse!);
|
||||||
|
}
|
||||||
|
|
||||||
|
GenericApiModel<dynamic>? emailApiResponse;
|
||||||
|
|
||||||
|
final Map<String, dynamic> emailRequest = <String, dynamic>{};
|
||||||
|
|
||||||
|
if (email != null && email.trim().isNotEmpty) {
|
||||||
|
emailRequest["Email"] = email.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
await apiClient.post(
|
||||||
|
ApiConsts.updatePatientEmail,
|
||||||
|
body: emailRequest,
|
||||||
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||||
|
failure = failureType;
|
||||||
|
},
|
||||||
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||||
|
try {
|
||||||
|
emailApiResponse = GenericApiModel<dynamic>(
|
||||||
|
messageStatus: messageStatus,
|
||||||
|
statusCode: statusCode,
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
data: response,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
failure = DataParsingFailure(e.toString());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (failure != null) return Left(failure!);
|
||||||
|
if (emailApiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||||
|
|
||||||
|
return Right(emailApiResponse!);
|
||||||
|
} catch (e) {
|
||||||
|
loggerService.logError("MonthlyReportsRepo.saveMonthlyReport error: $e");
|
||||||
|
return Left(UnknownFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
||||||
|
import 'monthly_reports_repo.dart';
|
||||||
|
class MonthlyReportsViewModel extends ChangeNotifier {
|
||||||
|
final MonthlyReportsRepo monthlyReportsRepo;
|
||||||
|
final ErrorHandlerService errorHandlerService;
|
||||||
|
|
||||||
|
bool isLoading = false;
|
||||||
|
|
||||||
|
MonthlyReportsViewModel({
|
||||||
|
required this.monthlyReportsRepo,
|
||||||
|
required this.errorHandlerService,
|
||||||
|
});
|
||||||
|
|
||||||
|
Future<bool> saveMonthlyReport({String? email}) async {
|
||||||
|
isLoading = true;
|
||||||
|
notifyListeners();
|
||||||
|
|
||||||
|
final result = await monthlyReportsRepo.saveMonthlyReport(email: email);
|
||||||
|
|
||||||
|
final success = result.fold(
|
||||||
|
(failure) {
|
||||||
|
errorHandlerService.handleError(failure: failure);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
(apiResponse) => (apiResponse.messageStatus ?? 0) == 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
isLoading = false;
|
||||||
|
notifyListeners();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hmg_patient_app_new/features/terms_conditions/terms_conditions_repo.dart';
|
import 'package:hmg_patient_app_new/features/monthly_reports/terms_conditions_repo.dart';
|
||||||
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
||||||
|
|
||||||
class TermsConditionsViewModel extends ChangeNotifier {
|
class TermsConditionsViewModel extends ChangeNotifier {
|
||||||
Loading…
Reference in New Issue