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:
+1
-1
@@ -1,6 +1,6 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "barkman", "barkman\barkman.csproj", "{625B24F1-FA8F-45F6-B3C8-22C538112B65}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "barkmanAPI", "barkmanAPI\barkmanAPI.csproj", "{625B24F1-FA8F-45F6-B3C8-22C538112B65}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
namespace BarkMan.DB;
|
||||
|
||||
public record InventoryItem
|
||||
{
|
||||
public int Id {get; set;}
|
||||
public string ? Name { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
|
||||
public class InventoryDB
|
||||
{
|
||||
private static List<InventoryItem> _inventory = new List<InventoryItem>()
|
||||
{
|
||||
new InventoryItem(){Id = 1, Name = "Dac70", Quantity = 1},
|
||||
new InventoryItem(){Id = 2, Name = "Ethercon Barrel", Quantity = 4},
|
||||
new InventoryItem(){Id = 3, Name = "Powercon Barrel", Quantity = 4},
|
||||
new InventoryItem(){Id = 4, Name = "2018 MacBook Pro", Quantity = 1},
|
||||
};
|
||||
|
||||
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(pizza =>
|
||||
{
|
||||
if (pizza.Id == update.Id)
|
||||
{
|
||||
pizza.Name = update.Name;
|
||||
}
|
||||
return pizza;
|
||||
}).ToList();
|
||||
return update;
|
||||
}
|
||||
|
||||
public static void RemoveItem(int id)
|
||||
{
|
||||
_inventory = _inventory.FindAll(item => item.Id != id).ToList();
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,10 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
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.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();
|
||||
@@ -4,10 +4,12 @@
|
||||
<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>
|
||||
|
||||
@@ -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