Removed strongly typed inventory objects
Added EAV inventory types Added EAV object handling philosophy Added controllers Added EF Core migration integration
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog.Events;
|
||||
using WyvernInventory.Core.Interfaces.Services;
|
||||
using WyvernInventory.Core.Models;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace WyvernInventory.API.Controllers.api.v1;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class InventoryItemController(IInventoryItemService inventoryItemService, ILogger logger) : ControllerBase
|
||||
{
|
||||
private readonly IInventoryItemService _inventoryItemService = inventoryItemService;
|
||||
private ILogger _logger = logger;
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult<List<InventoryItemDto>> Get([FromBody] List<InventoryItemRequest> items)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _inventoryItemService.GetAsync(items).Result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Error, e, "An error occured");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("upsert")]
|
||||
public ActionResult Post([FromBody] List<InventoryItemRequest> items)
|
||||
{
|
||||
try
|
||||
{
|
||||
(int, int) results = _inventoryItemService.UpsertAsync(items).Result;
|
||||
|
||||
if (results.Item1 > 0 || results.Item2 > 0)
|
||||
{
|
||||
return Ok(new { Created = results.Item1, Updated = results.Item2 });
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Error, e, "An error occured");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public ActionResult Delete([FromRoute] int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
int results = _inventoryItemService.DeleteAsync([new() { Id = id }]).Result;
|
||||
|
||||
return Ok(results);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Error, e, "An error occured");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user