Skip to content

Commit

Permalink
Bver/add support for objectcategories (#49)
Browse files Browse the repository at this point in the history
* support for objectCategories when creating a new event

* removed CategoryKey

* test refactoring

* update objectCategories for an event
  • Loading branch information
bverbeken authored Feb 24, 2022
1 parent 3e2c63b commit b5900a7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 22 deletions.
26 changes: 20 additions & 6 deletions SeatsioDotNet.Test/Events/CreateEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void TableBookingModeCustomCanBeUsed()
Assert.NotNull(evnt.Key);
Assert.Equal("CUSTOM", evnt.TableBookingConfig.Mode);
Assert.Equal(new Dictionary<string, string> {{"T1", "BY_TABLE"}, {"T2", "BY_SEAT"}}, evnt.TableBookingConfig.Tables);
}
}

[Fact]
public void TableBookingModeInheritCanBeUsed()
{
Expand All @@ -57,8 +57,8 @@ public void TableBookingModeInheritCanBeUsed()

Assert.NotNull(evnt.Key);
Assert.Equal("INHERIT", evnt.TableBookingConfig.Mode);
}
}

[Fact]
public void SocialDistancingRulesetKeyCanBepassedIn()
{
Expand All @@ -70,8 +70,22 @@ public void SocialDistancingRulesetKeyCanBepassedIn()
Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);

var evnt = Client.Events.Create(chartKey, null, null, "ruleset1");

Assert.Equal("ruleset1", evnt.SocialDistancingRulesetKey);
}


[Fact]
public void ObjectCategoriesCanBepassedIn()
{
var chartKey = CreateTestChart();

var objectCategories = new Dictionary<string, object>()
{
{"A-1", 10L}
};
var evnt = Client.Events.Create(chartKey, null, null, null, objectCategories);
Assert.Equal(objectCategories, evnt.ObjectCategories);
}
}
}
}
36 changes: 36 additions & 0 deletions SeatsioDotNet.Test/Events/UpdateEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,41 @@ public void RemoveSocialDistancingRulesetKey()
var retrievedEvent = Client.Events.Retrieve(evnt.Key);
Assert.Null(retrievedEvent.SocialDistancingRulesetKey);
}

[Fact]
public void UpdateObjectCategories()
{
var chartKey = CreateTestChart();
var objectCategories = new Dictionary<string, object>()
{
{"A-1", 10L}
};
var evnt = Client.Events.Create(chartKey, null, null, null, objectCategories);

var newObjectCategories = new Dictionary<string, object>()
{
{"A-2", 9L}
};
Client.Events.Update(evnt.Key, null, null, null, null, newObjectCategories);

var retrievedEvent = Client.Events.Retrieve(evnt.Key);
Assert.Equal(newObjectCategories, retrievedEvent.ObjectCategories);
}

[Fact]
public void RemoveObjectCategories()
{
var chartKey = CreateTestChart();
var objectCategories = new Dictionary<string, object>()
{
{"A-1", 10L}
};
var evnt = Client.Events.Create(chartKey, null, null, null, objectCategories);

Client.Events.Update(evnt.Key, null, null, null, null, new Dictionary<string, object>());

var retrievedEvent = Client.Events.Retrieve(evnt.Key);
Assert.Null(retrievedEvent.ObjectCategories);
}
}
}
4 changes: 3 additions & 1 deletion SeatsioDotNet/Events/Event.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using SeatsioDotNet.Charts;

namespace SeatsioDotNet.Events
{
Expand All @@ -15,6 +16,7 @@ public class Event
public DateTimeOffset? UpdatedOn { get; set; }
public List<Channel> Channels { get; set; }
public string SocialDistancingRulesetKey { get; set; }
public Dictionary<string, object> ObjectCategories { get; set; }
public List<string> PartialSeasonKeys { get; set; }
public List<Event> Events { get; set; }
public bool IsSeason { get; set; }
Expand All @@ -23,4 +25,4 @@ public class Event
public bool IsEventInSeason { get; set; }
public string TopLevelSeasonKey { get; set; }
}
}
}
53 changes: 38 additions & 15 deletions SeatsioDotNet/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using SeatsioDotNet.EventReports;
using SeatsioDotNet.Util;
using static SeatsioDotNet.Util.RestUtil;
using SeatsioDotNet.Charts;
using System;

namespace SeatsioDotNet.Events
{
Expand All @@ -19,20 +21,25 @@ public Events(RestClient restClient)

public Event Create(string chartKey)
{
return Create(chartKey, null, null, null);
return Create(chartKey, null, null, null, null);
}

public Event Create(string chartKey, string eventKey)
{
return Create(chartKey, eventKey, null, null);
return Create(chartKey, eventKey, null, null, null);
}

public Event Create(string chartKey, string eventKey, TableBookingConfig tableBookingConfig)
{
return Create(chartKey, eventKey, tableBookingConfig, null);
return Create(chartKey, eventKey, tableBookingConfig, null, null);
}

public Event Create(string chartKey, string eventKey, TableBookingConfig tableBookingConfig, string socialDistancingRulesetKey)
{
return Create(chartKey, eventKey, tableBookingConfig, socialDistancingRulesetKey, null);
}

public Event Create(string chartKey, string eventKey, TableBookingConfig tableBookingConfig, string socialDistancingRulesetKey, Dictionary<string, object> objectCategories)
{
Dictionary<string, object> requestBody = new Dictionary<string, object>();
requestBody.Add("chartKey", chartKey);
Expand All @@ -52,6 +59,11 @@ public Event Create(string chartKey, string eventKey, TableBookingConfig tableBo
requestBody.Add("socialDistancingRulesetKey", socialDistancingRulesetKey);
}

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

var restRequest = new RestRequest("/events", Method.POST).AddJsonBody(requestBody);
return AssertOk(_restClient.Execute<Event>(restRequest));
}
Expand Down Expand Up @@ -86,14 +98,20 @@ public Event[] Create(string chartKey, EventCreationParams[] eventCreationParams
public void Update(string eventKey, string chartKey, string newEventKey)
{
Update(eventKey, chartKey, newEventKey, null, null);
}
}

public void Update(string eventKey, string chartKey, string newEventKey, TableBookingConfig tableBookingConfig)
{
Update(eventKey, chartKey, newEventKey, tableBookingConfig, null);
}

public void Update(string eventKey, string chartKey, string newEventKey, TableBookingConfig tableBookingConfig, string socialDistancingRulesetKey)
public void Update(string eventKey, string chartKey, string newEventKey, TableBookingConfig tableBookingConfig,
string socialDistancingRulesetKey)
{
Update(eventKey, chartKey, newEventKey, tableBookingConfig, socialDistancingRulesetKey, null);
}

public void Update(string eventKey, string chartKey, string newEventKey, TableBookingConfig tableBookingConfig, string socialDistancingRulesetKey, Dictionary<string, object> objectCategories)
{
Dictionary<string, object> requestBody = new Dictionary<string, object>();

Expand All @@ -117,6 +135,11 @@ public void Update(string eventKey, string chartKey, string newEventKey, TableBo
requestBody.Add("socialDistancingRulesetKey", socialDistancingRulesetKey);
}

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

var restRequest = new RestRequest("/events/{key}", Method.POST)
.AddUrlSegment("key", eventKey)
.AddJsonBody(requestBody);
Expand All @@ -142,19 +165,19 @@ public EventObjectInfo RetrieveObjectInfo(string eventKey, string objectLabel)
var result = RetrieveObjectInfos(eventKey, new[] {objectLabel});
return result[objectLabel];
}

public Dictionary<string, EventObjectInfo> RetrieveObjectInfos(string eventKey, string[] objectLabels)
{
var restRequest = new RestRequest("/events/{key}/objects", Method.GET)
.AddUrlSegment("key", eventKey);

foreach (var objectLabel in objectLabels)
{
restRequest.AddQueryParameter("label", objectLabel);
}

return AssertOk(_restClient.Execute<Dictionary<string, EventObjectInfo>>(restRequest));

}

public ChangeObjectStatusResult Book(string eventKey, IEnumerable<string> objects, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null, string[] channelKeys = null, bool? ignoreSocialDistancing = null)
Expand Down Expand Up @@ -242,7 +265,7 @@ public ChangeObjectStatusResult ChangeObjectStatus(IEnumerable<string> events, I
return ChangeObjectStatus(events, objects.Select(o => new ObjectProperties(o)), status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, ignoreSocialDistancing);
}

public ChangeObjectStatusResult ChangeObjectStatus(IEnumerable<string> events, IEnumerable<ObjectProperties> objects, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null, string[] channelKeys = null, bool? ignoreSocialDistancing = null, string[] allowedPreviousStatuses = null, string[] rejectedPreviousStatuses = null)
public ChangeObjectStatusResult ChangeObjectStatus(IEnumerable<string> events, IEnumerable<ObjectProperties> objects, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null, string[] channelKeys = null, bool? ignoreSocialDistancing = null, string[] allowedPreviousStatuses = null, string[] rejectedPreviousStatuses = null)
{
var requestBody = ChangeObjectStatusRequest(events, objects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, ignoreSocialDistancing, allowedPreviousStatuses, rejectedPreviousStatuses);
var restRequest = new RestRequest("/events/groups/actions/change-object-status", Method.POST)
Expand Down Expand Up @@ -296,7 +319,7 @@ private Dictionary<string, object> ChangeObjectStatusRequest(IEnumerable<ObjectP
{
requestBody.Add("keepExtraData", keepExtraData);
}

if (ignoreChannels != null)
{
requestBody.Add("ignoreChannels", ignoreChannels);
Expand All @@ -306,7 +329,7 @@ private Dictionary<string, object> ChangeObjectStatusRequest(IEnumerable<ObjectP
{
requestBody.Add("channelKeys", channelKeys);
}

if (ignoreSocialDistancing != null)
{
requestBody.Add("ignoreSocialDistancing", ignoreSocialDistancing);
Expand Down Expand Up @@ -346,12 +369,12 @@ public BestAvailableResult ChangeObjectStatus(string eventKey, BestAvailable bes
{
requestBody.Add("keepExtraData", keepExtraData);
}

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

if (channelKeys != null)
{
requestBody.Add("channelKeys", channelKeys);
Expand Down

0 comments on commit b5900a7

Please sign in to comment.