Skip to content

Commit

Permalink
Merge pull request #937 from clement911/gift-card-search
Browse files Browse the repository at this point in the history
Gift card search
  • Loading branch information
clement911 committed Oct 11, 2023
2 parents c2a52cd + 2e75c87 commit f8f1390
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
25 changes: 25 additions & 0 deletions ShopifySharp/Filters/GiftCardSearchFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;

namespace ShopifySharp.Filters
{
Expand All @@ -16,5 +17,29 @@ public class GiftCardSearchFilter : ListFilter<GiftCard>
/// </summary>
[JsonProperty("query")]
public string Query { get; set; }

/// <summary>
/// Restricts results to those created after date (format: 2008-12-31 03:00).
/// </summary>
[JsonProperty("created_at_min")]
public DateTimeOffset? CreatedAtMin { get; set; }

/// <summary>
/// Restricts results to those created before date (format: 2008-12-31 03:00).
/// </summary>
[JsonProperty("created_at_max")]
public DateTimeOffset? CreatedAtMax { get; set; }

/// <summary>
/// Restricts results to those last updated after date (format: 2008-12-31 03:00).
/// </summary>
[JsonProperty("updated_at_min")]
public DateTimeOffset? UpdatedAtMin { get; set; }

/// <summary>
/// Restricts results to those last updated before date (format: 2008-12-31 03:00).
/// </summary>
[JsonProperty("updated_at_max")]
public DateTimeOffset? UpdatedAtMax { get; set; }
}
}
23 changes: 6 additions & 17 deletions ShopifySharp/Services/GiftCard/GiftCardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class GiftCardService : ShopifyService, IGiftCardService
public virtual async Task<ListResult<GiftCard>> ListAsync(GiftCardListFilter filter = null, CancellationToken cancellationToken = default) =>
await ListAsync(filter?.AsListFilter(), cancellationToken);

public virtual async Task<ListResult<GiftCard>> SearchAsync(ListFilter<GiftCard> filter, CancellationToken cancellationToken = default) =>
await ExecuteGetListAsync("gift_cards/search.json", "gift_cards", filter, cancellationToken);

public virtual async Task<ListResult<GiftCard>> SearchAsync(GiftCardSearchFilter filter, CancellationToken cancellationToken = default) =>
await SearchAsync(filter.AsListFilter(), cancellationToken);

/// <inheritdoc />
public virtual async Task<GiftCard> GetAsync(long giftCardId, CancellationToken cancellationToken = default) =>
await ExecuteGetAsync<GiftCard>($"gift_cards/{giftCardId}.json", "gift_card", cancellationToken: cancellationToken);
Expand Down Expand Up @@ -71,22 +77,5 @@ public virtual async Task<GiftCard> DisableAsync(long giftCardId, CancellationTo
var response = await ExecuteRequestAsync<GiftCard>(req, HttpMethod.Post, cancellationToken, rootElement: "gift_card");
return response.Result;
}

/// <inheritdoc />
public virtual async Task<ListResult<GiftCard>> SearchAsync(GiftCardSearchFilter filter, CancellationToken cancellationToken = default)
{
if (filter == null)
{
throw new ArgumentNullException(nameof(filter));
}

var req = PrepareRequest("gift_cards/search.json");

req.QueryParams.AddRange(filter.ToQueryParameters());

var response = await ExecuteRequestAsync<List<GiftCard>>(req, HttpMethod.Get, cancellationToken, rootElement: "gift_cards");

return ParseLinkHeaderToListResult(response);
}
}
}

0 comments on commit f8f1390

Please sign in to comment.