Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for-sale config to be specified when events and seasons are created #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions SeatsioDotNet.Test/Events/CreateEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,16 @@ public void ChannelsCanBePassedIn()

Assert.Equivalent(channels, evnt.Channels);
}

[Fact]
public void ForSaleConfigCanBePassedIn()
{
var chartKey = CreateTestChart();
var forSaleConfig = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-1"}).WithAreaPlaces(new(){{"GA1", 5}}).WithCategories(new []{"Cat1"});

var evnt = Client.Events.Create(chartKey, new CreateEventParams().WithForSaleConfig(forSaleConfig));

Assert.Equivalent(forSaleConfig, evnt.ForSaleConfig);
}
}
}
17 changes: 17 additions & 0 deletions SeatsioDotNet.Test/Events/CreateEventsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,22 @@ public void ChannelsCanBePassedIn()

Assert.Equivalent(channels, events[0].Channels);
}

[Fact]
public void ForSaleConfigCanBePassedIn()
{
var chartKey = CreateTestChart();
var forSaleConfig1 = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-1"}).WithAreaPlaces(new(){{"GA1", 3}}).WithCategories(new []{"Cat1"});
var forSaleConfig2 = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-2"}).WithAreaPlaces(new(){{"GA1", 7}}).WithCategories(new []{"Cat1"});

var events = Client.Events.Create(chartKey, new[]
{
new CreateEventParams().WithForSaleConfig(forSaleConfig1),
new CreateEventParams().WithForSaleConfig(forSaleConfig2)
});

Assert.Equivalent(forSaleConfig1, events[0].ForSaleConfig);
Assert.Equivalent(forSaleConfig2, events[1].ForSaleConfig);
}
}
}
14 changes: 12 additions & 2 deletions SeatsioDotNet.Test/Seasons/CreateSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SeatsioDotNet.Charts;
using SeatsioDotNet.Events;
using Xunit;

Expand Down Expand Up @@ -68,7 +67,7 @@ public void TableBookingConfigCanBePassedIn()
var season = Client.Seasons.Create(chartKey, tableBookingConfig: TableBookingConfig.AllBySeat());

Assert.Equal(TableBookingConfig.AllBySeat().Mode, season.TableBookingConfig.Mode);
}
}

[Fact]
public void ChannelsCanBePassedIn()
Expand All @@ -84,5 +83,16 @@ public void ChannelsCanBePassedIn()

Assert.Equivalent(channels, season.Channels);
}

[Fact]
public void ForSaleConfigCanBePassedIn()
{
var chartKey = CreateTestChart();
var forSaleConfig = new ForSaleConfig().WithForSale(false).WithObjects(new []{"A-1"}).WithAreaPlaces(new(){{"GA1", 5}}).WithCategories(new []{"Cat1"});

var season = Client.Seasons.Create(chartKey, forSaleConfig: forSaleConfig);

Assert.Equivalent(forSaleConfig, season.ForSaleConfig);
}
}
}
7 changes: 7 additions & 0 deletions SeatsioDotNet/Events/CreateEventParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CreateEventParams
public Dictionary<string, object> ObjectCategories { get; set; }
public Category[] Categories { get; set; }
public List<Channel> Channels { get; set; }
public ForSaleConfig ForSaleConfig { get; set; }

public CreateEventParams WithKey(string key)
{
Expand Down Expand Up @@ -55,5 +56,11 @@ public CreateEventParams WithChannels(List<Channel> channels)
Channels = channels;
return this;
}

public CreateEventParams WithForSaleConfig(ForSaleConfig forSaleConfig)
{
ForSaleConfig = forSaleConfig;
return this;
}
}
}
10 changes: 10 additions & 0 deletions SeatsioDotNet/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public Event Create(string chartKey, CreateEventParams p)
requestBody.Add("channels", p.Channels);
}

if (p.ForSaleConfig != null)
{
requestBody.Add("forSaleConfig", p.ForSaleConfig.AsJsonObject());
}

var restRequest = new RestRequest("/events", Method.Post).AddJsonBody(requestBody);
return AssertOk(_restClient.Execute<Event>(restRequest));
}
Expand Down Expand Up @@ -111,6 +116,11 @@ public Event[] Create(string chartKey, CreateEventParams[] eventCreationParams)
e.Add("channels", param.Channels);
}

if (param.ForSaleConfig != null)
{
e.Add("forSaleConfig", param.ForSaleConfig.AsJsonObject());
}

events.Add(e);
}

Expand Down
35 changes: 35 additions & 0 deletions SeatsioDotNet/Events/ForSaleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,40 @@ public class ForSaleConfig
public IEnumerable<string> Objects { get; set; }
public Dictionary<string, int> AreaPlaces { get; set; }
public IEnumerable<string> Categories { get; set; }

public ForSaleConfig WithForSale(bool forSale)
{
ForSale = forSale;
return this;
}

public ForSaleConfig WithObjects(IEnumerable<string> objects)
{
Objects = objects;
return this;
}

public ForSaleConfig WithAreaPlaces(Dictionary<string, int> areaPlaces)
{
AreaPlaces = areaPlaces;
return this;
}

public ForSaleConfig WithCategories(IEnumerable<string> categories)
{
Categories = categories;
return this;
}

public object AsJsonObject()
{
return new
{
forSale = ForSale,
objects = Objects,
areaPlaces = AreaPlaces,
categories = Categories
};
}
}
}
8 changes: 6 additions & 2 deletions SeatsioDotNet/Seasons/Seasons.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using RestSharp;
using SeatsioDotNet.Events;
using SeatsioDotNet.Util;
using static SeatsioDotNet.Util.RestUtil;

namespace SeatsioDotNet.Seasons
Expand All @@ -17,7 +16,7 @@ public Seasons(RestClient restClient, SeatsioClient seatsioClient)
_seatsioClient = seatsioClient;
}

public Event Create(string chartKey, string key = null, int? numberOfEvents = null, IEnumerable<string> eventKeys = null, TableBookingConfig tableBookingConfig = null, IEnumerable<Channel> channels = null)
public Event Create(string chartKey, string key = null, int? numberOfEvents = null, IEnumerable<string> eventKeys = null, TableBookingConfig tableBookingConfig = null, IEnumerable<Channel> channels = null, ForSaleConfig forSaleConfig = null)
{
Dictionary<string, object> requestBody = new Dictionary<string, object>();
requestBody.Add("chartKey", chartKey);
Expand Down Expand Up @@ -47,6 +46,11 @@ public Event Create(string chartKey, string key = null, int? numberOfEvents = nu
requestBody.Add("channels", channels);
}

if (forSaleConfig != null)
{
requestBody.Add("forSaleConfig", forSaleConfig.AsJsonObject());
}

var restRequest = new RestRequest("/seasons", Method.Post).AddJsonBody(requestBody);
return AssertOk(_restClient.Execute<Event>(restRequest));
}
Expand Down