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);
|
||||
|
||||
@@ -2,14 +2,35 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\ConfigVariable;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use App\Repository\ConfigVariableRepository;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class ConfigVariableController extends AbstractController
|
||||
{
|
||||
#[Route('/api/config', name: 'app_config_variable')]
|
||||
/**
|
||||
* Get All config variables.
|
||||
*/
|
||||
#[Route('/api/config', name: 'app_config_allVariable', methods: ["GET"])]
|
||||
#[OA\Tag(name: "Config")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns all public config variables.',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(ref: new Model(type: ConfigVariable::class))
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
public function getAllVariables(ConfigVariableRepository $repo): Response
|
||||
{
|
||||
$varList = $repo->findAllVariables();
|
||||
@@ -17,7 +38,22 @@ class ConfigVariableController extends AbstractController
|
||||
return $this->json(['results' => $varList]);
|
||||
}
|
||||
|
||||
#[Route('/api/config/section', name: 'app_config_sections')]
|
||||
#[Route('/api/config/section', name: 'app_config_sections', methods: ["GET"])]
|
||||
#[OA\Tag(name: "Config")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns all public config sections.',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(type: "string")
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
public function getSections(ConfigVariableRepository $repo): Response
|
||||
{
|
||||
$sectionList = $repo->getAllSections();
|
||||
@@ -30,7 +66,28 @@ class ConfigVariableController extends AbstractController
|
||||
return $this->json(['results' => $returnList]);
|
||||
}
|
||||
|
||||
#[Route('/api/config/section/{section}', name: 'app_config_variableBySection')]
|
||||
#[Route('/api/config/section/{section}', name: 'app_config_variableBySection', methods: ["GET"])]
|
||||
#[OA\Tag(name: "Config")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns all public config variables for given section.',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(ref: new Model(type: ConfigVariable::class))
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
#[OA\Parameter(
|
||||
name: 'section',
|
||||
in: 'path',
|
||||
description: 'Config section.',
|
||||
schema: new OA\Schema(type: 'string')
|
||||
)]
|
||||
public function getVariablesBySection(ConfigVariableRepository $repo, string $section): Response
|
||||
{
|
||||
if(\is_null($section) || $section == '') {
|
||||
@@ -42,7 +99,22 @@ class ConfigVariableController extends AbstractController
|
||||
return $this->json(['results' => $varList]);
|
||||
}
|
||||
|
||||
#[Route('/api/config/var/{key}', name: 'app_config_variable')]
|
||||
#[Route('/api/config/var/{key}', name: 'app_config_variable', methods: ["GET"])]
|
||||
#[OA\Tag(name: "Config")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Get config variable by key.',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: ConfigVariable::class),
|
||||
)
|
||||
)]
|
||||
#[OA\Parameter(
|
||||
name: 'key',
|
||||
in: 'path',
|
||||
description: 'Variable key.',
|
||||
schema: new OA\Schema(type: 'string')
|
||||
)]
|
||||
public function getByKey(ConfigVariableRepository $repo, string $key): Response
|
||||
{
|
||||
$var = $repo->findVariableByKey($key);
|
||||
|
||||
@@ -7,16 +7,36 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use App\Entity\RoomCategory;
|
||||
use App\Entity\RoomCategoryPhoto;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use OpenApi\Annotations\Property;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Serializer\Context\Normalizer\ObjectNormalizerContextBuilder;
|
||||
use OpenApi\Attributes as OA;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class RoomCategoryController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/api/room/category', name: 'app_room_AllCategories')]
|
||||
/**
|
||||
* Get All room categories.
|
||||
*/
|
||||
#[Route('/api/room/category', name: 'app_room_AllCategories', methods: ["GET"])]
|
||||
#[OA\Tag(name: "Rooms")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns all room categories',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(ref: new Model(type: RoomCategory::class))
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
public function getAll(RoomCategoryRepository $catRepo): Response
|
||||
{
|
||||
$catList = $catRepo->findAll();
|
||||
@@ -24,7 +44,24 @@ class RoomCategoryController extends AbstractController
|
||||
return $this->json(["results" => $catList]);
|
||||
}
|
||||
|
||||
#[Route('/api/room/category/{id}', name: 'app_room_category')]
|
||||
/**
|
||||
* Get a room category by ID.
|
||||
*/
|
||||
#[Route('/api/room/category/{id}', name: 'app_room_category', methods: ["GET"])]
|
||||
#[OA\Tag(name: "Rooms")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Returns a room category',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: RoomCategory::class),
|
||||
)
|
||||
)]
|
||||
#[OA\Parameter(
|
||||
name: 'id',
|
||||
in: 'path',
|
||||
description: 'RoomCategory ID',
|
||||
)]
|
||||
public function getById(RoomCategory $category): Response
|
||||
{
|
||||
return $this->json($category);
|
||||
|
||||
@@ -5,15 +5,51 @@ namespace App\Controller;
|
||||
use App\Repository\FareTableRepository;
|
||||
use App\Repository\RoomAvailabilityRepository;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use App\Request\SearchAvailabilityPeriodRequest;
|
||||
use App\Response\SearchAvailabilityResponse;
|
||||
use App\Request\SearchFareCategoryRequest;
|
||||
use App\Response\SearchFareCategoryResponse;
|
||||
use App\Service\PricesService;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchRoomsController extends AbstractController
|
||||
{
|
||||
#[Route('/api/search/availability', name: 'app_search_availability')]
|
||||
/**
|
||||
* Get availability for all rooms on period.
|
||||
* For each room, the minimal availability will be returned.
|
||||
*/
|
||||
#[Route('/api/search/availability', name: 'app_search_availability', methods: ["POST"])]
|
||||
#[OA\Tag(name: "Searchs")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Each room available',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(ref: new Model(type: SearchAvailabilityResponse::class))
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
#[OA\RequestBody(
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "filter",
|
||||
ref: new Model(type: SearchAvailabilityPeriodRequest::class),
|
||||
),
|
||||
],
|
||||
)
|
||||
)]
|
||||
public function getAvailabilityForPeriod(Request $request, RoomAvailabilityRepository $repoAvailability): Response
|
||||
{
|
||||
$payload = $request->toArray();
|
||||
@@ -30,7 +66,12 @@ class SearchRoomsController extends AbstractController
|
||||
return $this->json(["results" => $rs]);
|
||||
}
|
||||
|
||||
#[Route('/api/search/availabilityDetails', name: 'app_search_availabilityDetails')]
|
||||
/**
|
||||
* Get Availability for all rooms on each day of a period.
|
||||
* (Not used on Front-end APP)
|
||||
*/
|
||||
#[Route('/api/search/availabilityDetails', name: 'app_search_availabilityDetails', methods: ["POST"])]
|
||||
#[OA\Tag(name: "Searchs")]
|
||||
public function getAvailabilityForPeriodDetails(Request $request, RoomAvailabilityRepository $repoAvailability): Response
|
||||
{
|
||||
$payload = $request->toArray();
|
||||
@@ -44,10 +85,41 @@ class SearchRoomsController extends AbstractController
|
||||
|
||||
$rs = $repoAvailability->getAvailabilityForPeriodDetails($startDate, $endDate);
|
||||
|
||||
return $this->json($rs);
|
||||
return $this->json(["results" => $rs]);
|
||||
}
|
||||
|
||||
#[Route('/api/search/fares', name: 'app_search_faresForCategory')]
|
||||
/**
|
||||
* Get room category price for given period.
|
||||
* Returns price for a room category.
|
||||
* This price is the total for all the selected days by guest number.
|
||||
*/
|
||||
#[Route('/api/search/fares', name: 'app_search_faresForCategory', methods: ["POST"])]
|
||||
#[OA\Tag(name: "Searchs")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: 'Room price by guest number',
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(ref: new Model(type: SearchFareCategoryResponse::class))
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
#[OA\RequestBody(
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "filter",
|
||||
ref: new Model(type: SearchFareCategoryRequest::class),
|
||||
),
|
||||
],
|
||||
)
|
||||
)]
|
||||
public function getFaresForCategoryOnPeriod(Request $request, RoomCategoryRepository $repoCat, PricesService $priceService): Response
|
||||
{
|
||||
$payload = $request->toArray();
|
||||
@@ -73,13 +145,13 @@ class SearchRoomsController extends AbstractController
|
||||
$fareList = $priceService->getFinalPricesForSearch($roomCategory, $startDate, $endDate);
|
||||
$rs = [];
|
||||
foreach ($fareList as $key => $value) {
|
||||
$rs[] = [ "guestNumber" => $key, "price" => $value];
|
||||
$rs[] = ["guestNumber" => $key, "price" => $value];
|
||||
}
|
||||
|
||||
return $this->json(["results" => $rs]);
|
||||
}
|
||||
|
||||
#[Route('/search/debug', name: 'app_search_faresDebug')]
|
||||
#[Route('/debug/search', name: 'app_search_faresDebug')]
|
||||
public function faresDebug(Request $request, PricesService $priceService, FareTableRepository $repoFareTable, RoomCategoryRepository $repoCat): Response
|
||||
{
|
||||
$fareTable[] = $repoFareTable->find(1);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use App\Entity\BookingCustomer;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class BookingCreateRequest
|
||||
{
|
||||
#[OA\Property(description: 'Booking Arrival date')]
|
||||
public \DateTime $arrivalDate;
|
||||
|
||||
#[OA\Property(description: 'Booking departure date')]
|
||||
public \DateTime $departureDate;
|
||||
|
||||
#[OA\Property(
|
||||
description: 'Booking customer details',
|
||||
)]
|
||||
public BookingCustomer $customerDetails;
|
||||
|
||||
/**
|
||||
* @var array<BookingCreateRoomItem>
|
||||
*/
|
||||
#[OA\Property(
|
||||
description: 'Rooms to book',
|
||||
)]
|
||||
public array $rooms;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class BookingCreateRoomItem
|
||||
{
|
||||
#[OA\Property(description: 'Room category ID')]
|
||||
public string $roomCategory;
|
||||
|
||||
#[OA\Property(description: 'Guest number for the room')]
|
||||
public int $guestNumber;
|
||||
|
||||
#[OA\Property(description: 'Room amount')]
|
||||
public int $amount;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class BookingDetailsRequest
|
||||
{
|
||||
#[OA\Property(description: 'Booking reference number')]
|
||||
public string $refNumber;
|
||||
|
||||
#[OA\Property(maxLength: 255, description: 'Email associated to the booking')]
|
||||
public string $email;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchAvailabilityPeriodRequest
|
||||
{
|
||||
#[OA\Property(description: 'Period start date')]
|
||||
public \DateTime $startDate;
|
||||
|
||||
#[OA\Property(description: 'Period end date')]
|
||||
public \DateTime $endDate;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchFareCategoryRequest
|
||||
{
|
||||
#[OA\Property(description: 'Room category ID')]
|
||||
public int $roomCategory;
|
||||
|
||||
#[OA\Property(description: 'Period start date')]
|
||||
public \DateTime $startDate;
|
||||
|
||||
#[OA\Property(description: 'Period end date')]
|
||||
public \DateTime $endDate;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class BookingCreateResponse
|
||||
{
|
||||
#[OA\Property(description: 'Booking reference number')]
|
||||
public string $refNumber;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchAvailabilityResponse
|
||||
{
|
||||
#[OA\Property(description: 'Room category ID')]
|
||||
public string $roomCategory;
|
||||
|
||||
#[OA\Property(description: 'Number of available rooms')]
|
||||
public int $availability;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchFareCategoryResponse
|
||||
{
|
||||
#[OA\Property(description: 'Number of guests')]
|
||||
public int $guestNumber;
|
||||
|
||||
#[OA\Property(description: 'room price')]
|
||||
public int $price;
|
||||
}
|
||||
Reference in New Issue
Block a user