mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-12 22:11:54 +00:00
things and stuff
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using BarkMan.DB;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "BarkMan API", Description = "BARK BARK WOOF WOOF", Version = "v1" });
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bark Inventory API V1");
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/", () => "Hello World!");
|
||||
|
||||
app.MapGet("/inventory/{id}", (int id) => InventoryDb.GetInventory(id));
|
||||
app.MapGet("/inventory", () => InventoryDb.GetInventory());
|
||||
app.MapPost("/inventory", (InventoryItem item) => InventoryDb.CreateInventoryItem(item));
|
||||
app.MapPut("/inventory", (InventoryItem item) => InventoryDb.UpdateItem(item));
|
||||
app.MapDelete("/inventory/{id}", (int id) => InventoryDb.RemoveItem(id));
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5211",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7157;http://localhost:5211",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@barkman_HostAddress = http://localhost:5211
|
||||
|
||||
GET {{barkman_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>barkman</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class InventoryContext : DbContext
|
||||
{
|
||||
public int Id {get; set;}
|
||||
public string Name { get; set; }
|
||||
public string Brand { get; set; }
|
||||
public string? SerialNumber { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public float? RentalPrice { get; set; }
|
||||
public float? ReplacementCost { get; set; }
|
||||
public string? Notes { get; set; }
|
||||
|
||||
public string DbPath { get; }
|
||||
|
||||
public InventoryContext()
|
||||
{
|
||||
var folder = Environment.SpecialFolder.LocalApplicationData;
|
||||
var path = Environment.GetFolderPath(folder);
|
||||
DbPath = System.IO.Path.Join(path, "blogging.db");
|
||||
}
|
||||
|
||||
// The following configures EF to create a Sqlite database file in the
|
||||
// special "local" folder for your platform.
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||
=> options.UseSqlite($"Data Source={DbPath}");
|
||||
|
||||
}
|
||||
|
||||
public class InventoryDb
|
||||
{
|
||||
|
||||
public static List<InventoryItem> GetInventory()
|
||||
{
|
||||
return _inventory;
|
||||
}
|
||||
|
||||
public static InventoryItem ? GetInventory(int id)
|
||||
{
|
||||
return _inventory.SingleOrDefault(item => item.Id == id);
|
||||
}
|
||||
|
||||
public static InventoryItem CreateInventoryItem(InventoryItem item)
|
||||
{
|
||||
_inventory.Add(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static InventoryItem UpdateItem(InventoryItem update)
|
||||
{
|
||||
_inventory = _inventory.Select(item =>
|
||||
{
|
||||
if (item.Id == update.Id)
|
||||
{
|
||||
item.Name = update.Name;
|
||||
}
|
||||
return item;
|
||||
}).ToList();
|
||||
return update;
|
||||
}
|
||||
|
||||
public static void RemoveItem(int id)
|
||||
{
|
||||
_inventory = _inventory.FindAll(item => item.Id != id).ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user