analytics
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminAnalyticsController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
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
|
||||
{
|
||||
@@ -26,11 +26,24 @@ namespace Webshop.Api.Controllers.Admin
|
||||
/// 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]
|
||||
public async Task<ActionResult<AnalyticsDto>> GetAnalytics([FromQuery] AnalyticsPeriod period = AnalyticsPeriod.Last30Days)
|
||||
[ProducesResponseType(typeof(AnalyticsDto), 200)]
|
||||
[ProducesResponseType(typeof(object), 500)]
|
||||
public async Task<IActionResult> GetAnalytics([FromQuery] AnalyticsPeriod period = AnalyticsPeriod.Last30Days)
|
||||
{
|
||||
var stats = await _analyticsService.GetAnalyticsAsync(period);
|
||||
return Ok(stats);
|
||||
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." })
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user