feat: sam_stat P2 도메인 + 통계 API + 대시보드 전환 (Phase 4)
- 4.1: stat_project_monthly + ProjectStatService (건설/프로젝트 월간) - 4.2: stat_system_daily + SystemStatService (API/감사/FCM/파일/결재) - 4.3: stat_events, stat_snapshots + StatEventService + StatEventObserver - 4.4: StatController (summary/daily/monthly/alerts) + StatQueryService + FormRequest 3개 + routes/stats.php - 4.5: DashboardService sam_stat 우선 조회 + 원본 DB 폴백 패턴 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
64
app/Http/Controllers/Api/V1/StatController.php
Normal file
64
app/Http/Controllers/Api/V1/StatController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Stat\StatAlertRequest;
|
||||
use App\Http\Requests\V1\Stat\StatDailyRequest;
|
||||
use App\Http\Requests\V1\Stat\StatMonthlyRequest;
|
||||
use App\Services\Stats\StatQueryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly StatQueryService $statQueryService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 대시보드 요약 통계 (sam_stat 기반)
|
||||
*/
|
||||
public function summary(): JsonResponse
|
||||
{
|
||||
$data = $this->statQueryService->getDashboardSummary();
|
||||
|
||||
return ApiResponse::handle(['data' => $data], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 일간 통계 조회
|
||||
*/
|
||||
public function daily(StatDailyRequest $request): JsonResponse
|
||||
{
|
||||
$data = $this->statQueryService->getDailyStat(
|
||||
$request->validated('domain'),
|
||||
$request->validated()
|
||||
);
|
||||
|
||||
return ApiResponse::handle(['data' => $data], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 월간 통계 조회
|
||||
*/
|
||||
public function monthly(StatMonthlyRequest $request): JsonResponse
|
||||
{
|
||||
$data = $this->statQueryService->getMonthlyStat(
|
||||
$request->validated('domain'),
|
||||
$request->validated()
|
||||
);
|
||||
|
||||
return ApiResponse::handle(['data' => $data], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 목록 조회
|
||||
*/
|
||||
public function alerts(StatAlertRequest $request): JsonResponse
|
||||
{
|
||||
$data = $this->statQueryService->getAlerts($request->validated());
|
||||
|
||||
return ApiResponse::handle(['data' => $data], __('message.fetched'));
|
||||
}
|
||||
}
|
||||
21
app/Http/Requests/V1/Stat/StatAlertRequest.php
Normal file
21
app/Http/Requests/V1/Stat/StatAlertRequest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V1\Stat;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StatAlertRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'limit' => 'nullable|integer|min:1|max:100',
|
||||
'unread_only' => 'nullable|boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Requests/V1/Stat/StatDailyRequest.php
Normal file
22
app/Http/Requests/V1/Stat/StatDailyRequest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V1\Stat;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StatDailyRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'domain' => 'required|string|in:sales,finance,production,inventory,quote,hr,system',
|
||||
'start_date' => 'required|date|date_format:Y-m-d',
|
||||
'end_date' => 'required|date|date_format:Y-m-d|after_or_equal:start_date',
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Requests/V1/Stat/StatMonthlyRequest.php
Normal file
22
app/Http/Requests/V1/Stat/StatMonthlyRequest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V1\Stat;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StatMonthlyRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'domain' => 'required|string|in:sales,finance,production,project',
|
||||
'year' => 'required|integer|min:2020|max:2099',
|
||||
'month' => 'nullable|integer|min:1|max:12',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user