71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\OrderRepositoryInterface;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class OrderController extends Controller
|
|
{
|
|
private OrderRepositoryInterface $orderRepository;
|
|
|
|
public function __construct(OrderRepositoryInterface $orderRepository)
|
|
{
|
|
$this->orderRepository = $orderRepository;
|
|
}
|
|
|
|
public function index(): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'data' => $this->orderRepository->getAllOrders()
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$orderDetails = $request->only([
|
|
'client',
|
|
'details'
|
|
]);
|
|
|
|
return response()->json(
|
|
[
|
|
'data' => $this->orderRepository->createOrder($orderDetails)
|
|
],
|
|
Response::HTTP_CREATED
|
|
);
|
|
}
|
|
|
|
public function show(Request $request): JsonResponse
|
|
{
|
|
$orderId = $request->route('id');
|
|
|
|
return response()->json([
|
|
'data' => $this->orderRepository->getOrderById($orderId)
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request): JsonResponse
|
|
{
|
|
$orderId = $request->route('id');
|
|
$orderDetails = $request->only([
|
|
'client',
|
|
'details'
|
|
]);
|
|
|
|
return response()->json([
|
|
'data' => $this->orderRepository->updateOrder($orderId, $orderDetails)
|
|
]);
|
|
}
|
|
|
|
public function destroy(Request $request): JsonResponse
|
|
{
|
|
$orderId = $request->route('id');
|
|
$this->orderRepository->deleteOrder($orderId);
|
|
|
|
return response()->json(null, Response::HTTP_NO_CONTENT);
|
|
}
|
|
}
|