diff --git a/barkmanAPI/Migrations/20250123185805_status.Designer.cs b/barkmanAPI/Migrations/20250123185805_status.Designer.cs new file mode 100644 index 0000000..995dce6 --- /dev/null +++ b/barkmanAPI/Migrations/20250123185805_status.Designer.cs @@ -0,0 +1,91 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using barkmanapi; + +#nullable disable + +namespace barkmanapi.Migrations +{ + [DbContext(typeof(BarkContext))] + [Migration("20250123185805_status")] + partial class status + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("barkmanapi.InventoryItems", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Brand") + .IsRequired() + .HasColumnType("text") + .HasColumnName("brand"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("Notes") + .HasColumnType("text") + .HasColumnName("notes"); + + b.Property("RentalPrice") + .HasColumnType("real") + .HasColumnName("rental_price"); + + b.Property("ReplacementCost") + .HasColumnType("real") + .HasColumnName("replacement_cost"); + + b.Property("SerialNumber") + .HasColumnType("text") + .HasColumnName("serial_number"); + + b.Property("Status") + .HasColumnType("text") + .HasColumnName("status"); + + b.HasKey("Id") + .HasName("pk_inventory"); + + b.ToTable("inventory", (string)null); + }); + + modelBuilder.Entity("barkmanapi.ItemStatus", b => + { + b.Property("Id") + .HasColumnType("text") + .HasColumnName("id"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id") + .HasName("pk_item_status"); + + b.ToTable("item_status", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/barkmanAPI/Migrations/20250123185805_status.cs b/barkmanAPI/Migrations/20250123185805_status.cs new file mode 100644 index 0000000..0b2677d --- /dev/null +++ b/barkmanAPI/Migrations/20250123185805_status.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace barkmanapi.Migrations +{ + /// + public partial class status : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "item_status", + columns: table => new + { + id = table.Column(type: "text", nullable: false), + name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_item_status", x => x.id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "item_status"); + } + } +} diff --git a/barkmanAPI/Migrations/BarkContextModelSnapshot.cs b/barkmanAPI/Migrations/BarkContextModelSnapshot.cs index ab7aae2..6de27d7 100644 --- a/barkmanAPI/Migrations/BarkContextModelSnapshot.cs +++ b/barkmanAPI/Migrations/BarkContextModelSnapshot.cs @@ -65,6 +65,23 @@ namespace barkmanapi.Migrations b.ToTable("inventory", (string)null); }); + + modelBuilder.Entity("barkmanapi.ItemStatus", b => + { + b.Property("Id") + .HasColumnType("text") + .HasColumnName("id"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id") + .HasName("pk_item_status"); + + b.ToTable("item_status", (string)null); + }); #pragma warning restore 612, 618 } } diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 6c46e45..359f9a1 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -10,18 +10,20 @@ builder.Services.AddDbContext(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "BarkMan API", Description = "BARK BARK WOOF WOOF", Version = "v1" }); + c.SwaggerDoc("v1", + new OpenApiInfo { Title = "BarkMan API", Description = "BARK BARK WOOF WOOF", Version = "v1" }); }); builder.Services.AddCors(options => { options.AddPolicy(name: allowSpecificOrigins, - policy => + policy => { - policy.WithOrigins("https://barkdev.ts.drewr.io", "http://localhost:5173").AllowAnyMethod().AllowAnyHeader(); + policy.WithOrigins("https://barkdev.ts.drewr.io", "http://localhost:5173").AllowAnyMethod() + .AllowAnyHeader(); }); }); -builder.Services.AddDbContext(opt => +builder.Services.AddDbContext(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")).UseSnakeCaseNamingConvention()); var app = builder.Build(); @@ -29,16 +31,13 @@ var app = builder.Build(); if (!app.Environment.IsProduction()) { app.UseSwagger(); - app.UseSwaggerUI(c => - { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bark Inventory API V1"); - }); + app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bark Productions API V1"); }); } app.MapGet("/", () => "Hello World!"); app.MapGet("/inventory", async (BarkContext db) => - await db.Inventory.OrderBy(item=>item.Id).ToListAsync()); + await db.Inventory.OrderBy(item => item.Id).ToListAsync()); app.MapGet("/inventory/{id}", async (int id, BarkContext db) => { @@ -47,6 +46,7 @@ app.MapGet("/inventory/{id}", async (int id, BarkContext db) => { return Results.NotFound(new { Message = "Inventory item not found" }); } + return Results.Ok(item); }); @@ -57,7 +57,7 @@ app.MapPut("/inventory/{id}", async (int id, InventoryItems updatedItem, BarkCon { return Results.NotFound(new { Message = "Inventory item not found" }); } - + existingItem.Name = updatedItem.Name; existingItem.Brand = updatedItem.Brand; existingItem.SerialNumber = updatedItem.SerialNumber; @@ -68,7 +68,7 @@ app.MapPut("/inventory/{id}", async (int id, InventoryItems updatedItem, BarkCon await db.SaveChangesAsync(); return Results.Ok(existingItem); - }); +}); app.MapPost("/inventory", async (InventoryItems newItem, BarkContext db) => @@ -81,14 +81,19 @@ app.MapPost("/inventory", async (InventoryItems newItem, BarkContext db) => app.MapDelete("/inventory/{id}", async (int id, BarkContext db) => { var item = await db.Inventory.FindAsync(id); - if (item == null) { + if (item == null) + { return Results.NotFound(new { Message = "Inventory item not found" }); } + db.Inventory.Remove(item); await db.SaveChangesAsync(); return Results.Ok(new { Message = "Inventory item deleted successfully" }); }); +app.MapGet("/itemstatus", async (BarkContext db) => + await db.ItemStatus.ToListAsync()); + using (var serviceScope = app.Services.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService(); @@ -97,4 +102,4 @@ using (var serviceScope = app.Services.CreateScope()) app.UseCors(allowSpecificOrigins); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/barkmanAPI/barkDbModel.cs b/barkmanAPI/barkDbModel.cs index 88b538c..03c98d6 100644 --- a/barkmanAPI/barkDbModel.cs +++ b/barkmanAPI/barkDbModel.cs @@ -5,6 +5,7 @@ namespace barkmanapi; public class BarkContext(DbContextOptions options) : DbContext(options) { public DbSet Inventory { get; set; } + public DbSet ItemStatus { get; set; } } public class InventoryItems @@ -17,4 +18,10 @@ public class InventoryItems public float? RentalPrice { get; set; } public float? ReplacementCost { get; set; } public string? Notes { get; set; } +} + +public class ItemStatus +{ + public string Id { get; set; } + public string Name { get; set; } } \ No newline at end of file