Skip to content

Commit

Permalink
Added base CommandResponse class for all specific responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Inventor22 committed Mar 2, 2019
1 parent 6028fe5 commit 8b06c55
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class Commands
public const string SetQuantity = "SetQuantity";
public const string ShowAllBoxes = "ShowAllBoxes";
public const string BundleWith = "BundleWith";
public const string UnknownCommand = "UnknownCommand";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


namespace FindyBot3000.AzureFunction
{
using System.Collections.Generic;

public class TaggedItem : Item
{
public int? TagsMatched { get; set; }

public HashSet<string> Tags { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;


namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;

public class AddTagsResponse : ICommandCountResponse, ICommandFlagResponse, ICommandResponse
public class AddTagsResponse : CommandResponse, ICommandCountResponse, ICommandFlagResponse
{
public AddTagsResponse(bool success, int count)
{
this.Command = Commands.AddTags;
this.Success = success;
this.Count = count;
}

public string Command => Commands.AddTags;


public int Count { get; set; }

public bool Success { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@

namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;

public class CommandBooleanResponse : ICommandFlagResponse, ICommandResponse
public class CommandBooleanResponse : CommandResponse, ICommandFlagResponse
{
public CommandBooleanResponse(string command, bool success)
{
this.Command = command;
this.Success = success;
}

public string Command { get; private set; }

public bool Success { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@



namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;

public abstract class CommandResponse : ICommandResponse
{
public string Command { get; protected set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ namespace FindyBot3000.AzureFunction
using Newtonsoft.Json;
using System.Collections.Generic;

public class FindItemResponse : ICommandItemResponse, ICommandResponse
public class FindItemResponse : CommandResponse, ICommandItemResponse
{
public FindItemResponse() { }
public FindItemResponse()
{
this.Command = Commands.FindItem;
}

public FindItemResponse(List<Item> result)
{
this.Result = result;
this.Command = Commands.FindItem;
}

public string Command { get { return Commands.FindItem; } }


public int Count
{
get
Expand All @@ -25,10 +27,5 @@ public int Count
}

public List<Item> Result { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ namespace FindyBot3000.AzureFunction
using Newtonsoft.Json;
using System.Collections.Generic;

public class FindTagsResponse : ICommandResponse
public class FindTagsResponse : CommandResponse
{
public FindTagsResponse(int tagsCount, List<int[]> result)
{
this.Command = Commands.FindTags;
this.Tags = tagsCount;
this.Result = result;
}

public string Command => Commands.FindTags;


public int Count
{
get
Expand All @@ -26,10 +25,5 @@ public int Count
public int Tags { get; set; }

public List<int[]> Result { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@

namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;

public class InsertItemResponse : ICommandFlagResponse, ICommandResponse
public class InsertItemResponse : CommandResponse, ICommandFlagResponse
{
public InsertItemResponse(bool success)
{
this.Command = Commands.InsertItem;
this.Success = success;
}

public InsertItemResponse(bool success, int row, int col)
{
this.Command = Commands.InsertItem;
this.Success = success;
this.Row = row;
this.Col = col;
}

public string Command => Commands.InsertItem;

public bool Success { get; set; }

public int? Row { get; set; }

public int? Col { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@

namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;

public class ShowAllBoxesResponse : ICommandResponse
public class ShowAllBoxesResponse : CommandResponse, ICommandCountResponse
{
public ShowAllBoxesResponse() { }
public ShowAllBoxesResponse()
{
this.Command = Commands.FindItem;
}

public ShowAllBoxesResponse(int count, string coords)
{
this.Command = Commands.FindItem;
this.Count = count;
this.Coords = coords;
}

public string Command { get { return Commands.FindItem; } }

public int Count { get; set; } = 0;

public string Coords { get; set; } = string.Empty;

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;
using System.Collections.Generic;

public class SingleItemResponse : ICommandItemResponse, ICommandResponse
public class SingleItemResponse : CommandResponse, ICommandItemResponse
{
public SingleItemResponse(string command)
{
Expand All @@ -18,15 +17,8 @@ public SingleItemResponse(string command, List<Item> result)
this.Result = result;
}

public string Command { get; private set; }

public int Count { get { return this.Result != null ? this.Result.Count : -1; } }

public List<Item> Result { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

namespace FindyBot3000.AzureFunction
{
using Newtonsoft.Json;

public class UnknownCommandResponse : ICommandResponse
public class UnknownCommandResponse : CommandResponse
{
public UnknownCommandResponse(string unknownCommand)
{
this.Command = Commands.UnknownCommand;
this.UnknownCommand = unknownCommand;
}

public string Command { get { return "UnknownCommand"; } }

public string UnknownCommand { get; set; }

public string ToJsonString(bool indent = false)
{
return JsonConvert.SerializeObject(this, indent ? Formatting.Indented : Formatting.None);
}
}
}
Loading

0 comments on commit 8b06c55

Please sign in to comment.