{"id":16327339,"url":"https://github.com/willsams/python-hotel-reservation","last_synced_at":"2026-04-13T03:07:30.710Z","repository":{"id":207369542,"uuid":"719074800","full_name":"WillSams/python-hotel-reservation","owner":"WillSams","description":"An example is a GraphQL API that allows the creation and listing of reservations, along with the ability to list available rooms for a given date range.","archived":false,"fork":false,"pushed_at":"2024-05-06T19:24:48.000Z","size":39,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-12T20:01:32.617Z","etag":null,"topics":["bdd","direnv","docker","flask","graphql","knexjs","nodejs","nvm","postgresql","pytest","pytest-mock","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WillSams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"ko_fi":"samswebs"}},"created_at":"2023-11-15T11:56:00.000Z","updated_at":"2023-11-16T11:41:38.000Z","dependencies_parsed_at":"2023-11-15T13:29:51.294Z","dependency_job_id":"842e0ed5-5bf0-440e-8b00-a1094321e7c7","html_url":"https://github.com/WillSams/python-hotel-reservation","commit_stats":null,"previous_names":["willsams/python-hotel-reservation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fpython-hotel-reservation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fpython-hotel-reservation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fpython-hotel-reservation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fpython-hotel-reservation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WillSams","download_url":"https://codeload.github.com/WillSams/python-hotel-reservation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254240066,"owners_count":22037822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","direnv","docker","flask","graphql","knexjs","nodejs","nvm","postgresql","pytest","pytest-mock","python"],"created_at":"2024-10-10T23:11:08.371Z","updated_at":"2026-04-13T03:07:30.669Z","avatar_url":"https://github.com/WillSams.png","language":"Python","funding_links":["https://ko-fi.com/samswebs"],"categories":[],"sub_categories":[],"readme":"# Python Flask Example - Hotel Reservation Service\n\nThe **Hotel Reservation Service** example is a GraphQL API providing the ability to create and list reservations as well as the ability to list available rooms for a given date range.\n\nBooked reservations are listed via the API. Each reservation request were processed in the order provided as if they were real-time requests. The following rules are observed:\n\n**Context**:\n\n* When a room is reserved, it cannot be reserved by another guest on overlapping dates.\n* Whenever there are multiple available rooms for a request, the room with the lower final price is assigned.\n* Whenever a request is made for a single room, a double bed room may be assigned (if no single is available?).\n* Smokers are not placed in non-smoking rooms.\n* Non-smokers are not placed in allowed smoking rooms.\n* Final price for reservations are determined by daily price * num of days requested, plus the cleaning fee.\n\n**Usage**\n\nExample usage via [curl](https://curl.se/download.html):\n\n```bash\n# List all existing booked reservations\ncurl http://localhost:$API_PORT/development/api \\\n    -H 'Content-Type: application/json' \\\n    -d '{\"query\": \"query { getAllReservations { reservations { room_id checkin_date checkout_date  } } }\"}'\n\n# Create a new reservation\n# Note: if there is an overlap, you'll see a \n#   'Reservation dates overlap with an existing reservation' error message\n# To see the aforementioned error, run this mutation a multiple times\ncurl http://localhost:$API_PORT/development/api \\\n    -H 'Content-Type: application/json' \\\n    -d '{ \"query\": \"mutation { createReservation( input: { room_id: \\\"91754a14-4885-4200-a052-e4042431ffb8\\\", checkin_date: \\\"2023-12-31\\\", checkout_date: \\\"2024-01-02\\\", total_charge: 111 }) { success errors reservation { id room_id checkin_date checkout_date total_charge } } }\" }'\n\n# List Available Rooms for a given date range\ncurl http://localhost:$API_PORT/development/api \\\n    -H 'Content-Type: application/json' \\\n    -d '{\"query\": \"query { getAvailableRooms( input: { checkin_date: \\\"2023-12-31\\\", checkout_date: \\\"2024-01-02\\\" }) { success errors rooms { id num_beds allow_smoking daily_rate cleaning_fee } } }\" }'\n```\n\n**Table of Contents**:\n\n* [Prerequisites](#prerequisites)\n* [Getting Started](#getting-started)\n    - [Install Python Packages](#install-python-packages)\n    - [Install Node.js Packages](#install-nodejs-packages)\n    - [Create the Database](#create-the-database)\n* [Development](#development)\n* [Testing](#testing)\n* [Troubleshooting](#troubleshooting)\n    - [Docker Image](#docker-image)\n* [License](#license)\n\n## Prerequisites\n\nTo run the service, you will need to install the following tools.\n\n* [Python](https://www.python.org/downloads/)\n* [NodeJS](https://nodejs.org/en/) - Used for migrations ([Knex.js](https://knexjs.org/)). \n\nFor migrations, [Flask-Migrate](https://flask-migrate.readthedocs.io/en/latest/index.html) or [Alembic](https://alembic.sqlalchemy.org/en/latest/) are suitable options, but I prefer using **Knex.js** due to familiarity.\n\nThe below are optional:\n\n* [nvm](https://github.com/nvm-sh/nvm) - Used to manage NodeJS versions.\n* [Direnv](https://direnv.net/) - Used to manage environment variables.\n* [Docker](https://www.docker.com/)  - We can containerize the hotel reservation service:\n    - Push the container to [Amazon Elastic Container Registry](https://aws.amazon.com/ecr/)\n    - Once in ECR, serve the container as an [AWS Elastic Container service](https://aws.amazon.com/ecs/).\n    - We can then use the [Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/) to distribute traffic across ECS tasks.\n\n## Getting Started\n\nFirst, we'll need to set up our environment variables.  You can do this by either:\n\n* Manually exporting the necessary environment variables in your shell.  These are listed in the [`./envrc.example`](./envrc.example) file.\n\nor\n\n* Use optionally use **Direnv**.\n\n```bash\ncp .envrc.example .envrc\ndirenv allow\n```\n\nFor exporting environment variables, [Python Dotenv](https://pypi.org/project/python-dotenv/) is an option as well.  However, **Direnv** is preferred as it isn't dependent on Python therefore can be used in other use-cases.\n\n### Install Python Packages\n\nExecute the following in your terminal:\n\n```bash\npython -m venv venv\nsource venv/bin/activate\npip install --upgrade pip \npip install -r requirements.txt\n```\n\n### Install Node.js Packages\n\nExecute the following within your terminal:\n\n```bash\nnvm use             # To eliminate any issues, install/use the version listed in .nvmrc. \nnpm i               # install the packages needed for project \n```\n\n### Create the database\n\nFinally, let's create and seed the databases and our Reservations and Rooms tables:\n\n```bash\n# Create the databases and seed them\nNODE_ENV=development | ./create_db.sh \u0026\u0026 npm run refresh\nNODE_ENV=test | ./create_db.sh \u0026\u0026 npm run refresh\n```\n\n## Development\n\nTo run the service locally:\n\n```bash\ndocker-compose up -d  # runs the database in the background\npython src/main.py\n```\n\nTo verify the service is working:\n\n```bash\ncurl http://localhost:$API_PORT/$ENV/about\n```\n\nViola!  Again, you can also acces the Ariadne GraphiQL (interactive test playground) instance at [http://localhost:$API_PORT/$ENV/playground](http://localhost:$PLAYGROUND_PORT/$ENV/playground).  \n\n## Testing\n\nThe project includes BDD-style tests organized for improved readability and comprehension. These tests are segmented into individual files, a structure that simplifies the testing process and enhances accessibility. While individual preferences may vary, this is my chosen approach for managing tests in this project.\n\nTo run the tests, simply enter the following command in your terminal:\n\n```bash\n./run_tests.sh\n```\n\n## Troubleshooting\n\n### Docker image\n\nTo troubleshoot issues with the Docker image used for deployment, build it by executing the following:\n\n```bash\ndocker build -t py-hotel-res:latest .\ndocker run --name py-hotel-dev --network host py-hotel-res\n```\n\nIf the container is running, you should be able to navigate to [http://localhost/development/about](http://localhost/development/about)\n\n\nTo troubleshoot further, you can review files on the container by logging into it:\n\n```bash\nCONTAINER_ID=$(docker ps -qf \"name=py-hotel-dev\" -n 1)\ndocker exec -it $CONTAINER_ID sh\n```\n\nWhen done, stop the container and then remove it:\n\n```bash\ndocker stop py-hotel-dev\ndocker rm py-hotel-dev\n```\n\n## License\n\nLicense information can be found [here](./LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillsams%2Fpython-hotel-reservation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillsams%2Fpython-hotel-reservation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillsams%2Fpython-hotel-reservation/lists"}