diff --git a/app/Http/Controllers/Api/V1/ShiftController.php b/app/Http/Controllers/Api/V1/ShiftController.php index 48b4631..307f8b1 100644 --- a/app/Http/Controllers/Api/V1/ShiftController.php +++ b/app/Http/Controllers/Api/V1/ShiftController.php @@ -103,4 +103,63 @@ public function statistics(Request $request) ] ]); } + + /** + * Get shifts for the authenticated user + */ + public function my(Request $request) + { + $user = $request->user(); + $perPage = (int) $request->query('per_page', '15'); + $status = $request->query('status'); + $dateFrom = $request->query('date_from'); + $dateTo = $request->query('date_to'); + + $query = Shift::with(['user', 'dealership', 'replacement']) + ->where('user_id', $user->id); + + if ($status) { + $query->where('status', $status); + } + + if ($dateFrom) { + $query->where('shift_start', '>=', Carbon::parse($dateFrom)->startOfDay()); + } + + if ($dateTo) { + $query->where('shift_start', '<=', Carbon::parse($dateTo)->endOfDay()); + } + + $shifts = $query->orderByDesc('shift_start')->paginate($perPage); + + return response()->json($shifts); + } + + /** + * Get the current active shift for the authenticated user + */ + public function myCurrent(Request $request) + { + $user = $request->user(); + + $shift = Shift::with(['user', 'dealership', 'replacement']) + ->where('user_id', $user->id) + ->where('status', 'open') + ->whereNull('shift_end') + ->orderByDesc('shift_start') + ->first(); + + if (!$shift) { + return response()->json([ + 'success' => true, + 'data' => null, + 'message' => 'No active shift found' + ], 200); + } + + return response()->json([ + 'success' => true, + 'data' => $shift + ]); + } } diff --git a/routes/api.php b/routes/api.php index 0a399a5..d2c0f1c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -75,6 +75,8 @@ Route::get('/shifts', [ShiftController::class, 'index']); Route::get('/shifts/current', [ShiftController::class, 'current']); Route::get('/shifts/statistics', [ShiftController::class, 'statistics']); + Route::get('/shifts/my', [ShiftController::class, 'my']); + Route::get('/shifts/my/current', [ShiftController::class, 'myCurrent']); Route::get('/shifts/{id}', [ShiftController::class, 'show']); // Tasks diff --git a/swagger.yaml b/swagger.yaml index f2b4ae4..30686ee 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -1909,6 +1909,108 @@ paths: schema: $ref: '#/components/schemas/Error' + /shifts/my: + get: + tags: + - Shifts + summary: Получить смены текущего пользователя + description: Получение списка смен для аутентифицированного пользователя с пагинацией и фильтрацией + operationId: getMyShifts + security: + - bearerAuth: [] + parameters: + - name: per_page + in: query + description: Количество элементов на странице + schema: + type: integer + default: 15 + example: 20 + - name: page + in: query + description: Номер страницы + schema: + type: integer + default: 1 + example: 1 + - name: status + in: query + description: Фильтр по статусу + schema: + type: string + enum: [open, closed] + example: open + - name: date_from + in: query + description: Фильтр по начальной дате + schema: + type: string + format: date + example: "2025-10-01" + - name: date_to + in: query + description: Фильтр по конечной дате + schema: + type: string + format: date + example: "2025-10-31" + responses: + '200': + description: Список смен пользователя + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/PaginatedResponse' + - type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/Shift' + '401': + description: Неавторизован + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + /shifts/my/current: + get: + tags: + - Shifts + summary: Получить текущую открытую смену пользователя + description: Получение текущей активной смены аутентифицированного пользователя + operationId: getMyCurrentShift + security: + - bearerAuth: [] + responses: + '200': + description: Текущая смена пользователя + content: + application/json: + schema: + type: object + properties: + success: + type: boolean + example: true + data: + oneOf: + - $ref: '#/components/schemas/Shift' + - type: 'null' + nullable: true + message: + type: string + nullable: true + example: No active shift found + '401': + description: Неавторизован + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /tasks: get: tags: