chore: init project

This commit is contained in:
cesnimda
2026-06-30 15:53:32 +02:00
commit f43ef5f945
94 changed files with 4405 additions and 0 deletions
@@ -0,0 +1,53 @@
using InboxIntel.Application.Abstractions;
using InboxIntel.Domain.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace InboxIntel.Api.Controllers;
public record WidgetLayoutDto(string WidgetKey, int X, int Y, int W, int H, bool Visible, int SortOrder, string? SettingsJson);
/// <summary>Persists the user's draggable/resizable dashboard layout.</summary>
public class WidgetLayoutController : ApiControllerBase
{
private readonly IAppDbContext _db;
public WidgetLayoutController(IAppDbContext db) => _db = db;
[HttpGet]
public async Task<IActionResult> Get(CancellationToken ct)
{
var layouts = await _db.WidgetLayouts
.Where(w => w.UserId == UserId)
.OrderBy(w => w.SortOrder)
.Select(w => new WidgetLayoutDto(w.WidgetKey, w.X, w.Y, w.W, w.H, w.Visible, w.SortOrder, w.SettingsJson))
.ToListAsync(ct);
return Ok(layouts);
}
/// <summary>Upserts the full layout for the user (replace semantics).</summary>
[HttpPut]
public async Task<IActionResult> Save([FromBody] List<WidgetLayoutDto> layout, CancellationToken ct)
{
var existing = await _db.WidgetLayouts.Where(w => w.UserId == UserId).ToListAsync(ct);
var byKey = existing.ToDictionary(w => w.WidgetKey);
foreach (var dto in layout)
{
if (byKey.TryGetValue(dto.WidgetKey, out var w))
{
w.X = dto.X; w.Y = dto.Y; w.W = dto.W; w.H = dto.H;
w.Visible = dto.Visible; w.SortOrder = dto.SortOrder; w.SettingsJson = dto.SettingsJson;
}
else
{
_db.WidgetLayouts.Add(new WidgetLayout
{
UserId = UserId, WidgetKey = dto.WidgetKey, X = dto.X, Y = dto.Y, W = dto.W, H = dto.H,
Visible = dto.Visible, SortOrder = dto.SortOrder, SettingsJson = dto.SettingsJson
});
}
}
await _db.SaveChangesAsync(ct);
return NoContent();
}
}