-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into INFSCP01-122-1-feature-client-create
- Loading branch information
Showing
18 changed files
with
1,283 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class InventoriesController : ControllerBase | ||
{ | ||
private readonly InventoriesProvider _inventoriesProvider; | ||
private readonly LocationsProvider _locationsProvider; | ||
|
||
public InventoriesController(InventoriesProvider inventoriesProvider, LocationsProvider locationsProvider) | ||
{ | ||
_inventoriesProvider = inventoriesProvider; | ||
_locationsProvider = locationsProvider; | ||
} | ||
|
||
[HttpPost()] | ||
public IActionResult Create([FromBody] InventoryRequest req) | ||
{ | ||
if(req.ItemId.HasValue && _inventoriesProvider.GetInventoryByItemId(req.ItemId.Value) != null){ | ||
return BadRequest(new {message = $"Inventory already exists for ItemId '{req.ItemId.Value}'"}); | ||
} | ||
|
||
Inventory? newInventory = _inventoriesProvider.Create(req); | ||
if (newInventory == null) throw new ApiFlowException("Saving new inventory failed."); | ||
|
||
List<Location> locations = _locationsProvider.GetLocationsByInventoryId(newInventory.Id); | ||
|
||
Dictionary<string, int> calculatedValues = _inventoriesProvider.GetCalculatedValues(newInventory.Id); | ||
|
||
return Ok(new | ||
{ | ||
message = "Inventory created!", | ||
created_inventory = new InventoryResponse | ||
{ | ||
Description = newInventory.Description, | ||
ItemReference = newInventory.ItemReference, | ||
ItemId = newInventory.ItemId, | ||
Locations = locations.Select(l => new InventoryLocation() { | ||
LocationId = l.Id, | ||
OnHand = l.OnHand | ||
}).ToList(), | ||
TotalOnHand = calculatedValues["TotalOnHand"], | ||
TotalExpected = calculatedValues["TotalExpected"], | ||
TotalOrdered = calculatedValues["TotalOrdered"], | ||
TotalAllocated = calculatedValues["TotalAllocated"], | ||
TotalAvailable = calculatedValues["TotalAvailable"], | ||
CreatedAt = newInventory.CreatedAt, | ||
UpdatedAt = newInventory.UpdatedAt, | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Text.Json.Serialization; | ||
|
||
|
||
[ApiExplorerSettings(IgnoreApi = true)] | ||
public class InventoryRequest : BaseDTO | ||
{ | ||
[JsonPropertyName("description")] | ||
public string? Description { get; set; } | ||
|
||
[JsonPropertyName("item_reference")] | ||
public string? ItemReference { get; set; } | ||
|
||
[JsonPropertyName("item_id")] | ||
public Guid? ItemId { get; set; } | ||
|
||
[JsonPropertyName("locations")] | ||
public List<InventoryLocation>? Locations { get; set; } | ||
} | ||
|
||
|
||
[ApiExplorerSettings(IgnoreApi = true)] | ||
public class InventoryResponse : BaseDTO | ||
{ | ||
[JsonPropertyName("description")] | ||
public string? Description { get; set; } | ||
|
||
[JsonPropertyName("item_reference")] | ||
public string? ItemReference { get; set; } | ||
|
||
[JsonPropertyName("item_id")] | ||
public Guid? ItemId { get; set; } | ||
|
||
[JsonPropertyName("locations")] | ||
public List<InventoryLocation>? Locations { get; set; } | ||
|
||
[JsonPropertyName("created_at")] | ||
public DateTime? CreatedAt { get; set; } | ||
|
||
[JsonPropertyName("updated_at")] | ||
public DateTime? UpdatedAt { get; set; } | ||
|
||
[JsonPropertyName("total_on_hand")] | ||
public int? TotalOnHand { get; set; } | ||
|
||
[JsonPropertyName("total_expected")] | ||
public int? TotalExpected { get; set; } | ||
|
||
[JsonPropertyName("total_ordered")] | ||
public int? TotalOrdered { get; set; } | ||
|
||
[JsonPropertyName("total_allocated")] | ||
public int? TotalAllocated { get; set; } | ||
|
||
[JsonPropertyName("total_available")] | ||
public int? TotalAvailable { get; set; } | ||
} | ||
|
||
|
||
public class InventoryLocation : BaseDTO | ||
{ | ||
[JsonPropertyName("location_id")] | ||
public Guid? LocationId { get; set; } | ||
|
||
[JsonPropertyName("on_hand")] | ||
public int? OnHand { get; set; } | ||
} | ||
|
Oops, something went wrong.