Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Guard
Browse files Browse the repository at this point in the history
Signed-off-by: Karolis Vycius <k.vycius@gmail.com>
  • Loading branch information
vycius committed Jun 13, 2020
1 parent 04ce543 commit 7cb8bef
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/api/pets_api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,30 @@ class PetsApiService {

Future<List<Pet>> getPets(
List<int> petIds, String lastUpdateDateIso8601) async {
if (petIds.isNotEmpty) {
final queryParams = {
"pet_ids": petIds.join(','),
"last_update": lastUpdateDateIso8601,
};

var petsUrl = "/v1/pets/";
if (petIds.isEmpty) {
return [];
}

List<Pet> allPets = [];
while (petsUrl != null) {
final response = allPets.isEmpty
? await dio.get(petsUrl, queryParameters: queryParams)
: await dio.get(petsUrl);
var petsUrl = "/v1/pets/";
final queryParams = {
"pet_ids": petIds.join(','),
"last_update": lastUpdateDateIso8601,
};

final pets =
response.data['results'].map<Pet>((model) => Pet.fromJson(model));
List<Pet> allPets = [];
while (petsUrl != null) {
final response = allPets.isEmpty
? await dio.get(petsUrl, queryParameters: queryParams)
: await dio.get(petsUrl);

allPets.addAll(pets);
final pets =
response.data['results'].map<Pet>((model) => Pet.fromJson(model));

petsUrl = response.data['next'];
}
allPets.addAll(pets);

return allPets;
petsUrl = response.data['next'];
}
return [];

return allPets;
}
}

0 comments on commit 7cb8bef

Please sign in to comment.