49 lines
1.9 KiB
C#
49 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Threading.Tasks;
|
|
using Webshop.Application.DTOs.Admin;
|
|
using Webshop.Application.Services.Admin.Interfaces;
|
|
using Webshop.Application; // Hinzugefügt
|
|
|
|
namespace Webshop.Api.Controllers.Admin
|
|
{
|
|
/// <summary>
|
|
/// Stellt aggregierte Analysedaten für das Admin-Dashboard bereit.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/v1/admin/[controller]")]
|
|
[Authorize(Roles = "Admin")]
|
|
public class AdminAnalyticsController : ControllerBase
|
|
{
|
|
private readonly IAdminAnalyticsService _analyticsService;
|
|
|
|
public AdminAnalyticsController(IAdminAnalyticsService analyticsService)
|
|
{
|
|
_analyticsService = analyticsService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ruft die aggregierten Analysedaten und KPIs für den Admin-Bereich ab.
|
|
/// </summary>
|
|
/// <param name="period">Der Zeitraum für die Statistiken (Last7Days, Last30Days, AllTime). Standard ist Last30Days.</param>
|
|
/// <response code="200">Gibt die Analysedaten zurück.</response>
|
|
/// <response code="500">Tritt auf, wenn ein interner Serverfehler beim Abrufen der Daten auftritt.</response>
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(AnalyticsDto), 200)]
|
|
[ProducesResponseType(typeof(object), 500)]
|
|
public async Task<IActionResult> GetAnalytics([FromQuery] AnalyticsPeriod period = AnalyticsPeriod.Last30Days)
|
|
{
|
|
var result = await _analyticsService.GetAnalyticsAsync(period);
|
|
|
|
return result.Type switch
|
|
{
|
|
ServiceResultType.Success => Ok(result.Value),
|
|
|
|
ServiceResultType.Failure => StatusCode(500, new { message = result.ErrorMessage }),
|
|
|
|
// Fallback für unerwartete Fehlertypen
|
|
_ => StatusCode(500, new { message = "Ein unerwarteter Fehler ist aufgetreten." })
|
|
};
|
|
}
|
|
}
|
|
} |