Files
sam-api/app/Http/Controllers/Api/V1/CalendarController.php
권혁성 4208ca3010 feat: [HR/기타] 캘린더/배차/설비/재고 + DB 마이그레이션
- 캘린더 CRUD API, 배차차량 관리 API (CRUD + options)
- 배차정보 다중 행 시스템 (shipment_vehicle_dispatches)
- 설비 다중점검주기 + 부 담당자 스키마 추가
- TodayIssue 날짜 기반 조회, Stock/Client 날짜 필터
- i18n 메시지 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 02:59:30 +09:00

107 lines
3.7 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\CalendarService;
use Carbon\Carbon;
use Illuminate\Http\Request;
/**
* CEO 대시보드 캘린더 컨트롤러
*/
class CalendarController extends Controller
{
public function __construct(
private readonly CalendarService $calendarService
) {}
/**
* 캘린더 일정 조회
*
* @param Request $request
* - start_date: 조회 시작일 (Y-m-d, 기본: 이번 달 1일)
* - end_date: 조회 종료일 (Y-m-d, 기본: 이번 달 말일)
* - type: 일정 타입 필터 (schedule|order|construction|null=전체)
* - department_filter: 부서 필터 (all|department|personal, 기본: all)
*/
public function summary(Request $request)
{
$validated = $request->validate([
'start_date' => 'nullable|date_format:Y-m-d',
'end_date' => 'nullable|date_format:Y-m-d|after_or_equal:start_date',
'type' => 'nullable|in:schedule,order,construction,other',
'department_filter' => 'nullable|in:all,department,personal',
]);
// 기본값 설정: 이번 달 전체
$today = Carbon::today();
$startDate = $validated['start_date'] ?? $today->copy()->startOfMonth()->format('Y-m-d');
$endDate = $validated['end_date'] ?? $today->copy()->endOfMonth()->format('Y-m-d');
$type = $validated['type'] ?? null;
$departmentFilter = $validated['department_filter'] ?? 'all';
return ApiResponse::handle(function () use ($startDate, $endDate, $type, $departmentFilter) {
return $this->calendarService->getSchedules(
$startDate,
$endDate,
$type,
$departmentFilter
);
}, __('message.fetched'));
}
/**
* 일정 등록
*/
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required|string|max:200',
'description' => 'nullable|string|max:1000',
'start_date' => 'required|date_format:Y-m-d',
'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date',
'start_time' => 'nullable|date_format:H:i',
'end_time' => 'nullable|date_format:H:i',
'is_all_day' => 'boolean',
'color' => 'nullable|string|max:20',
]);
return ApiResponse::handle(function () use ($validated) {
return $this->calendarService->createSchedule($validated);
}, __('message.created'));
}
/**
* 일정 수정
*/
public function update(Request $request, int $id)
{
$validated = $request->validate([
'title' => 'required|string|max:200',
'description' => 'nullable|string|max:1000',
'start_date' => 'required|date_format:Y-m-d',
'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date',
'start_time' => 'nullable|date_format:H:i',
'end_time' => 'nullable|date_format:H:i',
'is_all_day' => 'boolean',
'color' => 'nullable|string|max:20',
]);
return ApiResponse::handle(function () use ($id, $validated) {
return $this->calendarService->updateSchedule($id, $validated);
}, __('message.updated'));
}
/**
* 일정 삭제
*/
public function destroy(int $id)
{
return ApiResponse::handle(function () use ($id) {
return $this->calendarService->deleteSchedule($id);
}, __('message.deleted'));
}
}