Initial Commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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,23 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["WyvernInventory.API/WyvernInventory.API.csproj", "WyvernInventory.API/"]
|
||||
RUN dotnet restore "WyvernInventory.API/WyvernInventory.API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/WyvernInventory.API"
|
||||
RUN dotnet build "./WyvernInventory.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./WyvernInventory.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "WyvernInventory.API.dll"]
|
||||
@@ -0,0 +1,31 @@
|
||||
using WyvernInventory.Core.Interfaces.Repos;
|
||||
using WyvernInventory.Core.Interfaces.Services;
|
||||
using WyvernInventory.Core.Models;
|
||||
using WyvernInventory.Infrastructure.Repos;
|
||||
using WyvernInventory.Infrastructure.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddSingleton<IDbObjectRepo<GenericInventoryItem>, GenericInventoryItemRepo>();
|
||||
builder.Services.AddSingleton<IDataObjectService<GenericInventoryItem>, GenericInventoryItemService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://0.0.0.0:5244",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7048;http://localhost:5244",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace WyvernInventory.API;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.6"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WyvernInventory.Core\WyvernInventory.Core.csproj" />
|
||||
<ProjectReference Include="..\WyvernInventory.Infrastructure\WyvernInventory.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,25 @@
|
||||
@WyvernInventory.API_HostAddress = http://localhost:5244
|
||||
|
||||
POST http://localhost:5244/inventory
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
{
|
||||
"name": "RTX 4070"
|
||||
}
|
||||
]
|
||||
###
|
||||
|
||||
POST http://localhost:5244/inventory/upsert
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
{
|
||||
"name": "RTX 4070 Ti Super",
|
||||
"description": "Desktop GPU"
|
||||
},
|
||||
{
|
||||
"name": "Ryzen 9 7950X3D",
|
||||
"description": "Desktop CPU 16c/32t"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user