feat: Implement a customizable dashboard with user preferences and a dynamic widget system.
This commit is contained in:
77
src/backend/Zentral.API/Controllers/DashboardController.cs
Normal file
77
src/backend/Zentral.API/Controllers/DashboardController.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Zentral.Domain.Entities;
|
||||
using Zentral.Infrastructure.Data;
|
||||
|
||||
namespace Zentral.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DashboardController : ControllerBase
|
||||
{
|
||||
private readonly ZentralDbContext _context;
|
||||
|
||||
public DashboardController(ZentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet("preference")]
|
||||
public async Task<ActionResult<DashboardPreferenceDto>> GetPreference()
|
||||
{
|
||||
// TODO: Implement proper user identification
|
||||
// For now, we'll use the first active user or a specific test user
|
||||
var user = await _context.Utenti.FirstOrDefaultAsync(u => u.Attivo);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound("No active user found");
|
||||
}
|
||||
|
||||
var preference = await _context.UserDashboardPreferences
|
||||
.FirstOrDefaultAsync(p => p.UtenteId == user.Id);
|
||||
|
||||
if (preference == null)
|
||||
{
|
||||
return Ok(new DashboardPreferenceDto { LayoutJson = "[]" });
|
||||
}
|
||||
|
||||
return Ok(new DashboardPreferenceDto { LayoutJson = preference.LayoutJson });
|
||||
}
|
||||
|
||||
[HttpPost("preference")]
|
||||
public async Task<ActionResult> SavePreference([FromBody] DashboardPreferenceDto dto)
|
||||
{
|
||||
// TODO: Implement proper user identification
|
||||
var user = await _context.Utenti.FirstOrDefaultAsync(u => u.Attivo);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound("No active user found");
|
||||
}
|
||||
|
||||
var preference = await _context.UserDashboardPreferences
|
||||
.FirstOrDefaultAsync(p => p.UtenteId == user.Id);
|
||||
|
||||
if (preference == null)
|
||||
{
|
||||
preference = new UserDashboardPreference
|
||||
{
|
||||
UtenteId = user.Id,
|
||||
LayoutJson = dto.LayoutJson
|
||||
};
|
||||
_context.UserDashboardPreferences.Add(preference);
|
||||
}
|
||||
else
|
||||
{
|
||||
preference.LayoutJson = dto.LayoutJson;
|
||||
preference.UpdatedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
public class DashboardPreferenceDto
|
||||
{
|
||||
public string LayoutJson { get; set; } = "[]";
|
||||
}
|
||||
Reference in New Issue
Block a user