-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed9dcec
commit 7ca0c6e
Showing
5 changed files
with
649 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,6 @@ app.*.map.json | |
# VSCode | ||
.vscode/ | ||
|
||
|
||
|
||
# Xcode | ||
/ios/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class ProgressData { | ||
final double currentWeight; | ||
final double totalCalories; | ||
final int month; | ||
|
||
ProgressData({ | ||
required this.currentWeight, | ||
required this.totalCalories, | ||
required this.month, | ||
}); | ||
|
||
factory ProgressData.fromJson(Map<String, dynamic> json) { | ||
return ProgressData( | ||
currentWeight: _parseDouble(json['currentWeight']), | ||
totalCalories: _parseDouble(json['totalCalories']), | ||
month: json['month'] as int, | ||
); | ||
} | ||
|
||
static double _parseDouble(dynamic value) { | ||
if (value == null) return 0.0; | ||
if (value is double) return value; | ||
if (value is int) return value.toDouble(); | ||
if (value is String) return double.tryParse(value) ?? 0.0; | ||
return 0.0; | ||
} | ||
} | ||
|
||
class ProgressResponse { | ||
final int statusCode; | ||
final String averageCurrentWeight; | ||
final List<ProgressData> data; | ||
|
||
ProgressResponse({ | ||
required this.statusCode, | ||
required this.averageCurrentWeight, | ||
required this.data, | ||
}); | ||
|
||
factory ProgressResponse.fromJson(Map<String, dynamic> json) { | ||
return ProgressResponse( | ||
statusCode: json['statusCode'] as int, | ||
averageCurrentWeight: json['averageCurrentWeight'] as String, | ||
data: (json['data'] as List) | ||
.map((item) => ProgressData.fromJson(item as Map<String, dynamic>)) | ||
.toList(), | ||
); | ||
} | ||
|
||
double get averageWeight => double.tryParse(averageCurrentWeight) ?? 0.0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'dart:developer'; | ||
import 'package:workout_ai/services/api_service.dart'; | ||
import 'package:workout_ai/models/progress_data.dart'; | ||
|
||
class ProgressService { | ||
final APIService _api = APIService(); | ||
|
||
Future<ProgressResponse> getProgress() async { | ||
try { | ||
final response = await _api.get('progress'); | ||
log('Progress response: $response'); | ||
|
||
if (response['statusCode'] != 200) { | ||
throw Exception(response['error'] ?? | ||
response['message'] ?? | ||
'Failed to fetch progress data'); | ||
} | ||
|
||
return ProgressResponse.fromJson(response); | ||
} catch (e) { | ||
log('Error in getProgress: $e'); | ||
rethrow; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.