- 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>
51 lines
1.6 KiB
Dart
51 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:prosapp_web_app/models/city.dart';
|
|
import 'package:prosapp_web_app/services/api_service.dart';
|
|
|
|
class CitiesProvider extends ChangeNotifier {
|
|
List<City> cities = [];
|
|
bool isLoading = true;
|
|
final _api = ApiService.instance;
|
|
|
|
CitiesProvider() {
|
|
getCities();
|
|
}
|
|
|
|
getCoordsOfCity(String cityName) {
|
|
for (var city in cities) {
|
|
if (city.cityName == cityName) return city.coordsOfCity;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
getCities() async {
|
|
try {
|
|
// GET /locations/countries returns nested {regions: [{cities: [...]}]}
|
|
final countries = await _api.get('/locations/countries') as List;
|
|
final result = <City>[];
|
|
for (final country in countries) {
|
|
final countryName = country['name'] as String? ?? 'Colombia';
|
|
for (final region in (country['regions'] as List? ?? [])) {
|
|
final regionName = region['name'] as String? ?? '';
|
|
for (final c in (region['cities'] as List? ?? [])) {
|
|
final lat = (c['latitude'] as num?)?.toDouble() ?? 0.0;
|
|
final lng = (c['longitude'] as num?)?.toDouble() ?? 0.0;
|
|
result.add(City(
|
|
cityName: c['name'] as String,
|
|
coordsOfCity: lat != 0.0 ? '$lat,$lng' : '',
|
|
stateOfCity: regionName,
|
|
countryOfCity: countryName,
|
|
));
|
|
}
|
|
}
|
|
}
|
|
cities = result..sort((a, b) => a.cityName.compareTo(b.cityName));
|
|
} catch (e) {
|
|
print('Error obteniendo ciudades: $e');
|
|
} finally {
|
|
isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
}
|