The Library Service API is a backend system built with Django REST Framework to manage a library's operations. The system allows users to browse books, borrow them, manage borrowings, and handle payments using Stripe. Additionally, it integrates with Telegram for sending notifications about borrowings and overdue items.
- Allows users to view available books in the library.
- Users can borrow books, and the system automatically calculates borrowing duration and fees.
Users can register, log in, and manage their profiles.
- Supports payments through Stripe, including creating payment sessions and handling fines for overdue borrowings.
- Sends notifications to users via Telegram when a borrowing is created, overdue, or returned.
- Admins can manage books, users, and borrowings.
- POST /api/user/login/: Log in with credentials to receive JWT tokens.
- POST /api/user/register/: Register a new user
- POST /api/user/register/: Register a new user.
- POST /api/user/token/: Obtain a JWT token by providing valid credentials (login).
- POST /api/user/token/refresh/: Refresh the JWT token.
- POST /api/user/token/verify/: Verify the validity of a JWT token.
- GET /api/user/me/: Retrieve or update the authenticated user's profile.
- GET /api/books/: List all available books.
- GET /api/books/{id}/: Get details of a specific book.
- POST /api/books/: Create a new book (admin only).
- PATCH /api/books/{id}/: Update book details (admin only).
- DELETE /api/books/{id}/: Delete a book (admin only)
- GET /api/borrowings/: List all borrowings (for admin) or borrowings by a specific user.
- POST /api/borrowings/: Create a new borrowing.
- GET /api/borrowings/{id}/: Retrieve details of a specific borrowing.
- PATCH /api/borrowings/{id}/: Update borrowing details (e.g., return date).
- DELETE /api/borrowings/{id}/: Delete a borrowing (admin only).
- POST /api/payments/checkout/: Create a Stripe payment session for a borrowing.
- POST /api/payments/webhook/: Stripe webhook to handle payment confirmation.
GET /debug/: Django Debug Toolbar (only available in development mode).
Python3 must be already installed
- git clone https://github.com/romanshupak/library-service.git
- stripe account
- telegram bot token
- cd library-service
- python -m venv venv
- venv\Scripts\activate (on Windows)
- source venv/bin/activate (on macOS)
- pip install -r requirements.txt
- python manage.py migrate
- python manage.py runserver
To run the project using Docker, ensure that Docker is installed on your system.
- Build the containers:
docker-compose build
- Run the containers:
docker-compose up
- To run Redis (used for Celery task queue):
docker run -d -p 6379:6379 redis
To configure the application, you need to set up the following environment variables in your .env file:
-
DJANGO_SECRET_KEY: The secret key used by Django for security purposes. This should be a long, random string.
-
TELEGRAM_BOT_TOKEN=Your_bot_token
-
TELEGRAM_CHAT_ID=Your_chat_id
-
CELERY_BROKER_URL=CELERY_BROKER_URL
-
CELERY_RESULT_BACKEND=CELERY_RESULT_BACKEND
-
STRIPE_SECRET_KEY=STRIPE_SECRET_KEY
-
STRIPE_PUBLISHABLE_KEY=STRIPE_PUBLISHABLE_KEY
-
STRIPE_ENDPOINT_SECRET_KEY=STRIPE_ENDPOINT_SECRET_KEY
Make sure to replace the placeholder values with your actual configuration settings before running the application.
- Backend: Django, Django REST Framework
- Database: SQLite
- Asynchronous Tasks: Celery, Redis
- Payments: Stripe
- Notifications: Telegram API
- Containerization: Docker
- create user via /api/user/register/
- get access token via /api/user/token/
For demonstration purposes, you can use the following token credentials:
- Email: [email protected], Password: libraryadmin
- Email: [email protected], Password: libraryuser1
- Email: [email protected], Password: libraryuser2
- Email: [email protected], Password: libraryuser3