Skip to content

alifruliarso/fastapi_restaurant_booking

Repository files navigation

Restaurant Booking API Example Project

Available Endpoint

The example of API usage can be found here.

Booking a table:

  • POST http:https://localhost:8000/v1/bookings
    {
      "restaurant_id": 1,
      "table_number": 1,
      "start_at": "2023-10-15T10:35:00",
      "guest_email": "[email protected]",
      "payment_amount": 5000,
      "payment_method": "cash",
      "payment_provider": "cash"
    }

Buy a ticket:

  • POST http:https://localhost:8000/v1/bookings/tickets
    {
      "restaurant_id": 0,
      "table_number": 0,
      "start_at": "2023-10-17T07:21:23.454Z",
      "ticket_code": "string",
      "payment_amount": 0,
      "payment_method": "string",
      "payment_provider": "string"
    }

Approve booking by admin:

  • PUT http:https://localhost:8000/v1/bookings/{booking_id}/approval

Approve buy ticket by admin:

  • PUT http:https://localhost:8000/v1/bookings//{booking_id}/approval/{dining_table_id}

Problem

In case an admin can not approve the booking, then there is a process for approving the booking automatically.
The job will run in defined interval (ex: 2s), do the approval on pending bookings within specific restaurant (configurable).

  • Example logs when the job running:
    app  | [2023-10-17 07:32:42,430] [INFO] [apscheduler.executors.default] Running job "execute_approve (trigger: interval[0:02:00], next run at: 2023-10-17 07:34:42 UTC)" (scheduled at 2023-10-17 07:32:42.430115+00:00)
    app  | Pending bookings = 0
    app  | [2023-10-17 07:32:42,448] [INFO] [apscheduler.executors.default] Job "execute_approve (trigger: interval[0:02:00], next run at: 2023-10-17 07:34:42 UTC)" executed successfully



Local Development

Setting configuration in .env file.

  • Change database's username, password, and host.
    DATABASE_URL=postgresql+asyncpg:https://useradmin:[email protected]:5432/restaurantbooking
  • Adding restaurant-id in case auto approve.
    RESTAURANTS_AUTO_APPROVED=[1]

Build docker image

  • First Build Only
    docker compose build
  • Run the app
    docker compose up

Migrations

  • Run migrations
    docker compose exec app migrate
  • Create an automatic migration from changes in src/database.py
    docker compose exec app makemigrations *migration_name*
  • Downgrade migrations
    docker compose exec app downgrade -1  # or -2 or base or hash of the migration
  • Format
    docker compose exec app format
  • Seed dummy restaurant
    docker compose exec app python src/seed_restaurant.py


Inspiration

Many pieces of this codebase have been inspired by various projects in the FastAPI community:

About

Restaurant Booking API Example Project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published