70 lines
2.7 KiB
PHP
70 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Models\Branch;
|
|
use App\Http\Responses\ApiResponse;
|
|
/**
|
|
* @OA\Tag(
|
|
* name="Branch",
|
|
* description="分店包廂"
|
|
* )
|
|
*/
|
|
class BranchControlController extends Controller
|
|
{
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/branches",
|
|
* tags={"Branch"},
|
|
* summary="取得分店資訊",
|
|
* description="需帶入 Bearer Token 取得當前用戶可存取的分店資訊",
|
|
* operationId="Branches",
|
|
* security={{ "sanctum": {} }},
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="成功回傳分店列表",
|
|
* @OA\JsonContent(
|
|
* @OA\Property(property="branches", type="array", @OA\Items(
|
|
* @OA\Property(property="id", type="integer", example=1),
|
|
* @OA\Property(property="branch_name", type="string", example="測試"),
|
|
* @OA\Property(property="enable", type="boolean", example=true),
|
|
* @OA\Property(
|
|
* property="rooms",
|
|
* type="array",
|
|
* @OA\Items(
|
|
* @OA\Property(property="room_name", type="string", example="pc101"),
|
|
* @OA\Property(property="is_online", type="boolean", example=true),
|
|
* @OA\Property(property="status", ref="#/components/schemas/RoomStatus"),
|
|
* @OA\Property(property="started_at", type="string", format="date-time", example="2025-06-04 10:00:00Z"),
|
|
* @OA\Property(property="ended_at", type="string", format="date-time", example="2025-06-04 12:00:00Z")
|
|
* )
|
|
* )
|
|
* ))
|
|
* )
|
|
* ),
|
|
* )
|
|
*/
|
|
public function Branches(Request $request): JsonResponse
|
|
{
|
|
$branches = Branch::with('rooms')->get()->map(function ($branch) {
|
|
return [
|
|
'id' => $branch->id,
|
|
'branch_name' => $branch->name,
|
|
'enable' => $branch->enable,
|
|
'rooms' => $branch->rooms->map(function ($room) {
|
|
return [
|
|
'room_name' => $room->type.$room->name,
|
|
'is_online' => $room->is_online,
|
|
'status' => $room->status,
|
|
'started_at' => $room->started_at,
|
|
'ended_at' => $room->ended_at,
|
|
];
|
|
}),
|
|
];
|
|
});
|
|
return ApiResponse::success(['branches' => $branches]);
|
|
}
|
|
} |