fetchComments method
Implementation
Future<List<CommentModel>> fetchComments(String requestId) async {
final userId = await userService.getUserId();
final response = await http.get(
Uri.parse('${apiUrl}requests/$requestId/comments'),
headers: {
'api-key': apiKey,
'user-id': userId,
},
);
if (response.statusCode == 200) {
List<dynamic> body = json.decode(response.body);
List<CommentModel> items = body.map((dynamic item) => CommentModel.fromJson(item)).toList();
return items;
} else {
throw Exception('Failed to load comments');
}
}