feat: Settings in Datenbank speichern statt localStorage
- Neue Spalte 'settings' in users-Tabelle (Migration via TryAddColumn) - SettingsEndpoint: GET/PUT /api/settings - DatabaseService: GetUserSettings() + UpdateUserSettings() - Frontend: currentSettings als globaler State in app.js - settings-page.js: localStorage komplett entfernt, nutzt API - Settings werden beim App-Start aus DB geladen und angewendet
This commit is contained in:
1 parent
aac10901fa
commit
a0752ea492
8 files changed
+102
-43
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using System.Text.Json;
|
||||
using Gott.Extensions;
|
||||
using Gott.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Gott.Endpoints;
|
||||
|
||||
public static class SettingsEndpoint
|
||||
{
|
||||
public static void MapSettingsEndpoints(this WebApplication app)
|
||||
{
|
||||
app.MapGet("/api/settings", HandleGet);
|
||||
app.MapPut("/api/settings", HandleUpdate);
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task HandleGet(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var userId = ctx.GetUserId();
|
||||
var json = await db.GetUserSettings(userId);
|
||||
ctx.Response.ContentType = "application/json";
|
||||
await ctx.Response.WriteAsync(json ?? "{}");
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task HandleUpdate(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var userId = ctx.GetUserId();
|
||||
var body = await JsonSerializer.DeserializeAsync<JsonElement>(ctx.Request.Body);
|
||||
var json = body.ToString();
|
||||
await db.UpdateUserSettings(userId, json);
|
||||
ctx.Response.ContentType = "application/json";
|
||||
await ctx.Response.WriteAsync(json);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user