At a minimum, this solution has two different parts:
- The Frontend
- The Backend / Admin Interface
-
The Frontend: This is a simple html css (in form of blade) in laravel application that:
-
Allows customers / clients to create a booking.
-
The booking create form includes some form fields such as :
- Name (required)
- Booking Date (required) (date-format)
- Flexibility (options below) (required)
- +/- 1 Day
- +/- 2 Days
- +/- 3 Days
- Vehicle Size (options below) (required)
- Small
- Medium
- Large
- Van
- Contact Number (required)
- Email Address (required)
-
When a booking is created by the customer, the system automatically generates a booking id (in form of auto-increment number) which may be useful for the customer when the admin eventually approved the booking. The booking approval email sent to the customer will let the customer know that this specific booking with the id of {id} has been approved.
-
-
The Backend/Admin : The backend is also a laravel application that:
- Gives access to the to authenticate themselves. To do this, please go to the url - (if you are running the project on laravel valet)
https://booking-system.test/admin/login
else if you are using the artisan command to run the project then that should be :https://localhost:{port}/admin/login
. If you come across any issues, please see the Setup & Instruction section for more details about setting up the project. - The admin interface allows a logged-in admin to create booking (possibly on behalf of customer ?).
- Mandating the admin to login. There are default seeders for admins to access the system and that can be found in the users table with any user with role 'admin'. However, there is a defaultAdmin state for the djValentine company with the email :
[email protected]
andpassword
:password
. - Upon logging-in to the system, created bookings can be seen on the admin dashboard or bookings page.
- These bookings are listed in a table with the ability of allowing the admin to modify a booking (edit), Delete a booking or approve a booking.
- It is important to know that deleted bookings are been soft-deleted which means they can be recovered.
- When a booking is approved by the admin, the system notifies the customer via their email address saying that "Dear user, your booking with id {id} has now been approved." The content of this email also include further booking details such as the flexibility, vehicle size, contact number etc.
- Admins can see approved bookings in the navbar section and can create booking using the "Create" button in the navbar section.
- Gives access to the to authenticate themselves. To do this, please go to the url - (if you are running the project on laravel valet)
- Because I like to start with my database schemas, I started with creating the application underlying schemas and database structure. The database tables includes the
bookings
table,flexibilities
table,vehicle_sizes
table,approved_bookings
table and theusers
table. - After then, I followed the TDD approach by having some feature testing in place by testing ability to create booking as a
non-admin
user, creating a booking as an admin user, viewing all bookings as anon-admin
user redirects the user to the log in page with a permission denied error. - There is a middleware responsible for bouncing a
non-admin
user back to the login route/to the home page. This middleware is called "Admin
" and can be found in theMiddleware
folder. All user info are persisted in the users table but what separates a user(customer) from the admin is therole
column in theusers
table. - After completing these tests, I started creating the application logic, controllers, routes and its dedicated actions.
- I used Laravel's form requests to inject the validation into the method and I injected the models repositories into the controllers that depends on these models to work. Forexample the BookingController needs flexibility and vehicle size model to be created. So this is been injected in to the Controller's constructor.
- When a booking is saved, any admin who logs in can see this created booking with its status showing pending by default until the admin approves the booking.
- This implementation uses an action
App\Actions\CreateBooking
,App\Actions\CreateUser
,App\Actions\UpdateBooking
,App\Actions\DeleteBooking
andApp\Actions\ApproveBooking
to implement the business logic. - The repository pattern is also used in querying data from the database.
Before setting up this repository, the following are the dependencies that needs to be available on your machine:
- [Composer] for dependency management.
- [Pest] [https://pestphp.com/docs/installation] for the test suite.
- [HTML], [CSS] and [Blade] for the frontend
- [Laravel] dependencies for the backend test suite.
- PHP (I have PHP 8.1.11 installed on my machine)
- Clone the repository:
git clone https://github.com/deendin/booking-system.git
- Assuming that the Dependencies listed above are satisfied, you can
cd
into the directory calledbooking-system.git
- Run
composer install
to install the project dependencies. When that is done, duplicate the content of.env.example
into a new file called.env
and runphp artisan migrate --seed
to create the database tables and it's seeders. - In the server you can either run
php artisan serve
to start the laravel app or if you have valet setup, you can runvalet link
in this directory and then head tohttps://booking-system.test
to see the application running. - To test, duplicate the contnet of the
.env.test.example
to a new.env.tesing
file, runphp artisan test
, which is expected to run this tests or continue to the next step which describes how to setup the frontend. - Note Incase the test fails with an error "target class [env] not found" then you can run
php artisan optimize
andphp artisan optimize:clear
. and re-run the test suite. Also, the test uses sqlite for the database so this needs to be setup as well.https://flaviocopes.com/sqlite-how-to-install/
- Go to the url
https://booking-system.test
orhttps://localhost:{port}
as the case may be. - You should automatically see the booking create page on the screen
- Fill in this form and create a booking
- Go to
https://booking-system.test/admin/login
to login as an admin with email :[email protected]
andpassword
:password
. - You should be able to see list of existing bookings (created from the seeder we run above) and the new one that's just been created from the frontend.
- You should see three buttons/links at the front of each booking with approval action, delete and edit.
- When you approve a booking, an email is sent to the creator (customer) of that booking with approval message and the booking details with the booking id as stated above so that they can know which of thier bookings got approved incase they have created many bookings in the past.
- Note if you by any chance get an error when approving a booking, then you may need to install an email client forexample I have used
mailhog
to test emails. But this can be setup here:https://jaymeh.co.uk/setting-up-mailhog-on-mac-with-php/
- More tests for each feature test to test for the form validations by using a dataProvider.
- Lint to lint the files.
- Change the way user roles (admin and user) are been hard-coded and use
ENUM
types instead - Handle pagination of bookings listing on the admin dashboard/bookings page.