Files
food-ai/client/lib/features/profile/profile_service.dart
dbastrikin c9ddb708b1 feat: replace age integer with date_of_birth across backend and client
Store date_of_birth (DATE) instead of a static age integer so that age
is always computed dynamically from the stored date of birth.

- Migration 011: adds date_of_birth, backfills from age, drops age
- AgeFromDOB helper computes current age from YYYY-MM-DD string
- User model, repository SQL, and service validation updated
- Flutter: User.age becomes a computed getter; profile edit screen
  uses a date picker bounded to [today-120y, today-10y]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 23:37:58 +02:00

60 lines
1.6 KiB
Dart

import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/api/api_client.dart';
import '../../core/auth/auth_provider.dart';
import '../../shared/models/user.dart';
final profileServiceProvider = Provider<ProfileService>((ref) {
return ProfileService(ref.read(apiClientProvider));
});
class UpdateProfileRequest {
final String? name;
final int? heightCm;
final double? weightKg;
final String? dateOfBirth;
final String? gender;
final String? activity;
final String? goal;
final String? language;
const UpdateProfileRequest({
this.name,
this.heightCm,
this.weightKg,
this.dateOfBirth,
this.gender,
this.activity,
this.goal,
this.language,
});
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
if (name != null) map['name'] = name;
if (heightCm != null) map['height_cm'] = heightCm;
if (weightKg != null) map['weight_kg'] = weightKg;
if (dateOfBirth != null) map['date_of_birth'] = dateOfBirth;
if (gender != null) map['gender'] = gender;
if (activity != null) map['activity'] = activity;
if (goal != null) map['goal'] = goal;
if (language != null) map['preferences'] = {'language': language};
return map;
}
}
class ProfileService {
final ApiClient _client;
ProfileService(this._client);
Future<User> getProfile() async {
final json = await _client.get('/profile');
return User.fromJson(json);
}
Future<User> updateProfile(UpdateProfileRequest req) async {
final json = await _client.put('/profile', data: req.toJson());
return User.fromJson(json);
}
}