Skip to content

Commit

Permalink
Merge branch 'development' into INFSCP01-122-1-feature-client-create
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidim9 authored Dec 2, 2024
2 parents 96608e9 + ef3ad6e commit 03c45ac
Show file tree
Hide file tree
Showing 18 changed files with 1,283 additions and 90 deletions.
52 changes: 52 additions & 0 deletions api/Controllers/InventoriesController.cs
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,
}
});
}
}
68 changes: 68 additions & 0 deletions api/DTOs/InventoryDTO.cs
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; }
}

Loading

0 comments on commit 03c45ac

Please sign in to comment.