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:
@@ -1,40 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WyvernInventory.Core.Interfaces.Services;
|
||||
using WyvernInventory.Core.Models;
|
||||
|
||||
namespace WyvernInventory.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class InventoryController(IDataObjectService<GenericInventoryItem> genericItemService)
|
||||
: ControllerBase
|
||||
{
|
||||
private readonly IDataObjectService<GenericInventoryItem> _genericItemService = genericItemService;
|
||||
|
||||
[HttpPost]
|
||||
public List<GenericInventoryItem> Get([FromBody] List<GenericInventoryItem> items)
|
||||
{
|
||||
return _genericItemService.GetAsync(_ => _).Result;
|
||||
}
|
||||
|
||||
[HttpPost("upsert")]
|
||||
public IResult Post([FromBody] List<GenericInventoryItem> items)
|
||||
{
|
||||
(int, int) results = _genericItemService.UpsertAsync(items).Result;
|
||||
|
||||
if (results.Item1 > 0 || results.Item2 > 0)
|
||||
{
|
||||
return Results.StatusCode(201);
|
||||
}
|
||||
|
||||
return Results.Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public IResult Delete([FromRoute] int id)
|
||||
{
|
||||
_genericItemService.DeleteAsync(new() { new() { Id = id } }).Wait();
|
||||
|
||||
return Results.Ok();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WyvernInventory.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> GetBwah()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
[HttpGet("bwah", Name = "GetWeatherForecastBwah")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 2).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.HttpLogging;
|
||||
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 InventoryTypeController(IDataObjectService<InventoryType, InventoryTypeDto> inventoryTypeService, ILogger logger) : ControllerBase
|
||||
{
|
||||
private readonly IDataObjectService<InventoryType, InventoryTypeDto> _inventoryTypeService = inventoryTypeService;
|
||||
private ILogger _logger = logger;
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult<List<InventoryTypeDto>> Get([FromBody] List<InventoryType> items)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _inventoryTypeService.GetAsync(items).Result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Error, e, "An error occured");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("upsert")]
|
||||
public IActionResult Post([FromBody] List<InventoryType> items)
|
||||
{
|
||||
try
|
||||
{
|
||||
(int, int) results = _inventoryTypeService.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 IActionResult Delete([FromRoute] int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
int results = _inventoryTypeService.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