This is a RESTful API for a bookstore, built using Go, Docker, PostgreSQL, and Nginx. The API supports operations like creating users, adding books to inventory, and writing reviews.
- User authentication
- Inventory management
- Writing and viewing book reviews
- Admin functionalities
- HTTPS support via Nginx
- Reverse proxy using Nginx
- Docker
- Docker Compose
- Go 1.21.0 or higher
-
Clone the repository
git clone https://github.com/BalkanID-University/vit-2025-summer-engineering-internship-task-35C4n0r
-
Navigate to the project folder
cd vit-2025-summer-engineering-internship-task-35C4n0r
-
HTTPS Configuration for Local Development
This project uses HTTPS for secure communication. For local development, you can generate a self-signed SSL certificate using OpenSSL. Run the following command: Place them in a folder
certs
in the root directory of the project.openssl req -x509 -newkey rsa:4096 -keyout localhost.key -out localhost.crt -days 365 -nodes -subj "/CN=localhost"
I've already added the certificates in certs/* for ease of use.
-
Environment Variables
The project uses the following environment variables:
DB_HOST
: Database host nameDB_USER
: Database userDB_PASSWORD
: Database passwordSERVER_PORT
: Port for the Go applicationSERVER_SECRET
: Secret for JWT generationADMIN_SECRET
: Secret for admin functionalities
I've already added all of the above variables to the
docker-compose.yml
for ease of use -
Build and start the Docker containers
docker-compose build docker compose up
Once the containers are up, the API will be available at https://localhost/api/
.
GET /
: Sanity check to test the server.POST /register
: Register a new user.POST /login
: Login and receive a JWT token.
These routes require a JWT token in the Authorization
header.
GET /middleware
: Checks if middleware is functioning correctly.POST /deactivate
: Deactivate a user's account.DELETE /delete
: Delete a user's account.
GET /books
: Search for books.POST /cart
: Add a book to the cart.PUT /cart
: Update the quantity of an item in the cart.DELETE /cart/:isbn
: Remove a book from the cart.GET /cart
: Retrieve items in the cart.POST /purchase
: Purchase items in the cart.
POST /review
: Add a review for a book.GET /review
: Retrieve reviews for a book.
GET /download/:isbn
: Download a book.
These routes require admin privileges.
POST /admin/add
: Add a new book to the database.DELETE /admin/delete/:isbn
: Remove a book from the inventory.PUT /admin/update
: Update the details of a book.