first commit
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import 'package:mobx/mobx.dart';
|
||||
import '../../../dashboard/data/models/doctor_info_model.dart';
|
||||
import '../../data/services/config_service.dart';
|
||||
|
||||
part 'config_store.g.dart';
|
||||
|
||||
// ignore: library_private_types_in_public_api
|
||||
class ConfigStore = _ConfigStoreBase with _$ConfigStore;
|
||||
|
||||
abstract class _ConfigStoreBase with Store {
|
||||
final ConfigService service;
|
||||
|
||||
_ConfigStoreBase({ConfigService? configService})
|
||||
: service = configService ?? ConfigService();
|
||||
|
||||
@observable
|
||||
int? id;
|
||||
|
||||
@observable
|
||||
bool isLoading = false;
|
||||
|
||||
@observable
|
||||
bool isSaving = false;
|
||||
|
||||
@observable
|
||||
String? errorMessage;
|
||||
|
||||
@observable
|
||||
String? successMessage;
|
||||
|
||||
@observable
|
||||
String nombreDoctor = '';
|
||||
|
||||
@observable
|
||||
String especialidad = '';
|
||||
|
||||
@observable
|
||||
String descripEspecialidad = '';
|
||||
|
||||
@observable
|
||||
String descripGeneral = '';
|
||||
|
||||
@computed
|
||||
bool get isValid => nombreDoctor.trim().isNotEmpty && especialidad.trim().isNotEmpty;
|
||||
|
||||
@action
|
||||
void initFromModel(DoctorInfoModel model) {
|
||||
id = model.id;
|
||||
nombreDoctor = model.nombreDoctor;
|
||||
especialidad = model.especialidad;
|
||||
descripEspecialidad = model.descripEspecialidad;
|
||||
descripGeneral = model.descripGeneral;
|
||||
errorMessage = null;
|
||||
successMessage = null;
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> loadConfig() async {
|
||||
isLoading = true;
|
||||
errorMessage = null;
|
||||
try {
|
||||
final config = await service.getConfig();
|
||||
initFromModel(config);
|
||||
} catch (e) {
|
||||
errorMessage = e.toString();
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<DoctorInfoModel?> saveConfig() async {
|
||||
if (!isValid) {
|
||||
errorMessage = 'El nombre del doctor y la especialidad son obligatorios.';
|
||||
return null;
|
||||
}
|
||||
|
||||
isSaving = true;
|
||||
errorMessage = null;
|
||||
successMessage = null;
|
||||
|
||||
try {
|
||||
final modelToSave = DoctorInfoModel(
|
||||
id: id,
|
||||
nombreDoctor: nombreDoctor.trim(),
|
||||
especialidad: especialidad.trim(),
|
||||
descripEspecialidad: descripEspecialidad.trim(),
|
||||
descripGeneral: descripGeneral.trim(),
|
||||
);
|
||||
|
||||
final updated = await service.updateConfig(modelToSave);
|
||||
initFromModel(updated);
|
||||
successMessage = 'Configuración guardada exitosamente';
|
||||
return updated;
|
||||
} catch (e) {
|
||||
errorMessage = e.toString().replaceAll('Exception: ', '');
|
||||
return null;
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'config_store.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// StoreGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers
|
||||
|
||||
mixin _$ConfigStore on _ConfigStoreBase, Store {
|
||||
Computed<bool>? _$isValidComputed;
|
||||
|
||||
@override
|
||||
bool get isValid => (_$isValidComputed ??= Computed<bool>(
|
||||
() => super.isValid,
|
||||
name: '_ConfigStoreBase.isValid',
|
||||
)).value;
|
||||
|
||||
late final _$idAtom = Atom(name: '_ConfigStoreBase.id', context: context);
|
||||
|
||||
@override
|
||||
int? get id {
|
||||
_$idAtom.reportRead();
|
||||
return super.id;
|
||||
}
|
||||
|
||||
@override
|
||||
set id(int? value) {
|
||||
_$idAtom.reportWrite(value, super.id, () {
|
||||
super.id = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$isLoadingAtom = Atom(
|
||||
name: '_ConfigStoreBase.isLoading',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get isLoading {
|
||||
_$isLoadingAtom.reportRead();
|
||||
return super.isLoading;
|
||||
}
|
||||
|
||||
@override
|
||||
set isLoading(bool value) {
|
||||
_$isLoadingAtom.reportWrite(value, super.isLoading, () {
|
||||
super.isLoading = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$isSavingAtom = Atom(
|
||||
name: '_ConfigStoreBase.isSaving',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get isSaving {
|
||||
_$isSavingAtom.reportRead();
|
||||
return super.isSaving;
|
||||
}
|
||||
|
||||
@override
|
||||
set isSaving(bool value) {
|
||||
_$isSavingAtom.reportWrite(value, super.isSaving, () {
|
||||
super.isSaving = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$errorMessageAtom = Atom(
|
||||
name: '_ConfigStoreBase.errorMessage',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String? get errorMessage {
|
||||
_$errorMessageAtom.reportRead();
|
||||
return super.errorMessage;
|
||||
}
|
||||
|
||||
@override
|
||||
set errorMessage(String? value) {
|
||||
_$errorMessageAtom.reportWrite(value, super.errorMessage, () {
|
||||
super.errorMessage = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$successMessageAtom = Atom(
|
||||
name: '_ConfigStoreBase.successMessage',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String? get successMessage {
|
||||
_$successMessageAtom.reportRead();
|
||||
return super.successMessage;
|
||||
}
|
||||
|
||||
@override
|
||||
set successMessage(String? value) {
|
||||
_$successMessageAtom.reportWrite(value, super.successMessage, () {
|
||||
super.successMessage = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$nombreDoctorAtom = Atom(
|
||||
name: '_ConfigStoreBase.nombreDoctor',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String get nombreDoctor {
|
||||
_$nombreDoctorAtom.reportRead();
|
||||
return super.nombreDoctor;
|
||||
}
|
||||
|
||||
@override
|
||||
set nombreDoctor(String value) {
|
||||
_$nombreDoctorAtom.reportWrite(value, super.nombreDoctor, () {
|
||||
super.nombreDoctor = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$especialidadAtom = Atom(
|
||||
name: '_ConfigStoreBase.especialidad',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String get especialidad {
|
||||
_$especialidadAtom.reportRead();
|
||||
return super.especialidad;
|
||||
}
|
||||
|
||||
@override
|
||||
set especialidad(String value) {
|
||||
_$especialidadAtom.reportWrite(value, super.especialidad, () {
|
||||
super.especialidad = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$descripEspecialidadAtom = Atom(
|
||||
name: '_ConfigStoreBase.descripEspecialidad',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String get descripEspecialidad {
|
||||
_$descripEspecialidadAtom.reportRead();
|
||||
return super.descripEspecialidad;
|
||||
}
|
||||
|
||||
@override
|
||||
set descripEspecialidad(String value) {
|
||||
_$descripEspecialidadAtom.reportWrite(value, super.descripEspecialidad, () {
|
||||
super.descripEspecialidad = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$descripGeneralAtom = Atom(
|
||||
name: '_ConfigStoreBase.descripGeneral',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String get descripGeneral {
|
||||
_$descripGeneralAtom.reportRead();
|
||||
return super.descripGeneral;
|
||||
}
|
||||
|
||||
@override
|
||||
set descripGeneral(String value) {
|
||||
_$descripGeneralAtom.reportWrite(value, super.descripGeneral, () {
|
||||
super.descripGeneral = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$loadConfigAsyncAction = AsyncAction(
|
||||
'_ConfigStoreBase.loadConfig',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> loadConfig() {
|
||||
return _$loadConfigAsyncAction.run(() => super.loadConfig());
|
||||
}
|
||||
|
||||
late final _$saveConfigAsyncAction = AsyncAction(
|
||||
'_ConfigStoreBase.saveConfig',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<DoctorInfoModel?> saveConfig() {
|
||||
return _$saveConfigAsyncAction.run(() => super.saveConfig());
|
||||
}
|
||||
|
||||
late final _$_ConfigStoreBaseActionController = ActionController(
|
||||
name: '_ConfigStoreBase',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
void initFromModel(DoctorInfoModel model) {
|
||||
final _$actionInfo = _$_ConfigStoreBaseActionController.startAction(
|
||||
name: '_ConfigStoreBase.initFromModel',
|
||||
);
|
||||
try {
|
||||
return super.initFromModel(model);
|
||||
} finally {
|
||||
_$_ConfigStoreBaseActionController.endAction(_$actionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
id: ${id},
|
||||
isLoading: ${isLoading},
|
||||
isSaving: ${isSaving},
|
||||
errorMessage: ${errorMessage},
|
||||
successMessage: ${successMessage},
|
||||
nombreDoctor: ${nombreDoctor},
|
||||
especialidad: ${especialidad},
|
||||
descripEspecialidad: ${descripEspecialidad},
|
||||
descripGeneral: ${descripGeneral},
|
||||
isValid: ${isValid}
|
||||
''';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user