Files
Partsource/PartSource.Api/Controllers/InventoryController.cs
2020-09-02 20:53:34 -04:00

45 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PartSource.Data.Models;
using PartSource.Services;
using System.Net;
using System.Threading.Tasks;
namespace PartSource.Api.Controllers
{
[Route("[controller]")]
[Route("v1/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "v1")]
public class InventoryController : BaseNexpartController
{
private readonly PartService _inventoryService;
public InventoryController(PartService inventoryService)
{
_inventoryService = inventoryService;
}
[HttpGet]
[Route("sku/{sku}/storeNumber/{storeNumber}")]
public async Task<ActionResult> GetInventory(int sku, int storeNumber)
{
PartsAvailability inventory = await _inventoryService.GetInventory(sku, storeNumber);
if (inventory == null)
{
return NotFound($"No part matching SKU {sku} was found.");
}
return Ok(new
{
data = new
{
StoreNumber = inventory.Store,
Sku = sku,
Quantity = inventory.QTY
}
});
}
}
}