Skip to content

ArtemLeo/library-service-api

Repository files navigation

Library Service API 📚 📕 📖

This project is an online management system for book borrowings.

  • This system optimizes the work of library administrators.
  • Makes the service much more user-friendly.

My Trello Board on this project:

My Trello board

Project Features:

Books Service:

  • CRUD Functionality: Allows adding, viewing, updating, and deleting book records through the Books Service.
  • Permissions: Only administrators can create, update, and delete books. All users, including unauthenticated ones, can see the list of books.
  • JWT Token Authentication: Uses JWT tokens for secure user authentication.

Users Service:

  • CRUD Functionality: Allows adding, viewing, updating, and deleting book records through the Users Service.
  • JWT Support: Supports JWT tokens for secure user authentication.

Borrowings Service:

  • Create Borrowing Endpoint: Enables users to borrow books with checks for available inventory and user association.
  • Filtering: Non-admin users can only view their own borrowings, enhancing privacy and security.
  • Return Borrowing Functionality: Implements the ability to return borrowed books while ensuring it cannot be done more than once and updates book inventory accordingly.
  • Notifications: Sends notifications via Telegram API for each new borrowing.
  • Telegram Integration: Sets up communication with Telegram for sending notifications.

ModHeader Integration:

  • Chrome Extension Compatibility: Enhances user experience with the ModHeader Chrome extension by customizing the default Authorization header to Authorize for JWT authentication.

API Documentation (Spectacular Integration):

  • Swagger UI: Provides interactive API documentation at /api/doc/swagger/.
  • Redoc UI: Offers clear and readable API documentation at /api/doc/redoc/.
  • Schema Endpoint: Accesses the API schema at /api/schema/.

Stages of Project Creation:

  • Initialization of the Project:
  • - Set up the initial Django project structure.
    - Configure project settings such as database connection and Django applications.
  • Creating the Books service:
  • - Implement models, serializers, views, and URLs specific to managing books.
    - Define CRUD operations for books, allowing creation, retrieval, update, and deletion.
  • Creating Users Service:
  • - Develop user models, serializers, views, and URLs for managing user profiles.
    - Implement user authentication and authorization functionalities using JWT tokens.
  • Adding Access Rights to the Books Service:
  • - Integrate permissions to control access to book CRUD operations.
    - Ensure only administrators have permissions for create, update, and delete actions.
  • Creating the Borrowings Service:
  • - Design models, serializers, views, and URLs to handle book borrowing transactions.
    - Implement borrowing functionality with validations for inventory availability and user associations.
  • Implementation of Borrowings Filtering and List Endpoint:
  • - Enhance the Borrowings API to support filtering for different user roles.
    - Allow non-admin users to view only their own borrowing records, ensuring privacy and security.
  • Implementation of Borrowing Return Functionality:
  • - Develop features to facilitate the return of borrowed books.
    - Include validations to prevent duplicate returns and update book inventory accordingly.
  • Implementation of Tests for Borrowing and Book:
  • - Create comprehensive unit tests to validate the functionality of book and borrowing APIs.
    - Ensure test coverage across models, views, serializers, and permissions.
  • Documentation of the Project:
  • - Generate API documentation using tools like drf-spectacular.
    - Provide interactive API documentation through Swagger UI and Redoc UI for clarity and usability.
  • Integration of Sending Notifications when Creating a Borrowing:
  • - Configure integration with Telegram API to send notifications for each new borrowing transaction.
    - Set up communication channels and message formats for notification delivery.
  • Registration of Models in the Admin Panel:
  • - Register relevant models (Books, Users, Borrowings) in the Django admin interface.
    - Enable administrators to manage and monitor data through the admin panel efficiently.
  • Update README.md:
  • - Maintain an up-to-date README.md file with essential project information, setup instructions, and usage guidelines.
    - Include details about environment variables, installation steps, and accessing API endpoints.

🏞 Test Coverage Report:

The test coverage report shows testing effectiveness, with an explanation of the columns below:

  • Stmts (Statements): Represents the total number of executable statements in the codebase, including lines of code that are evaluated during testing.
  • Miss (Missed Statements): Indicates the number of statements that were not executed during testing. This typically occurs when certain parts of the code were not covered by the test cases.
  • Cover (Coverage Percentage): Shows the percentage of statements that were executed during testing out of the total executable statements. It is calculated as (Stmts - Miss) / Stmts * 100.
Name                                                                    Stmts   Miss  Cover
-------------------------------------------------------------------------------------------
books\__init__.py                                                           0      0   100%
books\admin.py                                                              3      2    33%
books\apps.py                                                               4      0   100%
books\migrations\0001_initial.py                                            5      0   100%
books\migrations\__init__.py                                                0      0   100%
books\models.py                                                            12      1    92%
books\permissions.py                                                        4      0   100%
books\serializers.py                                                        6      0   100%
books\tests\__init__.py                                                     0      0   100%
books\tests\test_book_api.py                                               72      0   100%
books\urls.py                                                               6      0   100%
books\views.py                                                              8      0   100%
borrowings\__init__.py                                                      0      0   100%
borrowings\admin.py                                                         7      6    14%
borrowings\apps.py                                                          4      0   100%
borrowings\migrations\0001_initial.py                                       7      0   100%
borrowings\migrations\0002_borrowing_borrow_date_not_past_and_more.py       7      0   100%
borrowings\migrations\0003_remove_borrowing_borrow_date_not_past.py         4      0   100%
borrowings\migrations\__init__.py                                           0      0   100%
borrowings\models.py                                                       27      2    93%
borrowings\serializers.py                                                  44      0   100%
borrowings\tests\__init__.py                                                0      0   100%
borrowings\tests\test_borrowing_api.py                                    137      0   100%
borrowings\urls.py                                                          6      0   100%
borrowings\views.py                                                        49      0   100%
library_service_api\__init__.py                                             0      0   100%
library_service_api\settings.py                                            26      0   100%
library_service_api\urls.py                                                 4      0   100%
manage.py                                                                  12      2    83%
telegram_api\__init__.py                                                    0      0   100%
telegram_api\telegram_helper.py                                            12      2    83%
users\__init__.py                                                           0      0   100%
users\admin.py                                                             12     11     8%
users\apps.py                                                               4      0   100%
users\migrations\0001_initial.py                                            7      0   100%
users\migrations\__init__.py                                                0      0   100%
users\models.py                                                            36      8    78%
users\serializers.py                                                       17      7    59%
users\tests\__init__.py                                                     0      0   100%
users\tests\test_user_api.py                                                0      0   100%
users\urls.py                                                               5      0   100%
users\views.py                                                             13      1    92%
-------------------------------------------------------------------------------------------
TOTAL                                                                     560     42    92%

Installation and Usage:

  • Python 3.10 must be already installed.
  • Clone the repository.
  • Set up environment variables using ".env.sample" as a guide.
  • Run the application.
  • Feel free to explore and contribute!
git clone https://github.com/ArtemLeo/library-service-api.git

(for Windows)
python -m venv venv
source venv/Scripts/activate

(for Mac/Linux)
python3 -m venv venv
source venv/bin/activate

python -m pip install --upgrade pip
pip install -r requirements.txt

set DJANGO_SECRET_KEY=<your django secret key>
set DJANGO_ALLOWED_HOSTS=<your allowed hosts>
set DJANGO_DEBUG=<your debug value>

set TELEGRAM_BOT_TOKEN=<your telegram secret key>
set TELEGRAM_CHAT_ID=<your telegram chat id>

python manage.py makemigrations
python manage.py migrate
python manage.py runserver

Getting access:

  • create a user via /api/user/register
  • get access token via /api/user/token

About

An online management system for book borrowings.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages