- POST /v1/in/stats/daily: 기간별 일별 통계 - POST /v1/in/stats/summary: 대시보드 요약 통계 - POST /v1/in/stats/message: 메시지별 발송 통계 - POST /v1/in/stats/hourly: 시간대별 발송 추이 - POST /v1/in/stats/device: 디바이스 분포 통계 - IDailyStatRepository, DailyStatRepository 신규 - IPushSendLogRepository 통계 메서드 확장 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
3.0 KiB
C#
74 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using SPMS.Application.DTOs.Stats;
|
|
using SPMS.Application.Interfaces;
|
|
using SPMS.Domain.Common;
|
|
|
|
namespace SPMS.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("v1/in/stats")]
|
|
[ApiExplorerSettings(GroupName = "stats")]
|
|
public class StatsController : ControllerBase
|
|
{
|
|
private readonly IStatsService _statsService;
|
|
|
|
public StatsController(IStatsService statsService)
|
|
{
|
|
_statsService = statsService;
|
|
}
|
|
|
|
[HttpPost("daily")]
|
|
[SwaggerOperation(Summary = "일별 통계 조회", Description = "기간별 일별 발송/성공/실패/열람 통계를 조회합니다.")]
|
|
public async Task<IActionResult> GetDailyAsync([FromBody] DailyStatRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _statsService.GetDailyAsync(serviceId, request);
|
|
return Ok(ApiResponse<DailyStatResponseDto>.Success(result, "조회 성공"));
|
|
}
|
|
|
|
[HttpPost("summary")]
|
|
[SwaggerOperation(Summary = "요약 통계 조회", Description = "대시보드 요약 통계를 조회합니다.")]
|
|
public async Task<IActionResult> GetSummaryAsync()
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _statsService.GetSummaryAsync(serviceId);
|
|
return Ok(ApiResponse<SummaryStatResponseDto>.Success(result, "조회 성공"));
|
|
}
|
|
|
|
[HttpPost("message")]
|
|
[SwaggerOperation(Summary = "메시지별 통계 조회", Description = "특정 메시지의 발송 통계를 조회합니다.")]
|
|
public async Task<IActionResult> GetMessageStatAsync([FromBody] MessageStatRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _statsService.GetMessageStatAsync(serviceId, request);
|
|
return Ok(ApiResponse<MessageStatResponseDto>.Success(result, "조회 성공"));
|
|
}
|
|
|
|
[HttpPost("hourly")]
|
|
[SwaggerOperation(Summary = "시간대별 통계 조회", Description = "시간대별 발송 추이를 조회합니다.")]
|
|
public async Task<IActionResult> GetHourlyAsync([FromBody] HourlyStatRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _statsService.GetHourlyAsync(serviceId, request);
|
|
return Ok(ApiResponse<HourlyStatResponseDto>.Success(result, "조회 성공"));
|
|
}
|
|
|
|
[HttpPost("device")]
|
|
[SwaggerOperation(Summary = "디바이스 통계 조회", Description = "플랫폼/모델별 디바이스 분포를 조회합니다.")]
|
|
public async Task<IActionResult> GetDeviceStatAsync()
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _statsService.GetDeviceStatAsync(serviceId);
|
|
return Ok(ApiResponse<DeviceStatResponseDto>.Success(result, "조회 성공"));
|
|
}
|
|
|
|
private long GetServiceId()
|
|
{
|
|
if (HttpContext.Items.TryGetValue("ServiceId", out var serviceIdObj) && serviceIdObj is long serviceId)
|
|
return serviceId;
|
|
|
|
throw new Domain.Exceptions.SpmsException(ErrorCodes.BadRequest, "서비스 식별 정보가 없습니다.", 400);
|
|
}
|
|
}
|