KTVCentral/app/Http/Responses/ApiResponse.php
allen.yan 7c8c3fe69b DB 滙入
User 介面 只能看資料不能做修改
Role 介面移除
Branch介面 只能看資料不能做修改
Room 介面 可操控 包廂開關台
Sqgger API 可操控API
Room 有操控異動記錄
machine_statuses 需做資料留存需留7 天
20250528
2025-05-28 09:24:03 +08:00

39 lines
1.2 KiB
PHP

<?php
namespace App\Http\Responses;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
/**
* @OA\Schema(
* schema="ApiResponse",
* type="object",
* @OA\Property(property="code", type="string", example="OK"),
* @OA\Property(property="message", type="string", example="Success"),
* @OA\Property(property="data", type="object", nullable=true)
* )
*/
class ApiResponse
{
public static function success($data = null, string $message = 'Success', string $code = 'OK', int $status = Response::HTTP_OK): JsonResponse
{
return self::respond($code, $message, $data, $status);
}
public static function error(string $message = 'Error', string $code = 'ERROR', int $status = Response::HTTP_BAD_REQUEST): JsonResponse
{
return self::respond($code, $message, null, $status);
}
public static function unauthorized(string $message = 'Unauthorized'): JsonResponse
{
return self::error($message, 'UNAUTHORIZED', Response::HTTP_UNAUTHORIZED);
}
private static function respond(string $code, string $message, $data, int $status): JsonResponse
{
return response()->json(['code' => $code,'message' => $message,'data' => $data,], $status);
}
}