- Auth: phone login → POST /auth/phone (direct, no OTP); link phone → POST /auth/verify-phone; add email → POST /auth/link-email
- Services: replace query-param paths with dedicated role endpoints (/services/me, /services/professional/requests, /services/professional, etc.)
- Services: PATCH /services/:id → PATCH /services/:id/status
- Calendar: → GET /services/professional/calendar
- Professionals: /users/professionals → /professionals (handles {data:[...]} response)
- Professional info: /professional-info/:id → /professionals/:id; PATCH → /professionals/me
- Comments: /comments?... → /comments/user/:id and /comments/professional/:id
- Chat: /chats → /chat; start chat → POST /chat/start/:professionalId; poll GET /chat/:chatId/messages; send → POST /chat/:chatId/message
- Cities: /cities → GET /locations/countries (parse nested countries→regions→cities)
- Profesional.fromDocument: null-safe fields; convert schedules array→Schedules, specializations array→name/picture lists, payment_methods object/array
- Usuario.fromDocument: null-safe professional_state and id
- UsuarioProfesional.fromDocument: handle backend format (users nested, professional at top level)
- ScheduleEntity.parseTime: handle ISO8601 time strings from backend
- MessageEntity.fromDocument: accept sender_id (backend) or owner_id (legacy)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
110 lines
4.2 KiB
Dart
110 lines
4.2 KiB
Dart
import 'dart:typed_data';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:prosapp_web_app/models/location_preferences.dart';
|
|
import 'package:prosapp_web_app/models/payment_method_entity.dart';
|
|
import 'package:prosapp_web_app/models/profesional.dart';
|
|
import 'package:prosapp_web_app/models/schedules.dart';
|
|
import 'package:prosapp_web_app/services/api_service.dart';
|
|
import 'package:prosapp_web_app/services/notifications_service.dart';
|
|
|
|
class ProfessionalFormProvider with ChangeNotifier {
|
|
Profesional? profesional;
|
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
|
GlobalKey<FormState> profileFormKey = GlobalKey<FormState>();
|
|
final _api = ApiService.instance;
|
|
|
|
copyProfesionalWith({
|
|
String? id,
|
|
String? identification,
|
|
String? address,
|
|
String? aditionalAddress,
|
|
String? profession,
|
|
bool ratePreferences = false,
|
|
String? rate,
|
|
LocationPreferences? locationPreferences,
|
|
String? bannerPicture,
|
|
String? identificationPicture,
|
|
String? certificatePicture,
|
|
double? latitude,
|
|
double? longitude,
|
|
List<String>? specializations,
|
|
List<String>? specializationsPictures,
|
|
Schedules? schedules,
|
|
PaymentMethodEntity? paymentMethods,
|
|
}) {
|
|
profesional = Profesional(
|
|
id: id ?? profesional!.id,
|
|
identification: identification ?? profesional!.identification,
|
|
address: address ?? profesional!.address,
|
|
aditionalAddress: aditionalAddress ?? profesional!.aditionalAddress,
|
|
profession: profession ?? profesional!.profession,
|
|
ratePreferences: ratePreferences,
|
|
rate: rate ?? profesional!.rate,
|
|
locationPreferences: locationPreferences ?? profesional!.locationPreferences,
|
|
bannerPicture: bannerPicture ?? profesional!.bannerPicture,
|
|
identificationPicture: identificationPicture ?? profesional!.identificationPicture,
|
|
certificatePicture: certificatePicture ?? profesional!.certificatePicture,
|
|
latitude: latitude ?? profesional!.latitude,
|
|
longitude: longitude ?? profesional!.longitude,
|
|
specializations: specializations ?? profesional!.specializations,
|
|
specializationsPictures: specializationsPictures ?? profesional!.specializationsPictures,
|
|
schedules: schedules ?? profesional!.schedules,
|
|
paymentMethods: paymentMethods ?? profesional!.paymentMethods,
|
|
);
|
|
notifyListeners();
|
|
}
|
|
|
|
bool _validForm() => formKey.currentState!.validate();
|
|
bool _validProfileForm() => profileFormKey.currentState!.validate();
|
|
|
|
setProfesional(Profesional p) {
|
|
profesional = p;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<bool> updateProfesionalInfo(String userId) async {
|
|
if (!_validForm()) return false;
|
|
await _api.patch('/professionals/me', profesional!.toDocument());
|
|
NotificationsService.showSnackbar('Información actualizada');
|
|
return true;
|
|
}
|
|
|
|
Future<bool> updateProfesionalProfileInfo(String userId) async {
|
|
if (!_validProfileForm()) return false;
|
|
await _api.patch('/professionals/me', profesional!.toDocument());
|
|
NotificationsService.showSnackbar('Información actualizada');
|
|
return true;
|
|
}
|
|
|
|
Future<bool> updateProfesionalProfileScheduleInfo(String userId) async {
|
|
await _api.patch('/professionals/me', profesional!.toDocument());
|
|
NotificationsService.showSnackbar('Información actualizada');
|
|
return true;
|
|
}
|
|
|
|
Future<Profesional> uploadPdfIdentification(Uint8List fileBytes, String userId) async {
|
|
final url = await _api.upload(fileBytes, '${userId}_cedula.pdf');
|
|
if (url != null) copyProfesionalWith(identificationPicture: url);
|
|
notifyListeners();
|
|
return profesional!;
|
|
}
|
|
|
|
Future<Profesional> uploadPdfCertificate(Uint8List fileBytes, String userId) async {
|
|
final url = await _api.upload(fileBytes, '${userId}_certificado.pdf');
|
|
if (url != null) copyProfesionalWith(certificatePicture: url);
|
|
notifyListeners();
|
|
return profesional!;
|
|
}
|
|
|
|
Future<Profesional> uploadPdfSpecializations(List<Uint8List> filesBytes, String userId) async {
|
|
List<String> urls = [];
|
|
for (int i = 0; i < filesBytes.length; i++) {
|
|
final url = await _api.upload(filesBytes[i], '${userId}_especializacion_$i.pdf');
|
|
if (url != null) urls.add(url);
|
|
}
|
|
copyProfesionalWith(specializationsPictures: urls);
|
|
notifyListeners();
|
|
return profesional!;
|
|
}
|
|
}
|