...
This commit is contained in:
@@ -114,4 +114,67 @@ app.MapGraphQL();
|
||||
|
||||
app.MapGet("/", () => "Chrono CCG GraphQL API");
|
||||
|
||||
// REST Endpoints for Decks
|
||||
app.MapGet("/api/decks", async (AppDbContext db) =>
|
||||
{
|
||||
var decks = await db.UserDecks.OrderByDescending(d => d.UpdatedAt).ToListAsync();
|
||||
return Results.Ok(decks);
|
||||
});
|
||||
|
||||
app.MapGet("/api/decks/{id:guid}", async (AppDbContext db, Guid id) =>
|
||||
{
|
||||
var deck = await db.UserDecks.FindAsync(id);
|
||||
return deck != null ? Results.Ok(deck) : Results.NotFound();
|
||||
});
|
||||
|
||||
app.MapPost("/api/decks", async (AppDbContext db, UserDeck input) =>
|
||||
{
|
||||
var existing = await db.UserDecks.FindAsync(input.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
input.UpdatedAt = DateTime.UtcNow;
|
||||
db.UserDecks.Add(input);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(input);
|
||||
}
|
||||
existing.Name = input.Name;
|
||||
existing.Cards = input.Cards ?? [];
|
||||
existing.Divers = input.Divers ?? [];
|
||||
existing.Notes = input.Notes;
|
||||
existing.Season = input.Season;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(existing);
|
||||
});
|
||||
|
||||
app.MapDelete("/api/decks/{id:guid}", async (AppDbContext db, Guid id) =>
|
||||
{
|
||||
var existing = await db.UserDecks.FindAsync(id);
|
||||
if (existing != null)
|
||||
{
|
||||
db.UserDecks.Remove(existing);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(new { success = true });
|
||||
}
|
||||
return Results.NotFound();
|
||||
});
|
||||
|
||||
// Authentication endpoints
|
||||
app.MapPost("/api/auth/dev-login", async (AppDbContext db, ITokenService tokenService, HttpContext httpContext) =>
|
||||
{
|
||||
var user = await db.Users.FirstOrDefaultAsync(u => u.Username == "testuser");
|
||||
if (user == null)
|
||||
{
|
||||
user = new User { Username = "testuser", Password = "password123", CreatedAt = DateTime.UtcNow };
|
||||
db.Users.Add(user);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
var token = tokenService.GenerateToken(user.Username);
|
||||
httpContext.Response.Cookies.Append("chrono_auth_token", token, new CookieOptions { Path = "/", SameSite = SameSiteMode.Lax });
|
||||
httpContext.Response.Cookies.Append("chrono_auth_user", user.Username, new CookieOptions { Path = "/", SameSite = SameSiteMode.Lax });
|
||||
return Results.Ok(new { success = true, token, username = user.Username });
|
||||
});
|
||||
|
||||
app.MapDelete("/api/auth/credentials", () => Results.Ok(new { success = true }));
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user