using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using TaxBaik.Application.Services; namespace TaxBaik.Web.Controllers; /// /// 관리자 대시보드 API /// SOLID: Single Responsibility - 대시보드 데이터만 담당 /// [ApiController] [Route("api/[controller]")] [Authorize] public class AdminDashboardController : ControllerBase { private readonly AdminDashboardService _dashboardService; private readonly TaxFilingService _taxFilingService; public AdminDashboardController( AdminDashboardService dashboardService, TaxFilingService taxFilingService) { _dashboardService = dashboardService; _taxFilingService = taxFilingService; } /// /// 대시보드 요약 정보 조회 /// GET /api/admin-dashboard/summary /// [HttpGet("summary")] public async Task GetSummary() { try { var summary = await _dashboardService.GetSummaryAsync(); return Ok(summary); } catch (Exception ex) { return StatusCode(500, new ProblemDetails { Title = "대시보드 요약 조회 실패", Detail = ex.Message, Status = StatusCodes.Status500InternalServerError }); } } /// /// 30일 이내 마감 임박 신고 조회 /// GET /api/admin-dashboard/upcoming-filings?days=30 /// [HttpGet("upcoming-filings")] public async Task GetUpcomingFilings([FromQuery] int days = 30) { try { if (days <= 0) days = 30; var filings = await _taxFilingService.GetUpcomingAsync(days); return Ok(new { data = filings, days }); } catch (Exception ex) { return StatusCode(500, new ProblemDetails { Title = "마감 임박 신고 조회 실패", Detail = ex.Message, Status = StatusCodes.Status500InternalServerError }); } } /// /// 최근 문의 조회 /// GET /api/admin-dashboard/recent-inquiries?limit=10 /// [HttpGet("recent-inquiries")] public async Task GetRecentInquiries([FromQuery] int limit = 10) { try { if (limit <= 0) limit = 10; if (limit > 100) limit = 100; // 보안: 최대 100개 var inquiries = await _dashboardService.GetRecentInquiriesAsync(limit); return Ok(new { data = inquiries, limit }); } catch (Exception ex) { return StatusCode(500, new ProblemDetails { Title = "최근 문의 조회 실패", Detail = ex.Message, Status = StatusCodes.Status500InternalServerError }); } } /// /// 월별 통계 /// GET /api/admin-dashboard/monthly-stats?month=2026-06 /// [HttpGet("monthly-stats")] public async Task GetMonthlyStats([FromQuery] string? month = null) { try { var stats = await _dashboardService.GetMonthlyStatsAsync(month); return Ok(stats); } catch (Exception ex) { return StatusCode(500, new ProblemDetails { Title = "월별 통계 조회 실패", Detail = ex.Message, Status = StatusCodes.Status500InternalServerError }); } } }