This commit is contained in:
6d486f49
2026-08-17 01:13:48 -04:00
parent 1d6207fbfe
commit ffaab59585
26 changed files with 3133 additions and 105 deletions
-1
View File
@@ -1,4 +1,3 @@
using API.Models;
using Microsoft.EntityFrameworkCore;
using Model;
-12
View File
@@ -1,12 +0,0 @@
namespace API.Models;
public class UserDeck
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; } = "";
public List<string> Cards { get; set; } = [];
public List<string> Divers { get; set; } = [];
public string? Notes { get; set; }
public string? Season { get; set; }
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}
+63
View File
@@ -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();