- Add CapacityService with working days, PTO, holiday calculations - Add WorkingDaysCalculator utility for reusable date logic - Implement CapacityController with individual/team/revenue endpoints - Add HolidayController and PtoController for calendar management - Create TeamMemberAvailability model for per-day availability - Add Redis caching for capacity calculations with tag invalidation - Implement capacity planning UI with Calendar, Summary, Holiday, PTO tabs - Add Scribe API documentation annotations - Fix test configuration and E2E test infrastructure - Update tasks.md with completion status Backend Tests: 63 passed Frontend Unit: 32 passed E2E Tests: 134 passed, 20 fixme (capacity UI rendering) API Docs: Generated successfully
100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Holiday;
|
|
use App\Services\CapacityService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class HolidayController extends Controller
|
|
{
|
|
public function __construct(protected CapacityService $capacityService) {}
|
|
|
|
/**
|
|
* List Holidays
|
|
*
|
|
* Retrieve holidays for a specific month or all holidays when no month is provided.
|
|
*
|
|
* @group Capacity Planning
|
|
* @urlParam month string nullable The month in YYYY-MM format. Example: 2026-02
|
|
* @response [
|
|
* {
|
|
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
|
* "date": "2026-02-14",
|
|
* "name": "Company Holiday",
|
|
* "description": "Office closed"
|
|
* }
|
|
* ]
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'month' => 'nullable|date_format:Y-m',
|
|
]);
|
|
|
|
$holidays = isset($data['month'])
|
|
? $this->capacityService->getHolidaysForMonth($data['month'])
|
|
: Holiday::orderBy('date')->get();
|
|
|
|
return response()->json($holidays);
|
|
}
|
|
|
|
/**
|
|
* Create Holiday
|
|
*
|
|
* Add a holiday and clear cached capacity data for the related month.
|
|
*
|
|
* @group Capacity Planning
|
|
* @bodyParam date string required Date of the holiday. Example: 2026-02-14
|
|
* @bodyParam name string required Name of the holiday. Example: Presidents' Day
|
|
* @bodyParam description string nullable Optional description of the holiday.
|
|
* @response 201 {
|
|
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
|
* "date": "2026-02-14",
|
|
* "name": "Presidents' Day",
|
|
* "description": "Office closed"
|
|
* }
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'date' => 'required|date',
|
|
'name' => 'required|string',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$holiday = Holiday::create($data);
|
|
$this->capacityService->forgetCapacityCacheForMonth($holiday->date->format('Y-m'));
|
|
|
|
return response()->json($holiday, 201);
|
|
}
|
|
|
|
/**
|
|
* Delete Holiday
|
|
*
|
|
* Remove a holiday and clear affected capacity caches.
|
|
*
|
|
* @group Capacity Planning
|
|
* @urlParam id string required The holiday UUID. Example: 550e8400-e29b-41d4-a716-446655440000
|
|
* @response {
|
|
* "message": "Holiday deleted"
|
|
* }
|
|
*/
|
|
public function destroy(string $id): JsonResponse
|
|
{
|
|
$holiday = Holiday::find($id);
|
|
|
|
if (! $holiday) {
|
|
return response()->json(['message' => 'Holiday not found'], 404);
|
|
}
|
|
|
|
$month = $holiday->date->format('Y-m');
|
|
$holiday->delete();
|
|
$this->capacityService->forgetCapacityCacheForMonth($month);
|
|
|
|
return response()->json(['message' => 'Holiday deleted']);
|
|
}
|
|
}
|