This Django REST Framework (DRF) project manages a library system with features like registration, authentication book listing, borrowing, and returning. with complete unit testing of models, serializer, and views.
- Getting Started
- API Documentation
- Endpoint 1: Signup
- Endpoint 1: Get All User
- Endpoint 1: Login
- Endpoint 1: List All Books
- Endpoint 2: Borrow Book
- Endpoint 3: Return Borrowed Book
Make sure you have the following tools installed:
- Python (>=3.x)
- Django
- Django REST Framework
-
Clone the repository:
git clone https://github.com/sunilnp2/library-management-drf.git cd library-management-drf
-
Install dependencies:
pip install -r requirements.txt
-
Configure Database
PostgreSQL Database DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'lms', # your database name 'USER': 'sunil', #user db user 'PASSWORD': 'sunil', #user password 'HOST': '127.0.0.1', 'PORT': '5432', } } For Sqlite Database DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / "db.sqlite3", } }
-
Apply database migrations:
Windows python manage.py makemigrations python manage.py migrate Linux python3 manage.py makemigrations python3 manage.py migrate
-
Create Superuser:
python manage.py createsuperuser python3 manage.py createsuperuser test@gmail.com test123
-
Start the development server:
python manage.py runserver python3 manage.py runserver
The API will be accessible at http://localhost:8000
-
URL:
http://localhost:8000/auth/api/signup/
-
Method: POST
-
Authentication: No Auth
-
Data:
{ "name": "Sunil Nepali", "email": "sunil@gmail.com", "password": "test123" "password2": "test123" }
-
URL:
http://localhost:8000/auth/api/login/
-
Method: POST
-
Authentication: No Auth
-
Data:
{ "email": "sunil@gmail.com", "password": "test123" }
- URL:
http://localhost:8000/auth/api/getalluser/
- Method: Get
- Authentication: No Auth
- URL:
http://localhost:8000/auth/api/getuser/id/
- Method: Get
- Authentication: No Auth
-
URL:
http://localhost:8000/library/api/book_all_create/
-
Method: POST
-
Authentication: Basic Authentication
-
Permissions: CustomPermission - (IsAuthenticatedOrReadOnly)
-
Data:
{ "title": "Rich Dad Poor Dad", "isbn": "4354", "published_date": "2020-04-23" "genre": "finance" }
- URL:
http://localhost:8000/library/api/book_all_create/
- Method: Get
- Authentication: No Auth
- URL:
http://localhost:8000/library/api/book/id
- Method: Get
- Authentication: No Auth
-
URL:
http://localhost:8000/library/api/create-book-detail/
-
Method: POST
-
Authentication: Basic Auth
-
Permissions: CustomPermission - (IsAuthenticatedOrReadOnly)
-
Data:
{ "book": 1, "number_of_pages": 330, "publisher": "Asmita Publication", "language": "english" }
-
URL:
http://localhost:8000/library/api/book-detail/id/
-
Method: Patch
-
Authentication: Basic Auth
-
Permissions: CustomPermission - (IsAuthenticatedOrReadOnly)
-
Data:
{ "number_of_pages": 400, }
-
URL:
http://localhost:8000/library/api/borrowbook/
-
Method: POST
-
Authentication: Basic Auth
-
Permissions: CustomPermission - (IsAuthenticatedOrReadOnly)
-
Data:
{ "user": 1, "book": 1, }
- URL:
http://localhost:8000/library/api/list_borrowed_book/
- Method: Get
- Authentication: Basic Auth
- Permissions: CustomPermission - (IsAuthenticatedOrReadOnly)
-
URL:
http://localhost:8000/library/api/return-book/id/
-
Method: Put
-
Authentication: Basic Auth
-
Permissions: CustomPermission - (IsAuthenticatedOrReadOnly)
-
Data:
{ "returned_date": "2024-02-01" }