API 加入 分店資訊 20250604
This commit is contained in:
parent
dbb675e7a3
commit
1da2e215fb
@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Models\User;
|
||||
use OpenApi\Annotations as OA;
|
||||
use App\Http\Responses\ApiResponse;
|
||||
|
||||
/**
|
||||
* @OA\Tag(
|
||||
@ -72,7 +73,7 @@ class AuthController extends Controller
|
||||
} else {
|
||||
$token = $user->api_plain_token;
|
||||
}
|
||||
return \App\Http\Responses\ApiResponse::success(['token' => $token]);
|
||||
return ApiResponse::success(['token' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,6 +118,6 @@ class AuthController extends Controller
|
||||
*/
|
||||
public function profile(Request $request)
|
||||
{
|
||||
return \App\Http\Responses\ApiResponse::success($request->user());
|
||||
return ApiResponse::success($request->user());
|
||||
}
|
||||
}
|
||||
|
70
app/Http/Controllers/BranchControlController.php
Normal file
70
app/Http/Controllers/BranchControlController.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
@ -16,7 +16,11 @@ class Branch extends Model
|
||||
'external_ip',
|
||||
'enable',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'name' => 'string',
|
||||
'external_ip'=> 'string',
|
||||
'enable' => 'boolean',
|
||||
];
|
||||
public function rooms() {
|
||||
return $this->hasMany(Room::class);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\ArtistController;
|
||||
use App\Http\Controllers\AuthController;
|
||||
use App\Http\Controllers\BranchControlController;
|
||||
use App\Http\Controllers\RoomControlController;
|
||||
|
||||
Route::get('/artists/search', [App\Http\Controllers\ArtistController::class, 'search'])->name('api.artists.search');
|
||||
@ -12,6 +13,7 @@ Route::post('/room/receiveRegister', [RoomControlController::class, 'receiveRegi
|
||||
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::get('/profile', [AuthController::class, 'profile']);
|
||||
Route::get('/branches',[BranchControlController::class, 'Branches']);
|
||||
Route::post('/room/sendSwitch', [RoomControlController::class, 'sendSwitch']);
|
||||
Route::post('/room/receiveSwitch', [RoomControlController::class, 'receiveSwitch']);
|
||||
Route::post('/room/heartbeat', [RoomControlController::class, 'StatusReport']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user