mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
Installs Scribe for (mostly) automatic API documentation. Does a pretty good job and it's pretty painless to set-up. I'll have to configure it to work in the CI and to ensure that the static files are being pushed to production as they should be, but this is a good start.
40 lines
908 B
PHP
40 lines
908 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
trait ApiResponses
|
|
{
|
|
/**
|
|
* Return a success JSON response.
|
|
*/
|
|
protected function success(string $message, ?array $data = []): JsonResponse
|
|
{
|
|
return $this->baseResponse(message: $message, data: $data, code: 200);
|
|
}
|
|
|
|
/**
|
|
* The base response.
|
|
*/
|
|
private function baseResponse(?string $message = '', ?array $data = [], ?int $code = 200): JsonResponse
|
|
{
|
|
$response = [];
|
|
$response['message'] = $message;
|
|
if ($data) {
|
|
$response['data'] = $data;
|
|
}
|
|
$response['status'] = $code;
|
|
|
|
return response()->json($response, $code);
|
|
}
|
|
|
|
/**
|
|
* Return an error JSON response.
|
|
*/
|
|
protected function error(string $message, int $code): JsonResponse
|
|
{
|
|
return $this->baseResponse(message: $message, code: $code);
|
|
}
|
|
}
|