28 lines
643 B
PHP
28 lines
643 B
PHP
<?php
|
|
|
|
namespace App\Services\CafeBazaar;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class BazaarResponse
|
|
{
|
|
public function __construct(
|
|
public readonly int $status,
|
|
public readonly array $body,
|
|
) {}
|
|
|
|
public function successful(): bool
|
|
{
|
|
return $this->status >= 200 && $this->status < 300;
|
|
}
|
|
|
|
public function toJsonResponse(): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'data' => $this->successful() ? $this->body : null,
|
|
'error' => $this->successful() ? null : $this->body,
|
|
'meta' => ['bazaar_status' => $this->status],
|
|
], $this->status);
|
|
}
|
|
}
|