A fully fledged backed system that faliciates hotels management (an OYO MVP)
APACHE-2.0 License
GO-Hotel-Reservation is a Go-based web application for hotel reservations. It is built using the Fiber web framework and MongoDB as the database. This project provides a simple and scalable solution for managing hotel information, room bookings, user authentication, and more.
Before you begin, make sure you have the following prerequisites installed:
Clone the repository:
git clone https://github.com/Adarsh-jaiss/GO-Hotel-reservation.git
cd GO-Hotel-reservation
Install dependencies:
go mod download
Set up the environment variables:
Create a .env
file in the project root and add the following:
HTTP_LISTEN_ADDRESS=:3000
JWT_SECRET=your_secret_key
MONGO_DB_NAME=hotel-reservation
MONGO_DB_URL=mongodb://your_mongodb_host:your_mongodb_port/
Seed the database with some initial values, so that you can test the API's using those values
make seed
Run the application:
go run main.go
The application should now be accessible at http://localhost:8000
.
docker build -t go-api:1 .
docker images
docker run -d -p 8000:8000 --name go_api_conatiner go-api:1
localhost:8000
else use this to diectly run the docker container :
docker run -d -p 8000:8000 --env-file /path/to/your/.env --name my_container adarshjaiss/book-my-hotel:tagname
where your .env
files should have these configs :
HTTP_LISTEN_ADDRESS=:8000
JWT_SECRET=somethingsupersecretTHATKNOWBODYKNOWS
MONGO_DB_NAME=Hotel-reservation
MONGO_DB_URL=mongodb://172.17.0.2:27017/
This guide provides step-by-step instructions on how to build and run the GO-Hotel-Reservation project using Docker.
Make sure you have the following prerequisites installed on your system:
You can install it via this simple command
docker run --name mongob -d mongo:latest -p 27017:27017
and run a docker container via
docker run --rm --name my_mongo_container -d mongo:latest
or
docker run --name mongob -d -p 27017:27017 mongo:latest
Note : Don't forget to configure the enviroment variables before running the application,otherwise it will not start and throw an error
git clone https://github.com/YourUsername/GO-Hotel-reservation.git
cd GO-Hotel-reservation
go mod download
make seed
make docker or make run
If you have exited out of docker container, use this command to create another container out of the docker image
docker run -p 3000:3000 --rm --name hotel-reservation 4fde40842494
http://localhost:3000/api/auth/signup -> POST (create a new user)
{
"firstName": "rohan",
"lastName": "nanda",
"email": "[email protected]",
"password": "12345678",
"isAdmin": true
}
http://localhost:3000/api/auth/signin -> POST (sign in already existing user)
req body :
{
"email": "[email protected]",
"password": "12345678"
}
Note : ISAdmin can only be modified in seed, we can not create a new user with admin value true, we can only seed admin.
http://localhost:3000/api/v1/user -> GET all Users
http://localhost:3000/api/v1/user/:id -> GET
http://localhost:3000/api/v1/user/:id -> DELETE
http://localhost:3000/api/v1/user/:id -> PUT (NOT updating correctly) -> can only update first and last name.
body :
{
"firstName": "rohan_baba"
}
http://localhost:3000/api/v1/hotel -> GET all hotels
http://localhost:3000/api/v1/hotel/66a91ae3401a46473b599859 -> GET hotels by ID
http://localhost:3000/api/v1/hotel/66a91ae3401a46473b599859/rooms -> GET all rooms of a hotel
http://localhost:3000/api/v1/room -> GET all the available rooms
http://localhost:3000/api/v1/room/66a91ae3401a46473b59985a/book -> POST (book rooms)(working only after authentication)
req body :
{
"fromdate":"2024-12-12T00:00:00.0Z",
"tilldate":"2024-12-25T00:00:00.0Z",
"numPersons":4
}
http://localhost:3000/api/v1/booking/id -> GET bookings by a user
http://localhost:3000/api/v1/booking/id/cancel -> GET (Cancel booking)
http://localhost:3000/api/v1/admin/booking -> GET (all bookings) NOT WORKING
You can configure the application by modifying the values in the .env
file. Make sure to update the MongoDB connection details and set a secure JWT secret.
The API endpoints are documented in the API Documentation file.
Run tests using the following command:
make test
I haven't implemented few things such as Database migration, adding up another database layer (maybe postgress), Pagination, Custom Test Cases for all the handlers, and some other API functionalities like creating admin directly via post method but in future maybe I'll apply those as well.