feat: 보고서(Reports) API 구현
- 일일 일보 조회/엑셀 다운로드 API 추가 - 지출 예상 내역서 조회/엑셀 다운로드 API 추가 - ReportService: 전일/당일 잔액 계산, 월별 지출 예상 집계 - Laravel Excel을 이용한 엑셀 내보내기 구현 - Swagger 문서 작성 완료
This commit is contained in:
61
app/Http/Controllers/Api/V1/ReportController.php
Normal file
61
app/Http/Controllers/Api/V1/ReportController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Exports\DailyReportExport;
|
||||
use App\Exports\ExpenseEstimateExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V1\Report\DailyReportRequest;
|
||||
use App\Http\Requests\V1\Report\ExpenseEstimateRequest;
|
||||
use App\Http\Responses\ApiResponse;
|
||||
use App\Services\ReportService;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ReportService $service
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 일일 일보 조회
|
||||
*/
|
||||
public function daily(DailyReportRequest $request)
|
||||
{
|
||||
$report = $this->service->dailyReport($request->validated());
|
||||
|
||||
return ApiResponse::handle(__('message.fetched'), $report);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일일 일보 엑셀 다운로드
|
||||
*/
|
||||
public function dailyExport(DailyReportRequest $request)
|
||||
{
|
||||
$report = $this->service->dailyReport($request->validated());
|
||||
$filename = 'daily_report_'.$report['date'].'.xlsx';
|
||||
|
||||
return Excel::download(new DailyReportExport($report), $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* 지출 예상 내역서 조회
|
||||
*/
|
||||
public function expenseEstimate(ExpenseEstimateRequest $request)
|
||||
{
|
||||
$report = $this->service->expenseEstimate($request->validated());
|
||||
|
||||
return ApiResponse::handle(__('message.fetched'), $report);
|
||||
}
|
||||
|
||||
/**
|
||||
* 지출 예상 내역서 엑셀 다운로드
|
||||
*/
|
||||
public function expenseEstimateExport(ExpenseEstimateRequest $request)
|
||||
{
|
||||
$report = $this->service->expenseEstimate($request->validated());
|
||||
$filename = 'expense_estimate_'.$report['year_month'].'.xlsx';
|
||||
|
||||
return Excel::download(new ExpenseEstimateExport($report), $filename);
|
||||
}
|
||||
}
|
||||
36
app/Http/Requests/V1/Report/DailyReportRequest.php
Normal file
36
app/Http/Requests/V1/Report/DailyReportRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V1\Report;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DailyReportRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'date' => ['nullable', 'date', 'date_format:Y-m-d'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom attribute names
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'date' => __('validation.attributes.date'),
|
||||
];
|
||||
}
|
||||
}
|
||||
46
app/Http/Requests/V1/Report/ExpenseEstimateRequest.php
Normal file
46
app/Http/Requests/V1/Report/ExpenseEstimateRequest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V1\Report;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExpenseEstimateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'year_month' => ['nullable', 'regex:/^\d{4}-\d{2}$/'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom attribute names
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'year_month' => __('validation.attributes.year_month'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation messages
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'year_month.regex' => __('validation.date_format', ['format' => 'YYYY-MM']),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user