Skip to content

Commit

Permalink
Zones for charts can be expanded (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Jul 15, 2024
1 parent 44009a4 commit ea67df1
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 41 deletions.
4 changes: 2 additions & 2 deletions SeatsioDotNet.Test/Charts/CopyChartFromWorkspaceToTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CopyChartFromWorkspaceToTest : SeatsioClientTest
[Fact]
public async Task Test()
{
var chart = await Client.Charts.CreateAsync("my chart", "BOOTHS");
var chart = await Client.Charts.CreateAsync("my chart", "SIMPLE");
var toWorkspace = await Client.Workspaces.CreateAsync("my ws");

var copiedChart = await Client.Charts.CopyToWorkspaceAsync(chart.Key, Workspace.Key, toWorkspace.Key);
Expand All @@ -18,6 +18,6 @@ public async Task Test()
var retrievedChart = await workspaceClient.Charts.RetrieveAsync(copiedChart.Key);
Assert.Equal("my chart", retrievedChart.Name);
var drawing = await workspaceClient.Charts.RetrievePublishedVersionAsync(copiedChart.Key);
Assert.Equal("BOOTHS", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
}
}
4 changes: 2 additions & 2 deletions SeatsioDotNet.Test/Charts/CopyChartTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class CopyChartTest : SeatsioClientTest
[Fact]
public async Task Test()
{
var chart = await Client.Charts.CreateAsync("my chart", "BOOTHS");
var chart = await Client.Charts.CreateAsync("my chart", "SIMPLE");

var copiedChart = await Client.Charts.CopyAsync(chart.Key);

Assert.Equal("my chart (copy)", copiedChart.Name);
var drawing = await Client.Charts.RetrievePublishedVersionAsync(copiedChart.Key);
Assert.Equal("BOOTHS", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
}
}
4 changes: 2 additions & 2 deletions SeatsioDotNet.Test/Charts/CopyChartToWorkspaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CopyChartToWorkspaceTest : SeatsioClientTest
[Fact]
public async Task Test()
{
var chart = await Client.Charts.CreateAsync("my chart", "BOOTHS");
var chart = await Client.Charts.CreateAsync("my chart", "SIMPLE");
var workspace = await Client.Workspaces.CreateAsync("my ws");

var copiedChart = await Client.Charts.CopyToWorkspaceAsync(chart.Key, workspace.Key);
Expand All @@ -18,6 +18,6 @@ public async Task Test()
var retrievedChart = await workspaceClient.Charts.RetrieveAsync(copiedChart.Key);
Assert.Equal("my chart", retrievedChart.Name);
var drawing = await workspaceClient.Charts.RetrievePublishedVersionAsync(copiedChart.Key);
Assert.Equal("BOOTHS", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
}
}
6 changes: 3 additions & 3 deletions SeatsioDotNet.Test/Charts/CreateChartTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Test()
Assert.False(retrievedChart.Archived);

var drawing = await Client.Charts.RetrievePublishedVersionAsync(chart.Key);
Assert.Equal("MIXED", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
Assert.Empty(drawing.Categories);
}

Expand All @@ -44,13 +44,13 @@ public async Task Name()
[Fact]
public async Task VenueType()
{
var chart = await Client.Charts.CreateAsync(null, "BOOTHS");
var chart = await Client.Charts.CreateAsync(null, "SIMPLE");

Chart retrievedChart = await Client.Charts.RetrieveAsync(chart.Key);

Assert.Equal("Untitled chart", retrievedChart.Name);
var drawing = await Client.Charts.RetrievePublishedVersionAsync(chart.Key);
Assert.Equal("BOOTHS", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
Assert.Empty(drawing.Categories);
}

Expand Down
14 changes: 8 additions & 6 deletions SeatsioDotNet.Test/Charts/ListChartsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,28 @@ public async Task Tag()
[Fact]
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 chart = CreateTestChartWithZones();
var event1 = await Client.Events.CreateAsync(chart);
var event2 = await Client.Events.CreateAsync(chart);

var charts = await Client.Charts.ListAllAsync(expandEvents: true, expandValidation: true, expandVenueType: true).ToListAsync();
var charts = await Client.Charts.ListAllAsync(expandEvents: true, expandValidation: true, expandVenueType: true, expandZones: true).ToListAsync();

Assert.Equal(new[] {event2.Id, event1.Id}, charts.First().Events.Select(c => c.Id));
Assert.Equal("MIXED", charts.First().VenueType);
Assert.Equal("WITH_ZONES", charts.First().VenueType);
Assert.NotNull(charts.First().Validation);
Assert.Equal(new[] {new Zone("finishline", "Finish Line"), new Zone("midtrack", "Mid Track")}, charts.First().Zones);
}

[Fact]
public async Task ExpandNone()
{
var chart = await Client.Charts.CreateAsync();
CreateTestChartWithZones();

var charts = await Client.Charts.ListAllAsync(expandEvents: true).ToListAsync();

Assert.Empty(charts.First().Events);
Assert.Null(charts.First().Validation);
Assert.Null(charts.First().VenueType);
Assert.Null(charts.First().Zones);
}
}
8 changes: 4 additions & 4 deletions SeatsioDotNet.Test/Charts/ManageCategoriesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ManageCategoriesTest : SeatsioClientTest
[Fact]
public async Task AddCategory()
{
var chart = await Client.Charts.CreateAsync("aChart", "BOOTHS");
var chart = await Client.Charts.CreateAsync("aChart", "SIMPLE");

await Client.Charts.AddCategoryAsync(chart.Key, new Category(1, "cat 1", "#aaaaaa", true));
var drawing = await Client.Charts.RetrievePublishedVersionAsync(chart.Key);
Expand All @@ -26,7 +26,7 @@ public async Task RemoveCategory()
new Category(1, "Category 1", "#aaaaaa"),
new Category("cat-2", "Category 2", "#bbbbbb", true)
};
var chart = await Client.Charts.CreateAsync("aChart", "BOOTHS", categories);
var chart = await Client.Charts.CreateAsync("aChart", "SIMPLE", categories);

await Client.Charts.RemoveCategoryAsync(chart.Key, 1);

Expand All @@ -42,7 +42,7 @@ public async Task ListCategories()
new Category(1, "Category 1", "#aaaaaa"),
new Category("cat-2", "Category 2", "#bbbbbb", true)
};
var chart = await Client.Charts.CreateAsync("aChart", "BOOTHS", categories);
var chart = await Client.Charts.CreateAsync("aChart", "SIMPLE", categories);

IEnumerable<Category> categoryList = await Client.Charts.ListCategoriesAsync(chart.Key);
Assert.Equal(categories, categoryList);
Expand All @@ -51,7 +51,7 @@ public async Task ListCategories()
[Fact]
public async Task UpdateCategory()
{
var chart = await Client.Charts.CreateAsync("aChart", "BOOTHS");
var chart = await Client.Charts.CreateAsync("aChart", "SIMPLE");
await Client.Charts.AddCategoryAsync(chart.Key, new Category(1, "cat 1", "#aaaaaa", false));

await Client.Charts.UpdateCategoryAsync(chart.Key, 1,
Expand Down
11 changes: 11 additions & 0 deletions SeatsioDotNet.Test/Charts/RetrieveChartTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public async Task Test()
Assert.Null(retrievedChart.Events);
CustomAssert.ContainsOnly(new[] {"tag1", "tag2"}, retrievedChart.Tags);
Assert.False(retrievedChart.Archived);
Assert.Null(retrievedChart.Zones);
}

[Fact]
public async Task WithZones()
{
var chart = CreateTestChartWithZones();

Chart retrievedChart = await Client.Charts.RetrieveAsync(chart);

Assert.Equal(new[] {new Zone("finishline", "Finish Line"), new Zone("midtrack", "Mid Track")}, retrievedChart.Zones);
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions SeatsioDotNet.Test/Charts/UpdateChartTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ public class UpdateChartTest : SeatsioClientTest
[Fact]
public async Task Name()
{
var chart = await Client.Charts.CreateAsync(null, "BOOTHS", new[] {new Category(1, "Category 1", "#aaaaaa")});
var chart = await Client.Charts.CreateAsync(null, "SIMPLE", new[] {new Category(1, "Category 1", "#aaaaaa")});

await Client.Charts.UpdateAsync(chart.Key, "aChart");

Chart retrievedChart = await Client.Charts.RetrieveAsync(chart.Key);
Assert.Equal("aChart", retrievedChart.Name);
var drawing = await Client.Charts.RetrievePublishedVersionAsync(chart.Key);
Assert.Equal("BOOTHS", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
Assert.Single(drawing.Categories);
}

[Fact]
public async Task Categories()
{
var chart = await Client.Charts.CreateAsync("aChart", "BOOTHS");
var chart = await Client.Charts.CreateAsync("aChart", "SIMPLE");

await Client.Charts.UpdateAsync(chart.Key, categories: new[] {new Category(1, "Category 1", "#aaaaaa"), new Category("cat-2", "Category 2", "#bbbbbb", true)});

Chart retrievedChart = await Client.Charts.RetrieveAsync(chart.Key);
Assert.Equal("aChart", retrievedChart.Name);
var drawing = await Client.Charts.RetrievePublishedVersionAsync(chart.Key);
Assert.Equal("BOOTHS", drawing.VenueType);
Assert.Equal("SIMPLE", drawing.VenueType);
Assert.Equal(2, drawing.Categories.Count);
}
}
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/resources/sampleChart.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@
"foreground": false
}
],
"booths": [],
"SIMPLE": [],
"icons": [],
"generalAdmissionAreas": [
{
Expand Down
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/resources/sampleChartWithErrors.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
}
],
"shapes": [],
"booths": [],
"SIMPLE": [],
"generalAdmissionAreas": [
{
"categoryLabel": "Cat1",
Expand Down
6 changes: 3 additions & 3 deletions SeatsioDotNet.Test/resources/sampleChartWithSections.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"texts": [],
"rows": [],
"shapes": [],
"booths": [],
"SIMPLE": [],
"generalAdmissionAreas": [],
"sections": [
{
Expand Down Expand Up @@ -512,7 +512,7 @@
}
],
"shapes": [],
"booths": [],
"SIMPLE": [],
"generalAdmissionAreas": []
}
},
Expand Down Expand Up @@ -1005,7 +1005,7 @@
}
],
"shapes": [],
"booths": [],
"SIMPLE": [],
"generalAdmissionAreas": []
}
}
Expand Down
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/resources/sampleChartWithTables.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"texts": [],
"rows": [],
"shapes": [],
"booths": [],
"SIMPLE": [],
"generalAdmissionAreas": [],
"sections": [],
"focalPoint": {
Expand Down
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/resources/sampleChartWithZones.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SeatsioDotNet/Charts/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public class Chart
public IEnumerable<Event> Events { get; set; }
public ChartValidationResult Validation { get; set; }
public string VenueType { get; set; }
public Zone[] Zones { get; set; }
}
27 changes: 16 additions & 11 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 = false, bool expandValidation = false, bool expandVenueType = false)
public IAsyncEnumerable<Chart> ListAllAsync(string filter = null, string tag = null, bool expandEvents = false, bool expandValidation = false, bool expandVenueType = false, bool expandZones = false)
{
return List().AllAsync(ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType));
return List().AllAsync(ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType, expandZones));
}

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)
public async Task<Page<Chart>> ListFirstPageAsync(string filter = null, string tag = null, bool expandEvents = false, int? pageSize = null, bool expandValidation = false, bool expandVenueType = false, bool expandZones = false, CancellationToken cancellationToken = default)
{
return await List().FirstPageAsync(ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType), pageSize, cancellationToken);
return await List().FirstPageAsync(ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType, expandZones), pageSize, cancellationToken);
}

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)
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, bool expandZones = false, CancellationToken cancellationToken = default)
{
return await List().PageAfterAsync(id, ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType), pageSize, cancellationToken);
return await List().PageAfterAsync(id, ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType, expandZones), pageSize, cancellationToken);
}

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)
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,bool expandZones = false, CancellationToken cancellationToken = default)
{
return await List().PageBeforeAsync(id, ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType), pageSize, cancellationToken);
return await List().PageBeforeAsync(id, ChartListParams(filter, tag, expandEvents, expandValidation, expandVenueType, expandZones), pageSize, cancellationToken);
}

private Dictionary<string, object> ChartListParams(string filter, string tag, bool expandEvents, bool expandValidation, bool expandVenueType)
private Dictionary<string, object> ChartListParams(string filter, string tag, bool expandEvents, bool expandValidation, bool expandVenueType, bool expandZones = false)
{
var chartListParams = new Dictionary<string, object>();

Expand All @@ -297,12 +297,12 @@ private Dictionary<string, object> ChartListParams(string filter, string tag, bo
chartListParams.Add("tag", tag);
}

chartListParams.Add("expand", ChartListExpandParams(expandEvents, expandValidation, expandVenueType));
chartListParams.Add("expand", ChartListExpandParams(expandEvents, expandValidation, expandVenueType, expandZones));

return chartListParams;
}

private object ChartListExpandParams(bool expandEvents, bool expandValidation, bool expandVenueType)
private object ChartListExpandParams(bool expandEvents, bool expandValidation, bool expandVenueType, bool expandZones)
{
var result = new List<string>();

Expand All @@ -319,6 +319,11 @@ private object ChartListExpandParams(bool expandEvents, bool expandValidation, b
if (expandVenueType)
{
result.Add("venueType");
}

if (expandZones)
{
result.Add("zones");
}

return result;
Expand Down
29 changes: 29 additions & 0 deletions SeatsioDotNet/Charts/Zone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace SeatsioDotNet.Charts;

public class Zone
{
Zone()
{
}

public Zone(string key, string label)
{
this.Key = key;
this.Label = label;
}

public string Key { get; set; }
public string Label { get; set; }

public override bool Equals(object obj)
{
if (obj == null || obj.GetType() != typeof(Zone))
{
return false;
}

Zone zone = (Zone) obj;
return Key.Equals(zone.Key) &&
Label.Equals(zone.Label);
}
}

0 comments on commit ea67df1

Please sign in to comment.