Welcome to the BookRating Site! This project is a Django-based web application designed to manage and rate books through a RESTful API. The application utilizes Django Rest Framework (DRF) for API implementation, Postgres for database management, Redis for caching, and Celery for task scheduling. It also features token-based authentication, custom permissions, and unit tests.
- CRUD Operations: Full CRUD operations for managing books and ratings through RESTful APIs.
- Authentication: Token-based authentication to secure the API.
- Custom Permissions: Custom permission classes to manage access control.
- Caching: Utilizes Redis for efficient caching of frequently accessed data.
- Task Scheduling: Celery is integrated for background task processing.
- Filtering: Django Filters are applied to filter API responses.
- Rating System: Calculate and display book ratings and average ratings.
- Custom Django Command: A custom Django management command that fetches data from the Google Books API and populates the book model.
- Unit Testing: Comprehensive unit tests written using Factory Boy and Mock.
- Signals: Implementation of django signals.
- Backend: Django, Django Rest Framework (DRF)
- Database: PostgreSQL (Locally hosted)
- Caching: Redis
- Task Scheduling: Celery
- Testing: Factory Boy, Mock
- Authentication: Token-based
- Docker and Docker Compose
- PostgreSQL (Locally hosted)
- Redis
-
Clone the Repository:
git clone https://github.com/samikshakhadka/BookRating.git cd BookRating
-
Create and Configure Environment Variables:
- Create a
.env
file in the root directory and add the necessary environment variables such asDJANGO_DB_NAME
,DJANGO_DB_USER
,DJANGO_DB_PASSWORD
,DJANGO_DB_HOST
, andDJANGO_DB_PORT
. - Ensure that
DJANGO_DB_HOST
is set to your host's IP address orhost.docker.internal
(depending on your operating system).
- Create a
-
Build and Start the Docker Containers:
- Build and start the Docker containers using Docker Compose:
docker-compose up --build
- Build and start the Docker containers using Docker Compose:
-
Run Migrations:
- Once the containers are up, run the database migrations:
docker-compose run web python manage.py migrate
- Once the containers are up, run the database migrations:
-
Start Redis and Celery:
- Ensure Redis is running (this should be handled by Docker Compose) and start Celery within the Docker container:
docker-compose run worker
- Ensure Redis is running (this should be handled by Docker Compose) and start Celery within the Docker container:
-
Run the Development Server:
- The development server should already be running inside the Docker container, accessible at
http://localhost:8000
or the appropriate IP address.
- The development server should already be running inside the Docker container, accessible at
-
Run the Custom Django Command:
- To fetch book data from the Google Books API and populate the book model, run:
docker-compose run web python manage.py fetch_books
- To fetch book data from the Google Books API and populate the book model, run:
The API uses token-based authentication. To access the secured endpoints, include the token in the Authorization
header:
Authorization: Token <your_token>
Unit tests are written using Factory Boy and Mock. To run the tests, use the following command:
docker-compose run web python manage.py test
Contributions are welcome! Please submit a pull request or open an issue to discuss the changes you would like to make.