Skip to content

Commit

Permalink
fix: fix coop image url, fix due date on product upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Jan 27, 2024
1 parent caac9a1 commit edefcb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions GrocyScanner.Core/GrocyClient/GrocyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ public async Task AddProductToStock(int productId, int amount, DateOnly? bestBef
throw new ArgumentException("Amount cannot be negative", nameof(amount));
}

// this is Grocy's way of "no due date". Inserting null sadly displays "today" as the due date
DateOnly bestBeforeOrDefault = bestBefore ?? new DateOnly(2999, 12, 31);

HttpClient httpClient = _httpClientFactory.CreateClient();
HttpRequestMessage httpRequestMessage = new(HttpMethod.Post,
$"{_grocyConfiguration.Value.BaseUrl}/api/stock/products/{productId}/add");
httpRequestMessage.Headers.Add("GROCY-API-KEY", _grocyConfiguration.Value.ApiKey);
httpRequestMessage.Headers.Add("accept", "application/json");
string json =
$@"{{""amount"": {amount},""best_before_date"":""{bestBefore:yyyy-MM-dd}"",""price"":""{price:N}""}}";
string json =
$@"{{""amount"": {amount},""best_before_date"":""{bestBeforeOrDefault:yyyy-MM-dd}"",""price"":""{price:N}""}}";
httpRequestMessage.Content = new StringContent(json);
httpRequestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
await httpClient.SendAsync(httpRequestMessage);
Expand Down
3 changes: 2 additions & 1 deletion GrocyScanner.Core/Providers/CoopProductProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ public CoopProductProvider(IHttpClientFactory httpClientFactory, ILogger<CoopPro

private static string GetBestQualityImage(CoopProductImage coopProductImage)
{
return coopProductImage.Srcset
string uri = coopProductImage.Srcset
.OrderByDescending(sourceSetPair =>
int.Parse(sourceSetPair
.Last()
.Trim('w')))
.First()
.First();
return $"https:{uri}";
}

public string Name => "Coop";
Expand Down

0 comments on commit edefcb3

Please sign in to comment.