Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/Http/Controllers/Api/V1/ShiftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
}
}
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: 'null' is not a valid OpenAPI 3.0 schema type, so this schema becomes invalid. Model the nullable Shift by marking the $ref as nullable: true or using an allowed type.

Prompt for AI agents
Address the following comment on swagger.yaml at line 2001:

<comment>`type: &#39;null&#39;` is not a valid OpenAPI 3.0 schema type, so this schema becomes invalid. Model the nullable Shift by marking the `$ref` as `nullable: true` or using an allowed type.</comment>

<file context>
@@ -1909,6 +1909,108 @@ paths:
+                  data:
+                    oneOf:
+                      - $ref: &#39;#/components/schemas/Shift&#39;
+                      - type: &#39;null&#39;
+                    nullable: true
+                  message:
</file context>
Fix with Cubic

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:
Expand Down