Switch to PostgreSQL and update database configuration

This commit is contained in:
2025-01-21 19:41:18 -06:00
parent 4f76a08ca3
commit 364c7d83e2
7 changed files with 13 additions and 173 deletions
+5 -1
View File
@@ -1,3 +1,4 @@
using barkmanapi;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
@@ -20,6 +21,9 @@ builder.Services.AddCors(options =>
policy.WithOrigins("https://barkdev.ts.drewr.io", "http://localhost:5173").AllowAnyMethod().AllowAnyHeader();
});
});
builder.Services.AddDbContext<BarkContext>(opt =>
opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")).UseSnakeCaseNamingConvention());
var app = builder.Build();
if (!app.Environment.IsProduction())
@@ -34,7 +38,7 @@ if (!app.Environment.IsProduction())
app.MapGet("/", () => "Hello World!");
app.MapGet("/inventory", async (BarkContext db) =>
await db.Inventory.ToListAsync());
await db.Inventory.OrderBy(item=>item.Id).ToListAsync());
app.MapGet("/inventory/{id}", async (int id, BarkContext db) =>
{