1. Go to this page and download the library: Download jot/hf-repository library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Repository;
use Jot\HfRepository\Repository;
use Jot\HfShield\Entity\Order\Order as Entity;
class OrderRepository extends Repository
{
protected string $entity = Entity::class;
}
declare(strict_types=1);
namespace App\Controller\V1;
use App\Controller\AbstractController;
use Jot\HfShield\Entity\Order\Order;
use App\Repository\OrderRepository;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Hyperf\RateLimit\Annotation\RateLimit;
use Hyperf\Swagger\Annotation as SA;
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
#[SA\HyperfServer('http')]
#[SA\Tag(
name: 'Order',
description: 'Endpoints related to orders management'
)]
#[SA\Schema(schema: "app.error.response", ation",
in: "query",
in: "query",
new SA\Property(
property: "error",
type: "string",
example: null,
nullable: true
)
],
type: "object"
)
),
new SA\Response(
response: 400,
description: "Bad Request",
content: new SA\JsonContent(ref: "#/components/schemas/app.error.response")
),
new SA\Response(
response: 500,
description: "Application Error",
content: new SA\JsonContent(ref: "#/components/schemas/app.error.response")
)
]
)]
#[RateLimit(create: 10, consume: 1)]
#[GetMapping('orders[/]')]
public function getOrdersList(): PsrResponseInterface
{
$response = $this->repository->paginate($this->request->all());
if ($response['result'] === 'error') {
return $this->response->withStatus(400)->json($response);
}
return $this->response
->withHeader('Access-Control-Allow-Origin', '*')
->json($response);
}
#[SA\Get(
path: "/orders/{id}",
description: "Retrieve the details of a specific orders identified by ID.",
summary: "Get Order Data",
tags: ["Order"],
parameters: [
new SA\Parameter(
name: "id",
description: "Unique identifier of the orders",
in: "path",
s to the system.",
summary: "Create a New Order",
requestBody: new SA\RequestBody(
/schemas/app.error.response")
),
new SA\Response(
response: 404,
description: "Order Not Found",
content: new SA\JsonContent(ref: "#/components/schemas/app.error.response")
),
new SA\Response(
response: 500,
description: "Application Error",
content: new SA\JsonContent(ref: "#/components/schemas/app.error.response")
)
]
)]
#[RateLimit(create: 10, consume: 5)]
#[PutMapping('orders/{id}')]
public function updateOrder(string $id): PsrResponseInterface
{
$entity = new Order(['id' => $id, ...$this->request->all()]);
try {
$response = $this->repository->update($entity);
} catch (\Throwable $e) {
return $this->response->withStatus(400)->json([
'data' => null,
'result' => 'error',
'message' => $e->getMessage()
]);
}
return $this->response->json([
'data' => $response->toArray(),
'result' => 'success',
'message' => null,
]);
}
#[SA\Delete(
path: "/orders/{id}",
description: "Delete an existing orders by its unique identifier.",
summary: "Delete an Order",
tags: ["Order"],
parameters: [
new SA\Parameter(
name: "id",
description: "Unique identifier of the orders",
in: "path",