forked from Somnia/SomniaRooms
Added OpenAPI docs using nelmioAPIDocBundle.
This commit is contained in:
@@ -8,17 +8,40 @@ use App\Entity\BookingRoom;
|
||||
use App\Repository\BookingRepository;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use App\Repository\RoomAvailabilityRepository;
|
||||
use App\Request\BookingCreateRequest;
|
||||
use App\Request\BookingDetailsRequest;
|
||||
use App\Response\BookingCreateResponse;
|
||||
use App\Service\PricesService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class BookingController extends AbstractController
|
||||
{
|
||||
#[Route('/api/booking/details', name: 'app_booking_details')]
|
||||
/**
|
||||
* Get booking details
|
||||
*/
|
||||
#[Route('/api/booking/details', name: 'app_booking_details', methods: ["POST"])]
|
||||
#[OA\Tag(name: "Booking")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns booking details',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: Booking::class),
|
||||
)
|
||||
)]
|
||||
#[OA\RequestBody(
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: BookingDetailsRequest::class),
|
||||
)
|
||||
)]
|
||||
public function getBookingDetails(Request $request, BookingRepository $repoBooking): JsonResponse
|
||||
{
|
||||
$payload = $request->toArray();
|
||||
@@ -42,14 +65,32 @@ class BookingController extends AbstractController
|
||||
return $this->json($customerBooking);
|
||||
}
|
||||
|
||||
#[Route('/api/booking/create', name: 'app_booking_create')]
|
||||
/**
|
||||
* Create a new Booking.
|
||||
*/
|
||||
#[Route('/api/booking/create', name: 'app_booking_create', methods: ["POST"])]
|
||||
#[OA\Tag(name: "Booking")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns booking details',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: BookingCreateResponse::class)
|
||||
)
|
||||
)]
|
||||
#[OA\RequestBody(
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: BookingCreateRequest::class),
|
||||
)
|
||||
)]
|
||||
public function newBooking(Request $request, BookingRepository $repoBooking, EntityManagerInterface $entityManager,
|
||||
RoomCategoryRepository $repoCat, RoomAvailabilityRepository $repoAvailability,
|
||||
PricesService $priceSrv): JsonResponse
|
||||
{
|
||||
$payload = $request->toArray();
|
||||
if (\is_null($payload)) {
|
||||
throw new \Exception('Invalid Payload', 400);
|
||||
throw new HttpException('Invalid Payload', 400);
|
||||
}
|
||||
|
||||
|
||||
@@ -136,8 +177,10 @@ class BookingController extends AbstractController
|
||||
}
|
||||
|
||||
if(!$priceFound) {
|
||||
throw new HttpException(500,
|
||||
"No se puedo obtener el precio para la categoría: " . $roommCategory->getId() . " , guests: " . $selecctedGuestAmount);
|
||||
throw new HttpException(
|
||||
500,
|
||||
"No se puedo obtener el precio para la categoría: " . $roomCategory->getId() . " , guests: " . $selectedGuestAmount
|
||||
);
|
||||
}
|
||||
|
||||
$entityManager->persist($room);
|
||||
|
||||
Reference in New Issue
Block a user