refactor doctor replay service
parent
78694a4c07
commit
0c7c4d7dae
@ -0,0 +1,27 @@
|
||||
import 'package:doctor_app_flutter/config/config.dart';
|
||||
import 'package:doctor_app_flutter/core/model/hospitals_model.dart';
|
||||
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
|
||||
import 'package:doctor_app_flutter/models/doctor/list_gt_my_patients_question_model.dart';
|
||||
import 'package:doctor_app_flutter/models/doctor/request_doctor_reply.dart';
|
||||
|
||||
class DoctorReplyService extends BaseService {
|
||||
|
||||
List<ListGtMyPatientsQuestions> get listDoctorWorkingHoursTable => _listDoctorWorkingHoursTable;
|
||||
List<ListGtMyPatientsQuestions> _listDoctorWorkingHoursTable = [];
|
||||
|
||||
|
||||
RequestDoctorReply _requestDoctorReply = RequestDoctorReply();
|
||||
Future getDoctorReply() async {
|
||||
await baseAppClient.post(GT_MY_PATIENT_QUESTION,
|
||||
onSuccess: (dynamic response, int statusCode) {
|
||||
_listDoctorWorkingHoursTable.clear();
|
||||
response['List_GtMyPatientsQuestions'].forEach((v) {
|
||||
_listDoctorWorkingHoursTable
|
||||
.add(ListGtMyPatientsQuestions.fromJson(v));
|
||||
});
|
||||
}, onFailure: (String error, int statusCode) {
|
||||
hasError = true;
|
||||
super.error = error;
|
||||
}, body: _requestDoctorReply.toJson(),);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
|
||||
import 'package:doctor_app_flutter/core/model/hospitals_model.dart';
|
||||
import 'package:doctor_app_flutter/core/service/doctor_reply_service.dart';
|
||||
import 'package:doctor_app_flutter/core/service/hospital/hospitals_service.dart';
|
||||
import 'package:doctor_app_flutter/models/doctor/list_gt_my_patients_question_model.dart';
|
||||
|
||||
import '../../locator.dart';
|
||||
import 'base_view_model.dart';
|
||||
|
||||
class DoctorReplayViewModel extends BaseViewModel {
|
||||
DoctorReplyService _doctorReplyService = locator<DoctorReplyService>();
|
||||
|
||||
List<ListGtMyPatientsQuestions> get listDoctorWorkingHoursTable => _doctorReplyService.listDoctorWorkingHoursTable;
|
||||
|
||||
Future getDoctorReply() async {
|
||||
setState(ViewState.Busy);
|
||||
await _doctorReplyService.getDoctorReply();
|
||||
if (_doctorReplyService.hasError) {
|
||||
error = _doctorReplyService.error;
|
||||
setState(ViewState.Error);
|
||||
} else
|
||||
setState(ViewState.Idle);
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
import 'package:doctor_app_flutter/client/base_app_client.dart';
|
||||
import 'package:doctor_app_flutter/config/config.dart';
|
||||
import 'package:doctor_app_flutter/models/doctor/request_doctor_reply.dart';
|
||||
import 'package:doctor_app_flutter/models/doctor/list_gt_my_patients_question_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class DoctorReplyProvider with ChangeNotifier {
|
||||
List<ListGtMyPatientsQuestions> listDoctorWorkingHoursTable = [];
|
||||
|
||||
bool isLoading = true;
|
||||
bool isError = false;
|
||||
String error = '';
|
||||
RequestDoctorReply _requestDoctorReply = RequestDoctorReply();
|
||||
BaseAppClient baseAppClient = BaseAppClient();
|
||||
DoctorReplyProvider() {
|
||||
getDoctorReply();
|
||||
}
|
||||
|
||||
getDoctorReply() async {
|
||||
try {
|
||||
await baseAppClient.post(GT_MY_PATIENT_QUESTION,
|
||||
body: _requestDoctorReply.toJson(),
|
||||
onSuccess: (dynamic response, int statusCode) {
|
||||
response['List_GtMyPatientsQuestions'].forEach((v) {
|
||||
listDoctorWorkingHoursTable
|
||||
.add(ListGtMyPatientsQuestions.fromJson(v));
|
||||
isError = false;
|
||||
isLoading = false;
|
||||
});
|
||||
}, onFailure: (String error, int statusCode) {
|
||||
isError = true;
|
||||
isLoading = false;
|
||||
this.error = error;
|
||||
});
|
||||
|
||||
notifyListeners();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue