fetchItems method

Future<Map<String, List<FeatureModel>>> fetchItems()

Implementation

Future<Map<String, List<FeatureModel>>> fetchItems() async {
  final userId = await userService.getUserId();

  final response = await http.get(
    Uri.parse('${apiUrl}requests'),
    headers: {
      'api-key': apiKey,
      'user-id': userId,
    },
  );

  if (response.statusCode == 200) {
    List<dynamic> body = json.decode(response.body);
    List<FeatureModel> items = body.map((dynamic item) => FeatureModel.fromJson(item)).toList();
    return _groupItemsByStatus(items);
  } else {
    throw Exception('Failed to load features');
  }
}