diff --git a/barkman.sln b/barkman.sln index 1fe295e..633caa4 100644 --- a/barkman.sln +++ b/barkman.sln @@ -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 diff --git a/barkman/DB.cs b/barkman/DB.cs deleted file mode 100644 index 231fad2..0000000 --- a/barkman/DB.cs +++ /dev/null @@ -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 _inventory = new List() - { - 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 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(); - } -} \ No newline at end of file diff --git a/barkman/Program.cs b/barkmanAPI/Program.cs similarity index 66% rename from barkman/Program.cs rename to barkmanAPI/Program.cs index 5a8f98b..6101173 100644 --- a/barkman/Program.cs +++ b/barkmanAPI/Program.cs @@ -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(); \ No newline at end of file diff --git a/barkman/Properties/launchSettings.json b/barkmanAPI/Properties/launchSettings.json similarity index 100% rename from barkman/Properties/launchSettings.json rename to barkmanAPI/Properties/launchSettings.json diff --git a/barkman/appsettings.Development.json b/barkmanAPI/appsettings.Development.json similarity index 100% rename from barkman/appsettings.Development.json rename to barkmanAPI/appsettings.Development.json diff --git a/barkman/appsettings.json b/barkmanAPI/appsettings.json similarity index 100% rename from barkman/appsettings.json rename to barkmanAPI/appsettings.json diff --git a/barkman/barkman.http b/barkmanAPI/barkman.http similarity index 100% rename from barkman/barkman.http rename to barkmanAPI/barkman.http diff --git a/barkman/barkman.csproj b/barkmanAPI/barkmanAPI.csproj similarity index 75% rename from barkman/barkman.csproj rename to barkmanAPI/barkmanAPI.csproj index 2805cec..ccbffe7 100644 --- a/barkman/barkman.csproj +++ b/barkmanAPI/barkmanAPI.csproj @@ -4,10 +4,12 @@ net9.0 enable enable + barkman + diff --git a/barkmanAPI/inventoryModel.cs b/barkmanAPI/inventoryModel.cs new file mode 100644 index 0000000..718c0d7 --- /dev/null +++ b/barkmanAPI/inventoryModel.cs @@ -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 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(); + } +} \ No newline at end of file