Compare commits
4
Commits
a495be6bb2
...
d9489f2558
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9489f2558 | ||
|
|
e93a5ff3a9 | ||
|
|
69bc2630fd | ||
|
|
bad9c6ea51 |
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 96 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-bed"><path d="M2 4v16"/><path d="M2 8h18a2 2 0 0 1 2 2v10"/><path d="M2 17h20"/><path d="M6 8v9"/></svg>
|
||||
|
After Width: | Height: | Size: 306 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-bug-off"><path d="M15 7.13V6a3 3 0 0 0-5.14-2.1L8 2"/><path d="M14.12 3.88 16 2"/><path d="M22 13h-4v-2a4 4 0 0 0-4-4h-1.3"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="m2 2 20 20"/><path d="M7.7 7.7A4 4 0 0 0 6 11v3a6 6 0 0 0 11.13 3.13"/><path d="M12 20v-8"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/></svg>
|
||||
|
After Width: | Height: | Size: 530 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check"><path d="M20 6 9 17l-5-5"/></svg>
|
||||
|
After Width: | Height: | Size: 242 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-coffee"><path d="M10 2v2"/><path d="M14 2v2"/><path d="M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"/><path d="M6 2v2"/></svg>
|
||||
|
After Width: | Height: | Size: 371 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
|
||||
|
After Width: | Height: | Size: 255 B |
@@ -0,0 +1,48 @@
|
||||
:root {
|
||||
--main-border-radius: 5pt;
|
||||
}
|
||||
|
||||
|
||||
.container {
|
||||
margin: 1em auto;
|
||||
max-width: 800px;
|
||||
width: 75%;
|
||||
padding: 10px;
|
||||
border-radius: var(--main-border-radius);
|
||||
border: 1px solid #dad9d9;
|
||||
box-shadow: 2px 2px 4px #dad9d9;
|
||||
background-color: #F5F5F5;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
position: relative;
|
||||
margin-block: 10px;
|
||||
padding-block: 8px;
|
||||
margin-inline: auto;
|
||||
width: 80%;
|
||||
|
||||
border: 1px solid #dad9d9;
|
||||
border-radius: var(--main-border-radius);
|
||||
}
|
||||
|
||||
.msg-container {
|
||||
max-width: 70%;
|
||||
margin-inline: auto;
|
||||
|
||||
padding-block: 5px;
|
||||
padding-inline: 8px;
|
||||
|
||||
border-radius: var(--main-border-radius);
|
||||
border: 1px solid #dad9d9;
|
||||
}
|
||||
|
||||
.msg-error {
|
||||
background-color: rgba(164, 0, 0, 0.5);
|
||||
border-color: rgba(87, 0, 0, 0.75);
|
||||
}
|
||||
|
||||
.msg-warn {
|
||||
background-color: rgba(255, 234, 6, 0.5);
|
||||
border-color: rgba(204, 187, 0, 0.75);
|
||||
}
|
||||
@@ -35,6 +35,7 @@ security:
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/admin, roles: ROLE_ADMIN }
|
||||
- { path: ^/debug, roles: ROLE_SUPERADMIN }
|
||||
# - { path: ^/profile, roles: ROLE_USER }
|
||||
|
||||
when@test:
|
||||
|
||||
@@ -23,7 +23,7 @@ class BookingCrudController extends AbstractCrudController
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
$fieldRefNumber = TextField::new ('refNumber');
|
||||
$fieldBookingTime = DateTimeField::new ('BookingTime');
|
||||
$fieldBookingTime = DateTimeField::new('bookingTime');
|
||||
if ($pageName == Crud::PAGE_EDIT) {
|
||||
$fieldRefNumber->setDisabled(true);
|
||||
$fieldBookingTime->setDisabled(true);
|
||||
@@ -33,8 +33,8 @@ class BookingCrudController extends AbstractCrudController
|
||||
yield $fieldRefNumber;
|
||||
yield $fieldBookingTime;
|
||||
|
||||
yield DateField::new ('ArrivalDate');
|
||||
yield DateField::new ('DepartureDate');
|
||||
yield DateField::new('arrivalDate');
|
||||
yield DateField::new('departureDate');
|
||||
|
||||
yield AssociationField::new ('bookingCustomer')->renderAsEmbeddedForm(BookingCustomerCrudController::class);
|
||||
yield CollectionField::new ('bookingRooms')->useEntryCrudForm();
|
||||
|
||||
@@ -17,9 +17,9 @@ class BookingCustomerCrudController extends AbstractCrudController
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield TextField::new('Name');
|
||||
yield TextField::new('Surname');
|
||||
yield TextField::new('Email');
|
||||
yield TextField::new('PhoneNumber');
|
||||
yield TextField::new('name');
|
||||
yield TextField::new('surname');
|
||||
yield TextField::new('email');
|
||||
yield TextField::new('phoneNumber');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ class BookingRoomCrudController extends AbstractCrudController
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield AssociationField::new ('RoomCategory')->setCrudController(RoomCategoryCrudController::class);
|
||||
yield NumberField::new ('GuestNumber');
|
||||
yield MoneyField::new ('RoomPrice')->setCurrency("EUR");
|
||||
yield NumberField::new ('Amount');
|
||||
yield AssociationField::new('roomCategory')->setCrudController(RoomCategoryCrudController::class);
|
||||
yield NumberField::new('guestNumber');
|
||||
yield MoneyField::new('roomPrice')->setCurrency("EUR");
|
||||
yield NumberField::new('amount');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\DTO\AppSetupConfig;
|
||||
use App\DTO\ExampleDataConfig;
|
||||
use App\Entity\ConfigVariable;
|
||||
use App\Form\AppSetupFormType;
|
||||
use App\Form\ExampleDataFormType;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use App\Service\AppSetupService;
|
||||
use App\Service\ExampleDataService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class AppSetupController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/setup', name: 'app_setup_setup')]
|
||||
public function addAdmin(
|
||||
AppSetupService $setupService,
|
||||
Request $request,
|
||||
EntityManagerInterface $entityManager
|
||||
): Response {
|
||||
|
||||
$configRepo = $entityManager->getRepository(ConfigVariable::class);
|
||||
$setupStatus = $configRepo->findBy(["key" => "SETUP_STATUS"]);
|
||||
|
||||
if ($setupStatus != null && $setupStatus[0] != null && $setupStatus[0]->getValue() == 1) {
|
||||
return $this->GoToResultPage(
|
||||
isError: false,
|
||||
message: "SomniaRooms already setup.",
|
||||
linkRoute: "admin",
|
||||
linkLabel: "Go to admin panel"
|
||||
);
|
||||
}
|
||||
|
||||
$config = new AppSetupConfig();
|
||||
$form = $this->createForm(AppSetupFormType::class, $config);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
$rs = $setupService->InitialSetup($config);
|
||||
|
||||
if (!$rs) {
|
||||
return $this->GoToResultPage(
|
||||
isError: false,
|
||||
message: "An error occurred during setup proccess, try again."
|
||||
);
|
||||
}
|
||||
|
||||
if ($config->getGenExampleData()) {
|
||||
return $this->redirectToRoute("app_setup_gendata");
|
||||
}
|
||||
|
||||
return $this->GoToResultPage(
|
||||
isError: false,
|
||||
message: "SomniaRooms is setup! Go to admin panel to start!",
|
||||
linkRoute: "admin",
|
||||
linkLabel: "Go to admin panel"
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('app_setup/setup.html.twig', [
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
#[Route('/debug/exampleData', name: 'app_setup_gendata')]
|
||||
public function generateData(
|
||||
Request $request,
|
||||
ExampleDataService $dataService,
|
||||
RoomCategoryRepository $roomCategoryRepository
|
||||
): Response {
|
||||
|
||||
$config = new ExampleDataConfig();
|
||||
$form = $this->createForm(ExampleDataFormType::class, $config);
|
||||
$isFormInvalid = $form->isSubmitted() && !$form->isValid();
|
||||
|
||||
//Check for RoomCategories on db.
|
||||
$roomCategoryCount = $roomCategoryRepository->count();
|
||||
$hasRoomCategories = $roomCategoryCount > 0;
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
$rs = $dataService->AddExampleData($config);
|
||||
$isOk = $rs == "OK";
|
||||
$msg = $isOk ? "Example data generated! Go to admin panel to start!" : $rs;
|
||||
|
||||
return $this->GoToResultPage(
|
||||
isError: !$isOk,
|
||||
message: $msg,
|
||||
linkRoute: $isOk ? "admin" : "",
|
||||
linkLabel: $isOk ? "Go to admin panel" : ""
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('app_setup/exampleData.html.twig', [
|
||||
'form' => $form,
|
||||
'isFormInvalid' => $isFormInvalid,
|
||||
'hasRoomCategories' => $hasRoomCategories
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private function GoToResultPage(bool $isError, string $message, string $linkRoute = null, string $linkLabel = null): Response
|
||||
{
|
||||
return $this->render('app_setup/result.html.twig', [
|
||||
'isError' => $isError,
|
||||
'message' => $message,
|
||||
'linkLabel' => $linkLabel,
|
||||
'linkRoute' => $linkRoute
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ 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\Request\SearchPricesForCategoryRequest;
|
||||
use App\Response\SearchPricesForCategoryResponse;
|
||||
use App\Service\PricesService;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -89,7 +89,7 @@ class SearchRoomsController extends AbstractController
|
||||
* 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"], format: "json")]
|
||||
#[Route('/api/search/prices', name: 'app_search_pricesForCategory', methods: ["POST"], format: "json")]
|
||||
#[OA\Tag(name: "Searchs")]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
@@ -100,7 +100,7 @@ class SearchRoomsController extends AbstractController
|
||||
new OA\Property(
|
||||
property: "results",
|
||||
type: "array",
|
||||
items: new OA\Items(ref: new Model(type: SearchFareCategoryResponse::class))
|
||||
items: new OA\Items(ref: new Model(type: SearchPricesForCategoryResponse::class))
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -108,14 +108,14 @@ class SearchRoomsController extends AbstractController
|
||||
#[OA\RequestBody(
|
||||
content: new OA\JsonContent(
|
||||
type: 'object',
|
||||
ref: new Model(type: SearchFareCategoryRequest::class),
|
||||
ref: new Model(type: SearchPricesForCategoryRequest::class),
|
||||
)
|
||||
)]
|
||||
public function getFaresForCategoryOnPeriod(
|
||||
public function getPricesForCategoryOnPeriod(
|
||||
Request $request,
|
||||
RoomCategoryRepository $repoCat,
|
||||
PricesService $priceService,
|
||||
#[MapRequestPayload()] SearchFareCategoryRequest $searchRequest
|
||||
#[MapRequestPayload()] SearchPricesForCategoryRequest $searchRequest
|
||||
): Response {
|
||||
if (\is_null($searchRequest)) {
|
||||
throw new \Exception('Invalid Payload', 400);
|
||||
|
||||
@@ -2,13 +2,8 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\ConfigVariable;
|
||||
use App\Enum\ConfigSectionType;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
@@ -34,53 +29,4 @@ class SecurityController extends AbstractController
|
||||
{
|
||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
||||
}
|
||||
|
||||
#[Route(path: '/setup', name: 'app_security_addAdmin')]
|
||||
public function addAdmin(UserPasswordHasherInterface $passwordHasher, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$configRepo = $entityManager->getRepository(ConfigVariable::class);
|
||||
$setupStatus = $configRepo->findBy(["key" => "SETUP_STATUS"]);
|
||||
|
||||
if($setupStatus != null && $setupStatus[0] != null && $setupStatus[0]->getValue() != 1) {
|
||||
return new Response("Setup was already done");
|
||||
}
|
||||
|
||||
|
||||
$entityManager->beginTransaction();
|
||||
|
||||
try {
|
||||
|
||||
//Create system variables.
|
||||
$var_setup = new ConfigVariable();
|
||||
$var_setup->setKey("SETUP_STATUS");
|
||||
$var_setup->setValue("1");
|
||||
$var_setup->setSection(ConfigSectionType::Internal);
|
||||
$entityManager->persist($var_setup);
|
||||
|
||||
|
||||
//Create user Admin.
|
||||
$user = new User();
|
||||
$user->setUsername("admin");
|
||||
$user->setRoles(["ROLE_USER", "ROLE_ADMIN", "ROLE_SUPERADMIN"]);
|
||||
$plaintextPassword = "admin";
|
||||
|
||||
// hash the password (based on the security.yaml config for the $user class)
|
||||
$hashedPassword = $passwordHasher->hashPassword(
|
||||
$user,
|
||||
$plaintextPassword
|
||||
);
|
||||
$user->setPassword($hashedPassword);
|
||||
|
||||
$entityManager->persist($user);
|
||||
|
||||
$entityManager->flush();
|
||||
$entityManager->commit();
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$entityManager->rollback();
|
||||
throw $th;
|
||||
}
|
||||
|
||||
return new Response("Setup completed :)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO;
|
||||
|
||||
class AppSetupConfig
|
||||
{
|
||||
protected string $adminUser;
|
||||
protected string $adminPass;
|
||||
|
||||
protected bool $genExampleData;
|
||||
|
||||
public function getAdminUser(): string
|
||||
{
|
||||
return $this->adminUser;
|
||||
}
|
||||
|
||||
public function setAdminUser(string $adminUser): void
|
||||
{
|
||||
$this->adminUser = $adminUser;
|
||||
}
|
||||
|
||||
public function getAdminPass(): string
|
||||
{
|
||||
return $this->adminPass;
|
||||
}
|
||||
|
||||
public function setAdminPass(string $adminPass): void
|
||||
{
|
||||
$this->adminPass = $adminPass;
|
||||
}
|
||||
|
||||
public function getGenExampleData(): bool
|
||||
{
|
||||
return $this->genExampleData;
|
||||
}
|
||||
|
||||
public function setGenExampleData(bool $genExampleData): void
|
||||
{
|
||||
$this->genExampleData = $genExampleData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class ExampleDataConfig
|
||||
{
|
||||
protected DateTime $startDate;
|
||||
protected DateTime $endDate;
|
||||
|
||||
protected bool $genRoomCategories;
|
||||
|
||||
protected bool $genFaretables;
|
||||
protected bool $genAvailability;
|
||||
protected string $genMode;
|
||||
|
||||
public const GENMODE_EXAMPLE = "EXAMPLE";
|
||||
public const GENMODE_RANDOM = "RANDOM";
|
||||
|
||||
public function getStartDate(): DateTime
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
public function setStartDate(DateTime $startDate): void
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
}
|
||||
|
||||
public function getEndDate(): DateTime
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function setEndDate(DateTime $endDate): void
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
public function getGenRoomCategories(): bool
|
||||
{
|
||||
return $this->genRoomCategories;
|
||||
}
|
||||
|
||||
public function setGenRoomCategories(bool $genRoomCategories): void
|
||||
{
|
||||
$this->genRoomCategories = $genRoomCategories;
|
||||
}
|
||||
|
||||
public function getGenFaretables(): bool
|
||||
{
|
||||
return $this->genFaretables;
|
||||
}
|
||||
|
||||
public function setGenFaretables(bool $genFaretables): void
|
||||
{
|
||||
$this->genFaretables = $genFaretables;
|
||||
}
|
||||
|
||||
public function getGenAvailability(): bool
|
||||
{
|
||||
return $this->genAvailability;
|
||||
}
|
||||
|
||||
public function setGenAvailability(bool $genAvailability): void
|
||||
{
|
||||
$this->genAvailability = $genAvailability;
|
||||
}
|
||||
|
||||
public function getGenMode(): string
|
||||
{
|
||||
return $this->genMode;
|
||||
}
|
||||
|
||||
public function setGenMode(string $genMode): void
|
||||
{
|
||||
$this->genMode = $genMode;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Enum\UserRoleEnum;
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
@@ -73,7 +74,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
$roles = $this->roles;
|
||||
// guarantee every user at least has ROLE_USER
|
||||
$roles[] = 'ROLE_USER';
|
||||
$roles[] = UserRoleEnum::ROLE_USER->value;
|
||||
|
||||
return array_unique($roles);
|
||||
}
|
||||
@@ -122,6 +123,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
// If you store any temporary, sensitive data on the user, clear it here
|
||||
// $this->plainPassword = null;
|
||||
$this->plainPassword = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
|
||||
enum UserRoleEnum: string
|
||||
{
|
||||
case ROLE_USER = 'ROLE_USER';
|
||||
case ROLE_ADMIN = 'ROLE_ADMIN';
|
||||
case ROLE_SUPERADMIN = 'ROLE_SUPERADMIN';
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\DTO\AppSetupConfig;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AppSetupFormType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('adminUser', TextType::class);
|
||||
$builder->add('adminPass', PasswordType::class);
|
||||
$builder->add('genExampleData', CheckboxType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('setup', SubmitType::class);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AppSetupConfig::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\DTO\ExampleDataConfig;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ExampleDataFormType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('startDate', DateType::class);
|
||||
$builder->add('endDate', DateType::class);
|
||||
|
||||
$builder->add('genRoomCategories', CheckboxType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
$builder->add('genFaretables', CheckboxType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
$builder->add('genAvailability', CheckboxType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
$builder->add('genMode', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Random' => ExampleDataConfig::GENMODE_RANDOM,
|
||||
'Example' => ExampleDataConfig::GENMODE_EXAMPLE
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('Generate', SubmitType::class);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => ExampleDataConfig::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\RoomAvailability;
|
||||
use App\Entity\RoomCategory;
|
||||
use DateInterval;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -129,14 +130,16 @@ class RoomAvailabilityRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* For a given RoomCategory, sets its availability for all days on a period with the given amount.
|
||||
*/
|
||||
public function bulkEditRoomAvailabilityForCategoryOnPeriod(RoomCategory $roomCategory, \DateTimeInterface $startDate, \DateTimeInterface $endDate, int $amount): void
|
||||
public function bulkEditRoomAvailabilityForCategoryOnPeriod(RoomCategory $roomCategory, \DateTimeInterface $startDate, \DateTimeInterface $endDate, int $amount, bool $useTransactions = true): void
|
||||
{
|
||||
$strStartDate = $startDate->format('Y-m-d');
|
||||
$strEndDate = $endDate->format('Y-m-d');
|
||||
$roomCatId = $roomCategory->getId();
|
||||
|
||||
$entityManager = $this->getEntityManager();
|
||||
if ($useTransactions) {
|
||||
$entityManager->beginTransaction();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -144,7 +147,7 @@ class RoomAvailabilityRepository extends ServiceEntityRepository
|
||||
$this->createQueryBuilder('ra')
|
||||
->delete()
|
||||
->andWhere('ra.day >= :startDate')
|
||||
->andWhere('ra.day < :endDate')
|
||||
->andWhere('ra.day <= :endDate')
|
||||
->andWhere('ra.roomCategory = :roomCategory')
|
||||
->setParameter('roomCategory', $roomCatId)
|
||||
->setParameter('startDate', $strStartDate)
|
||||
@@ -154,8 +157,10 @@ class RoomAvailabilityRepository extends ServiceEntityRepository
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
// Include end date.
|
||||
$endDateIncluded = date_add($endDate, new DateInterval("P1D"));
|
||||
//For each day, create item and persist it.
|
||||
$daterange = new \DatePeriod($startDate, new \DateInterval('P1D'), $endDate);
|
||||
$daterange = new \DatePeriod($startDate, new \DateInterval('P1D'), $endDateIncluded);
|
||||
foreach ($daterange as $date) {
|
||||
$item = new RoomAvailability();
|
||||
$item->setRoomCategory($roomCategory);
|
||||
@@ -166,12 +171,15 @@ class RoomAvailabilityRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
$entityManager->commit();
|
||||
|
||||
if ($useTransactions) {
|
||||
$entityManager->commit();
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
if ($useTransactions) {
|
||||
$entityManager->rollback();
|
||||
}
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace App\Request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchFareCategoryRequest
|
||||
class SearchPricesForCategoryRequest
|
||||
{
|
||||
#[OA\Property(description: 'Room category ID')]
|
||||
public int $roomCategory;
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace App\Response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SearchFareCategoryResponse
|
||||
class SearchPricesForCategoryResponse
|
||||
{
|
||||
#[OA\Property(description: 'Number of guests')]
|
||||
public int $guestNumber;
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\DTO\AppSetupConfig;
|
||||
use App\Entity\ConfigVariable;
|
||||
use App\Entity\User;
|
||||
use App\Enum\ConfigSectionType;
|
||||
use App\Enum\UserRoleEnum;
|
||||
use App\Repository\ConfigVariableRepository;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
/**
|
||||
* Service for setup proccess.
|
||||
*/
|
||||
class AppSetupService
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private LoggerInterface $logger,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private ConfigVariableRepository $repoVariables,
|
||||
private UserPasswordHasherInterface $passwordHasher,
|
||||
private Security $security
|
||||
) {}
|
||||
|
||||
public function InitialSetup(AppSetupConfig $configData): bool
|
||||
{
|
||||
$this->entityManager->beginTransaction();
|
||||
$user = new User();
|
||||
|
||||
try {
|
||||
//Create system variables.
|
||||
$this->logger->info("SomniaRooms Setup - Creating system variables...");
|
||||
|
||||
$var_setup = $this->repoVariables->find("SETUP_STATUS");
|
||||
if (!$var_setup) {
|
||||
$var_setup = new ConfigVariable();
|
||||
$var_setup->setKey("SETUP_STATUS");
|
||||
}
|
||||
$var_setup->setValue("1");
|
||||
$var_setup->setSection(ConfigSectionType::Internal);
|
||||
$this->entityManager->persist($var_setup);
|
||||
|
||||
|
||||
//Create user Admin.
|
||||
$this->logger->info("SomniaRooms Setup - Adding super-admin user...");
|
||||
$user->setUsername($configData->getAdminUser());
|
||||
$user->setRoles([UserRoleEnum::ROLE_USER->value, UserRoleEnum::ROLE_ADMIN->value, UserRoleEnum::ROLE_SUPERADMIN->value]);
|
||||
$plaintextPassword = $configData->getAdminPass();
|
||||
|
||||
|
||||
|
||||
// hash the password (based on the security.yaml config for the $user class)
|
||||
$hashedPassword = $this->passwordHasher->hashPassword(
|
||||
$user,
|
||||
$plaintextPassword
|
||||
);
|
||||
$user->setPassword($hashedPassword);
|
||||
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->commit();
|
||||
} catch (\Throwable $th) {
|
||||
$this->entityManager->rollback();
|
||||
throw $th;
|
||||
}
|
||||
|
||||
//If init was sucessfull, log admin user.
|
||||
$this->security->login($user);
|
||||
|
||||
$this->logger->info("SomniaRooms Setup completed!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\DTO\AppSetupConfig;
|
||||
use App\DTO\ExampleDataConfig;
|
||||
use App\Entity\ConfigVariable;
|
||||
use App\Entity\FareTable;
|
||||
use App\Entity\RoomCategory;
|
||||
use App\Entity\RoomFare;
|
||||
use App\Entity\User;
|
||||
use App\Enum\ConfigSectionType;
|
||||
use App\Enum\UserRoleEnum;
|
||||
use App\Repository\ConfigVariableRepository;
|
||||
use App\Repository\FareTableRepository;
|
||||
use App\Repository\RoomAvailabilityRepository;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use App\Repository\RoomFareRepository;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Service for setup proccess.
|
||||
*/
|
||||
class ExampleDataService
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private LoggerInterface $logger,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private RoomCategoryRepository $roomCategoryRepository,
|
||||
private RoomAvailabilityRepository $roomAvailabilityRepository,
|
||||
private FareTableRepository $fareTableRepository,
|
||||
private RoomFareRepository $roomFareRepository,
|
||||
) {}
|
||||
|
||||
public function AddExampleData(ExampleDataConfig $config): string
|
||||
{
|
||||
$genMode = $config->getGenMode();
|
||||
if ($genMode == ExampleDataConfig::GENMODE_EXAMPLE) {
|
||||
return "'Example' generation mode is not supported yet!";
|
||||
}
|
||||
|
||||
$this->entityManager->beginTransaction();
|
||||
|
||||
try {
|
||||
if ($config->getGenRoomCategories()) {
|
||||
$this->GenerateRoomCategories();
|
||||
}
|
||||
if ($config->getGenAvailability()) {
|
||||
$this->GenerateAvailability($config);
|
||||
}
|
||||
if ($config->getGenFaretables()) {
|
||||
$this->GenerateFares($config);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->commit();
|
||||
} catch (\Throwable $th) {
|
||||
$this->entityManager->rollback();
|
||||
throw $th;
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
private function GenerateRoomCategories(): bool
|
||||
{
|
||||
//TODOME.
|
||||
return true;
|
||||
}
|
||||
|
||||
private function GenerateAvailability(ExampleDataConfig $config): bool
|
||||
{
|
||||
$roomCategoryList = $this->roomCategoryRepository->findAll();
|
||||
foreach ($roomCategoryList as $room) {
|
||||
//TODOME: Make amounts configurable.
|
||||
$amount = random_int(0, 7);
|
||||
$this->roomAvailabilityRepository->bulkEditRoomAvailabilityForCategoryOnPeriod(
|
||||
$room,
|
||||
$config->getStartDate(),
|
||||
$config->getEndDate(),
|
||||
$amount,
|
||||
useTransactions: false
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function GenerateFares(ExampleDataConfig $config): bool
|
||||
{
|
||||
$generationTime = new DateTime();
|
||||
$strGenTime = $generationTime->format('d-m-Y H:i:s');
|
||||
|
||||
$roomCategoryList = $this->roomCategoryRepository->findAll();
|
||||
foreach ($roomCategoryList as $room) {
|
||||
$list = $this->fareTableRepository->findFareTable($room->getId(), $config->getStartDate(), $config->getEndDate());
|
||||
if (count($list) > 0) {
|
||||
//TODOME: Log info.
|
||||
continue;
|
||||
}
|
||||
|
||||
$fareTable = new FareTable();
|
||||
$fareTable->setStartDate($config->getStartDate());
|
||||
$fareTable->setEndDate($config->getEndDate());
|
||||
$fareTable->setRoomCategory($room);
|
||||
$fareTable->setComment("Autogenerated " . $strGenTime);
|
||||
|
||||
$this->entityManager->persist($fareTable);
|
||||
|
||||
for ($i = 1; $i < $room->getMaxGuestNum(); $i++) {
|
||||
$roomFare = new RoomFare();
|
||||
$roomFare->setGuestNumber($i);
|
||||
$roomFare->setFareTable($fareTable);
|
||||
|
||||
//TODOME: Make amounts configurable.
|
||||
// Random price per person.
|
||||
$amount = random_int(10, 25) * $i * 100;
|
||||
$roomFare->setFareAmount($amount);
|
||||
|
||||
$this->entityManager->persist($roomFare);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Example Data{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<h1>SomniaRooms - Example data!</h1>
|
||||
|
||||
<p>
|
||||
Add example data to your SomniaRooms.
|
||||
</p>
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
{% if isFormInvalid %}
|
||||
<div class="msg-container msg-error">
|
||||
{{ form_errors(form) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="form-section">
|
||||
<h2>Room Categories</h2>
|
||||
{% if hasRoomCategories %}
|
||||
<div class="msg-container msg-warn">
|
||||
<span>Warning: There are already room categories on the DB. More will be added.</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{{ form_row(form.genRoomCategories) }}
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<h2>Fares and availability</h2>
|
||||
{{ form_row(form.genFaretables) }}
|
||||
{{ form_row(form.genAvailability) }}
|
||||
{{ form_row(form.genMode) }}
|
||||
<br>
|
||||
{{ form_row(form.startDate) }}
|
||||
{{ form_row(form.endDate) }}
|
||||
</div>
|
||||
|
||||
<br>
|
||||
{{ form_rest(form) }}
|
||||
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,24 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Setup!{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<div class="container">
|
||||
<h1>SomniaRooms - Set-Up!</h1>
|
||||
|
||||
{% if isError %}
|
||||
<img src="{{ asset('resources/x.svg') }}" />
|
||||
{% else %}
|
||||
<img src="{{ asset('resources/coffee.svg') }}" />
|
||||
{% endif %}
|
||||
|
||||
|
||||
<p>{{message}}</p>
|
||||
{% if linkRoute and linkLabel %}
|
||||
<a href="{{ path(linkRoute) }}">{{linkLabel}}</a>
|
||||
{% endif %}
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,12 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Setup!{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<h1>SomniaRooms - Set-Up!</h1>
|
||||
|
||||
Setup your SomniaRooms backend application.
|
||||
{{ form(form) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,17 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{% block title %}Welcome!{% endblock %}</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>">
|
||||
<title>{% block title %}Welcome!{% endblock %} - SomniaRooms</title>
|
||||
<link rel="icon" href="{{asset('resources/bed.svg')}}">
|
||||
{% block stylesheets %}
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
{% block importmap %}{{ importmap('app') }}{% endblock %}
|
||||
{% block javascripts %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block body %}{% endblock %}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user