- Added Symfony Validation Lib. - Updated API DTOs to include validation constraints.
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Controller;
|
||||
use App\ApiErrorException;
|
||||
use App\DTO\ApiErrorMessage;
|
||||
use App\Entity\Booking;
|
||||
use App\Entity\BookingCustomer;
|
||||
use App\Entity\BookingRoom;
|
||||
use App\Repository\BookingRepository;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
@@ -18,8 +17,6 @@ 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;
|
||||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
|
||||
@@ -51,10 +48,6 @@ class BookingController extends AbstractController
|
||||
#[MapRequestPayload()] BookingDetailsRequest $detailsRequest
|
||||
): JsonResponse {
|
||||
|
||||
if (\is_null($detailsRequest)) {
|
||||
throw new ApiErrorException(new ApiErrorMessage(400, ApiErrorMessage::TYPE_INVALID_REQUEST_BODY_FORMAT));
|
||||
}
|
||||
|
||||
$selectedBooking = $repoBooking->findOneBy(["refNumber" => $detailsRequest->refNumber]);
|
||||
if (\is_null($selectedBooking)) {
|
||||
throw new NotFoundHttpException('Booking not found');
|
||||
@@ -87,18 +80,12 @@ class BookingController extends AbstractController
|
||||
)
|
||||
)]
|
||||
public function newBooking(
|
||||
Request $request,
|
||||
EntityManagerInterface $entityManager,
|
||||
RoomCategoryRepository $repoCat,
|
||||
RoomAvailabilityRepository $repoAvailability,
|
||||
PricesService $priceSrv,
|
||||
#[MapRequestPayload()] BookingCreateRequest $createRequest
|
||||
): JsonResponse {
|
||||
if (\is_null($createRequest)) {
|
||||
throw new ApiErrorException(
|
||||
new ApiErrorMessage(400, ApiErrorMessage::TYPE_INVALID_REQUEST_BODY_FORMAT)
|
||||
);
|
||||
}
|
||||
|
||||
$booking = new Booking();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user