From 44009a4da802b0a904d208b47d9091f5e1f24121 Mon Sep 17 00:00:00 2001 From: mroloux Date: Mon, 15 Jul 2024 11:54:43 +0200 Subject: [PATCH] Allow fine-grained control over the expanded chart fields (#127) --- SeatsioDotNet.Test/Charts/ListChartsTest.cs | 16 +++++--- SeatsioDotNet/Charts/Charts.cs | 42 ++++++++++++++------- SeatsioDotNet/Util/PageFetcher.cs | 12 +++++- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/SeatsioDotNet.Test/Charts/ListChartsTest.cs b/SeatsioDotNet.Test/Charts/ListChartsTest.cs index 71ce78c..a40d663 100644 --- a/SeatsioDotNet.Test/Charts/ListChartsTest.cs +++ b/SeatsioDotNet.Test/Charts/ListChartsTest.cs @@ -64,24 +64,28 @@ public async Task Tag() } [Fact] - public async Task Expand() + public async Task ExpandAll() { var chart = await Client.Charts.CreateAsync(); var event1 = await Client.Events.CreateAsync(chart.Key); var event2 = await Client.Events.CreateAsync(chart.Key); - var charts = await Client.Charts.ListAllAsync(expandEvents: true).ToListAsync(); + var charts = await Client.Charts.ListAllAsync(expandEvents: true, expandValidation: true, expandVenueType: true).ToListAsync(); Assert.Equal(new[] {event2.Id, event1.Id}, charts.First().Events.Select(c => c.Id)); + Assert.Equal("MIXED", charts.First().VenueType); + Assert.NotNull(charts.First().Validation); } [Fact] - public async Task Validation() + public async Task ExpandNone() { - CreateTestChartWithErrors(); + var chart = await Client.Charts.CreateAsync(); - var chart = await Client.Charts.ListAllAsync(withValidation: true).FirstAsync(); + var charts = await Client.Charts.ListAllAsync(expandEvents: true).ToListAsync(); - Assert.NotNull(chart.Validation); + Assert.Empty(charts.First().Events); + Assert.Null(charts.First().Validation); + Assert.Null(charts.First().VenueType); } } \ No newline at end of file diff --git a/SeatsioDotNet/Charts/Charts.cs b/SeatsioDotNet/Charts/Charts.cs index 7471e7b..d2541b3 100644 --- a/SeatsioDotNet/Charts/Charts.cs +++ b/SeatsioDotNet/Charts/Charts.cs @@ -263,27 +263,27 @@ public async Task ValidateDraftVersionAsync(string chartK return AssertOk(await _restClient.ExecuteAsync(restRequest, cancellationToken)); } - public IAsyncEnumerable ListAllAsync(string filter = null, string tag = null, bool? expandEvents = null, bool? withValidation = false) + public IAsyncEnumerable ListAllAsync(string filter = null, string tag = null, bool expandEvents = false, bool expandValidation = false, bool expandVenueType = false) { - return List().AllAsync(ChartListParams(filter, tag, expandEvents, withValidation)); + return List().AllAsync(ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType)); } - public async Task> ListFirstPageAsync(string filter = null, string tag = null, bool? expandEvents = false, int? pageSize = null, bool? withValidation = false, CancellationToken cancellationToken = default) + public async Task> ListFirstPageAsync(string filter = null, string tag = null, bool expandEvents = false, int? pageSize = null, bool expandValidation = false, bool expandVenueType = false, CancellationToken cancellationToken = default) { - return await List().FirstPageAsync(ChartListParams(filter, tag, expandEvents, withValidation), pageSize, cancellationToken); + return await List().FirstPageAsync(ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType), pageSize, cancellationToken); } - public async Task> ListPageAfterAsync(long id, string filter = null, string tag = null, bool? expandEvents = false, int? pageSize = null, bool? withValidation = false, CancellationToken cancellationToken = default) + public async Task> ListPageAfterAsync(long id, string filter = null, string tag = null, bool expandEvents = false, int? pageSize = null, bool expandValidation = false, bool expandVenueType = false, CancellationToken cancellationToken = default) { - return await List().PageAfterAsync(id, ChartListParams(filter, tag, expandEvents, withValidation), pageSize, cancellationToken); + return await List().PageAfterAsync(id, ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType), pageSize, cancellationToken); } - public async Task> ListPageBeforeAsync(long id, string filter = null, string tag = null, bool? expandEvents = false, int? pageSize = null, bool? withValidation = false, CancellationToken cancellationToken = default) + public async Task> ListPageBeforeAsync(long id, string filter = null, string tag = null, bool expandEvents = false, int? pageSize = null, bool expandValidation = false, bool expandVenueType = false, CancellationToken cancellationToken = default) { - return await List().PageBeforeAsync(id, ChartListParams(filter, tag, expandEvents, withValidation), pageSize, cancellationToken); + return await List().PageBeforeAsync(id, ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType), pageSize, cancellationToken); } - private Dictionary ChartListParams(string filter, string tag, bool? expandEvents, bool? withValidation = false) + private Dictionary ChartListParams(string filter, string tag, bool expandEvents, bool expandValidation, bool expandVenueType) { var chartListParams = new Dictionary(); @@ -297,17 +297,31 @@ private Dictionary ChartListParams(string filter, string tag, bo chartListParams.Add("tag", tag); } - if (expandEvents != null && expandEvents.Value) + chartListParams.Add("expand", ChartListExpandParams(expandEvents, expandValidation, expandVenueType)); + + return chartListParams; + } + + private object ChartListExpandParams(bool expandEvents, bool expandValidation, bool expandVenueType) + { + var result = new List(); + + if (expandEvents) { - chartListParams.Add("expand", "events"); + result.Add("events"); } - if (withValidation == true) + if (expandValidation) { - chartListParams.Add("validation", true); + result.Add("validation"); } - return chartListParams; + if (expandVenueType) + { + result.Add("venueType"); + } + + return result; } private ParametrizedLister List() diff --git a/SeatsioDotNet/Util/PageFetcher.cs b/SeatsioDotNet/Util/PageFetcher.cs index 29f31dd..43d06c9 100644 --- a/SeatsioDotNet/Util/PageFetcher.cs +++ b/SeatsioDotNet/Util/PageFetcher.cs @@ -65,7 +65,17 @@ private RestRequest BuildRequest(Dictionary listParams, int? pag { foreach (var param in listParams) { - restRequest.AddQueryParameter(param.Key, param.Value.ToString()); + if (param.Value.GetType() == typeof(List)) + { + foreach (var v in (List)param.Value) + { + restRequest.AddQueryParameter(param.Key, v); + } + } + else + { + restRequest.AddQueryParameter(param.Key, param.Value.ToString()); + } } }