Skip to content

Commit

Permalink
Complete price updater
Browse files Browse the repository at this point in the history
  • Loading branch information
withinfocus committed Mar 10, 2024
1 parent 12f5540 commit e927c1f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,25 @@ async Task UpdateCollectionPricesAsync(int collectionId)
return;
}

// TODO
foreach (var label in collection.Labels)
{
if (label.Bottles == null || !label.Bottles.Any())
{
continue;
}

for(var bottle in label.Bottles)
foreach (var bottle in label.Bottles)
{
if (!bottle.PurchasePrice.HasValue)
if (!bottle.PurchasePrice.HasValue && label.PriceAverageConverted.HasValue)
{
bottle.PurchasePrice = label.PriceAverageUsd;
using HttpResponseMessage bottleUpdateResponse = await httpClient.PatchAsJsonAsync(
$"https://api.invintorywines.com/v2/collections/{collectionId}/bottles",
new
{
bottle_ids = new[] { bottle.Id },
purchase_price = label.PriceAverageConverted
});
bottleUpdateResponse.EnsureSuccessStatusCode();
}
}
}
Expand Down

0 comments on commit e927c1f

Please sign in to comment.