mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
created item status db
This commit is contained in:
@@ -0,0 +1,91 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Brand")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("brand");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("name");
|
||||||
|
|
||||||
|
b.Property<string>("Notes")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("notes");
|
||||||
|
|
||||||
|
b.Property<float?>("RentalPrice")
|
||||||
|
.HasColumnType("real")
|
||||||
|
.HasColumnName("rental_price");
|
||||||
|
|
||||||
|
b.Property<float?>("ReplacementCost")
|
||||||
|
.HasColumnType("real")
|
||||||
|
.HasColumnName("replacement_cost");
|
||||||
|
|
||||||
|
b.Property<string>("SerialNumber")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("serial_number");
|
||||||
|
|
||||||
|
b.Property<string>("Status")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("status");
|
||||||
|
|
||||||
|
b.HasKey("Id")
|
||||||
|
.HasName("pk_inventory");
|
||||||
|
|
||||||
|
b.ToTable("inventory", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("barkmanapi.ItemStatus", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("name");
|
||||||
|
|
||||||
|
b.HasKey("Id")
|
||||||
|
.HasName("pk_item_status");
|
||||||
|
|
||||||
|
b.ToTable("item_status", (string)null);
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace barkmanapi.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class status : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "item_status",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id = table.Column<string>(type: "text", nullable: false),
|
||||||
|
name = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("pk_item_status", x => x.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "item_status");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,23 @@ namespace barkmanapi.Migrations
|
|||||||
|
|
||||||
b.ToTable("inventory", (string)null);
|
b.ToTable("inventory", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("barkmanapi.ItemStatus", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("name");
|
||||||
|
|
||||||
|
b.HasKey("Id")
|
||||||
|
.HasName("pk_item_status");
|
||||||
|
|
||||||
|
b.ToTable("item_status", (string)null);
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-10
@@ -10,15 +10,17 @@ builder.Services.AddDbContext<BarkContext>();
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(c =>
|
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 =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy(name: allowSpecificOrigins,
|
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<BarkContext>(opt =>
|
builder.Services.AddDbContext<BarkContext>(opt =>
|
||||||
@@ -29,16 +31,13 @@ var app = builder.Build();
|
|||||||
if (!app.Environment.IsProduction())
|
if (!app.Environment.IsProduction())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(c =>
|
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bark Productions API V1"); });
|
||||||
{
|
|
||||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bark Inventory API V1");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.MapGet("/", () => "Hello World!");
|
app.MapGet("/", () => "Hello World!");
|
||||||
|
|
||||||
app.MapGet("/inventory", async (BarkContext db) =>
|
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) =>
|
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.NotFound(new { Message = "Inventory item not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
return Results.Ok(item);
|
return Results.Ok(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ app.MapPut("/inventory/{id}", async (int id, InventoryItems updatedItem, BarkCon
|
|||||||
|
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return Results.Ok(existingItem);
|
return Results.Ok(existingItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.MapPost("/inventory", async (InventoryItems newItem, BarkContext db) =>
|
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) =>
|
app.MapDelete("/inventory/{id}", async (int id, BarkContext db) =>
|
||||||
{
|
{
|
||||||
var item = await db.Inventory.FindAsync(id);
|
var item = await db.Inventory.FindAsync(id);
|
||||||
if (item == null) {
|
if (item == null)
|
||||||
|
{
|
||||||
return Results.NotFound(new { Message = "Inventory item not found" });
|
return Results.NotFound(new { Message = "Inventory item not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Inventory.Remove(item);
|
db.Inventory.Remove(item);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return Results.Ok(new { Message = "Inventory item deleted successfully" });
|
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())
|
using (var serviceScope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();
|
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace barkmanapi;
|
|||||||
public class BarkContext(DbContextOptions<BarkContext> options) : DbContext(options)
|
public class BarkContext(DbContextOptions<BarkContext> options) : DbContext(options)
|
||||||
{
|
{
|
||||||
public DbSet<InventoryItems> Inventory { get; set; }
|
public DbSet<InventoryItems> Inventory { get; set; }
|
||||||
|
public DbSet<ItemStatus> ItemStatus { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InventoryItems
|
public class InventoryItems
|
||||||
@@ -18,3 +19,9 @@ public class InventoryItems
|
|||||||
public float? ReplacementCost { get; set; }
|
public float? ReplacementCost { get; set; }
|
||||||
public string? Notes { get; set; }
|
public string? Notes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ItemStatus
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user