From e927c1fd5568f3e974eb1c19b7cfdadce835c267 Mon Sep 17 00:00:00 2001 From: Matt Bishop Date: Sun, 10 Mar 2024 18:18:50 -0400 Subject: [PATCH] Complete price updater --- Program.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index e7ef004..411c97d 100644 --- a/Program.cs +++ b/Program.cs @@ -111,7 +111,6 @@ async Task UpdateCollectionPricesAsync(int collectionId) return; } - // TODO foreach (var label in collection.Labels) { if (label.Bottles == null || !label.Bottles.Any()) @@ -119,11 +118,18 @@ async Task UpdateCollectionPricesAsync(int collectionId) 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(); } } }