Skip to content

Commit

Permalink
Allow fine-grained control over the expanded chart fields (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Jul 15, 2024
1 parent 59ce965 commit 44009a4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
16 changes: 10 additions & 6 deletions SeatsioDotNet.Test/Charts/ListChartsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
42 changes: 28 additions & 14 deletions SeatsioDotNet/Charts/Charts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,27 @@ public async Task<ChartValidationResult> ValidateDraftVersionAsync(string chartK
return AssertOk(await _restClient.ExecuteAsync<ChartValidationResult>(restRequest, cancellationToken));
}

public IAsyncEnumerable<Chart> ListAllAsync(string filter = null, string tag = null, bool? expandEvents = null, bool? withValidation = false)
public IAsyncEnumerable<Chart> 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<Page<Chart>> ListFirstPageAsync(string filter = null, string tag = null, bool? expandEvents = false, int? pageSize = null, bool? withValidation = false, CancellationToken cancellationToken = default)
public async Task<Page<Chart>> 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<Page<Chart>> ListPageAfterAsync(long id, string filter = null, string tag = null, bool? expandEvents = false, int? pageSize = null, bool? withValidation = false, CancellationToken cancellationToken = default)
public async Task<Page<Chart>> 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<Page<Chart>> ListPageBeforeAsync(long id, string filter = null, string tag = null, bool? expandEvents = false, int? pageSize = null, bool? withValidation = false, CancellationToken cancellationToken = default)
public async Task<Page<Chart>> 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<string, object> ChartListParams(string filter, string tag, bool? expandEvents, bool? withValidation = false)
private Dictionary<string, object> ChartListParams(string filter, string tag, bool expandEvents, bool expandValidation, bool expandVenueType)
{
var chartListParams = new Dictionary<string, object>();

Expand All @@ -297,17 +297,31 @@ private Dictionary<string, object> 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<string>();

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<Chart> List()
Expand Down
12 changes: 11 additions & 1 deletion SeatsioDotNet/Util/PageFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ private RestRequest BuildRequest(Dictionary<string, object> listParams, int? pag
{
foreach (var param in listParams)
{
restRequest.AddQueryParameter(param.Key, param.Value.ToString());
if (param.Value.GetType() == typeof(List<string>))
{
foreach (var v in (List<string>)param.Value)
{
restRequest.AddQueryParameter(param.Key, v);
}
}
else
{
restRequest.AddQueryParameter(param.Key, param.Value.ToString());
}
}
}

Expand Down

0 comments on commit 44009a4

Please sign in to comment.