Sessions: Sidebar, Session-Wechsel, Archivieren-Button, alles session-bezogen
This commit is contained in:
1 parent
8ddee38032
commit
25f07caf83
15 files changed
+442
-78
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Gott.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Gott.Endpoints;
|
||||
|
||||
public static class SessionEndpoint
|
||||
{
|
||||
public static void MapSessionEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
app.MapGet("/api/sessions", HandleList);
|
||||
app.MapPost("/api/sessions", HandleCreate);
|
||||
app.MapPut("/api/sessions/{sessionId}", HandleUpdate);
|
||||
}
|
||||
|
||||
private static async Task HandleList(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var sessions = await db.GetSessions();
|
||||
await ctx.Response.WriteAsJsonAsync(sessions);
|
||||
}
|
||||
|
||||
private static async Task HandleCreate(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var session = await db.CreateSession("Neue Session");
|
||||
await ctx.Response.WriteAsJsonAsync(session);
|
||||
}
|
||||
|
||||
private static async Task HandleUpdate(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var sessionId = ctx.Request.RouteValues["sessionId"]?.ToString();
|
||||
if (string.IsNullOrEmpty(sessionId))
|
||||
{
|
||||
ctx.Response.StatusCode = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
var body = await JsonSerializer.DeserializeAsync<JsonElement>(ctx.Request.Body);
|
||||
if (body.TryGetProperty("name", out var nameEl))
|
||||
{
|
||||
await db.UpdateSessionName(sessionId, nameEl.GetString());
|
||||
}
|
||||
|
||||
var session = await db.GetSession(sessionId);
|
||||
await ctx.Response.WriteAsJsonAsync(session);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user