Skip to content

Commit

Permalink
ADDING FUNCTIONALITY TO UPDATE AND CREATE ORDERS IN BULK. THIS
Browse files Browse the repository at this point in the history
FUNCTIONALITY DID NOT EXIST BEFORE.
  • Loading branch information
Ather Rizvi committed Dec 30, 2021
1 parent 1c9d0f9 commit a8683d8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ShipStation4Net/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ protected Task<T> PostDataAsync<T>(string resourceEndpoint, T data)
return PostDataAsync<T, T>(resourceEndpoint, data);
}

protected Task<T> PutDataAsync<T>(int id, T data)
protected Task<U> BulkPostDataAsync<T, U>(string resourceEndpoint, T data) where U : class
{
return PostDataAsync<T, U>(resourceEndpoint, data);
}

protected Task<T> PutDataAsync<T>(int id, T data)
{
return PutDataAsync(string.Format("{0}/{1}", BaseUri, id), data);
}
Expand Down
23 changes: 23 additions & 0 deletions ShipStation4Net/Clients/Orders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public Task<Order> CreateAsync(Order newItem)

/// <summary>
/// An alias of CreateAsync because updates are on the same endpoint as creates.
/// ShipStation recommends using this method instead of calling the create api multiple times.
/// https://www.shipstation.com/docs/api/orders/create-update-multiple-orders/
/// </summary>
/// <param name="item">The item to update.</param>
/// <returns>The updated order.</returns>
Expand All @@ -145,6 +147,27 @@ public Task<Order> UpdateAsync(Order item)
return CreateAsync(item);
}

/// <summary>
/// Will create a list of orders in bulk. If the orderKey is supplied then the order will
/// be updated.
/// </summary>
/// <param name="items">List of new items to create</param>
/// <returns>BulkOrderResponse which contains created orders</returns>
public Task<BulkOrderResponse> BulkCreateAsync(List<Order> items)
{
return BulkPostDataAsync<List<Order>, BulkOrderResponse>("createorders", items);
}

/// <summary>
/// An alias for BulkCreateAsync which updates all items in the list.
/// </summary>
/// <param name="items">List of new items to update</param>
/// <returns>BulkOrderResponse which contains updated orders</returns>
public Task<BulkOrderResponse> BulkUpdateAsync(List<Order> items)
{
return BulkCreateAsync(items);
}

/// <summary>
/// Retrieves a single order from the database.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions ShipStation4Net/Domain/Entities/BulkOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace ShipStation4Net.Domain.Entities
{
public class BulkOrderResult
{
[JsonProperty("orderId")]
public int? OrderId { get; set; }

[JsonProperty("orderNumber")]
public string OrderNumber { get; set; }

[JsonProperty("orderKey")]
public string OrderKey { get; set; }

[JsonProperty("success")]
public bool Success { get; set; }

[JsonProperty("errorMessage")]
public string ErrorMessage { get; set; }
}
}
15 changes: 15 additions & 0 deletions ShipStation4Net/Responses/BulkOrderResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;
using ShipStation4Net.Domain.Entities;
using System.Collections.Generic;

namespace ShipStation4Net.Responses
{
public class BulkOrderResponse
{
[JsonProperty("hasErrors")]
public bool HasErrors { get; set; }

[JsonProperty("results")]
public List<BulkOrderResult> Results { get; set; }
}
}

0 comments on commit a8683d8

Please sign in to comment.