This is a Django-based RESTful API for managing a library system with book borrowings, payments, and notifications. The API supports CRUD operations for books, user management, borrowing, payments, and integrates with the Stripe payment gateway and Telegram API.
- Python 3.x
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/sakhaline/library-service.git cd library-service-api
-
You can open project in IDE and configure .env file using .env.sample file as an example.
-
Build and run the Docker containers:
docker-compose up --build
The API will be accessible at http://localhost:8000/.
Click me
- Start chat with Bot Father
/newbot
- to create new bot- Send bot's name
/setprivacy
- change to Disable- Copy and save API Key, Bot Link
- You need to create channel
- Than, you should add your bot using Bot Link
- Write some message in chat
- Go to
https://api.telegram.org/bot<TOKEN>/getUpdates
. - In
<TOKEN>
place API Key - You will get response:
"chat": {
"id": -4017738106,
"title": "Order Tickets",
"type": "group",
"all_members_are_administrators": true
},
- Save your Chat ID
- Write all saved information inside .env file like that:
TELEGRAM_API_KEY=6503311767:AAEkcCdnc3MewRnLe53YZgnDSdqdq1pq7mE
TELEGRAM_CHAT_ID=-4017738106
You can change images that bot sends in telegram_notifications.py
BORROW_PHOTO = ("link-to-image")
PAYMENT_PHOTO = ("link-to-image")
Click me
- Sent
/start
to Checks and Orders Bot
- Sent
/start
to Get My ID Bot - Copy
Your user ID: 751285126
Description
The Books Service in the Library API offers complete CRUD functionality, including the initialization of the "books" app, creation of a book model, and implementation of serializers and views for essential endpoints. Additionally, robust permissions are enforced, ensuring that only admin users have the authority to create, update, and delete books, while all users, including those not authenticated, can access a comprehensive list of available books. JWT token authentication from the users' service enhances security and user-specific interactions within the Books Service.API Endpoints
- POST:
/books/
- Add a new book - GET:
/books/
- Get a list of books - GET:
/books/<id>/
- Get detailed information about a book - PUT/PATCH:
/books/<id>/
- Update book details (including inventory) - DELETE:
/books/<id>/
- Delete a book
Description
The Users Service in the Library API implements full CRUD functionality, beginning with the initialization of the "users" app. This involves adding a user model with email support and integrating JWT (JSON Web Token) authentication for enhanced security. The implementation includes serializers and views for all endpoints, ensuring a seamless and secure user management system.API Endpoints
- POST:
/users/
- Register a new user - POST:
/users/token/
- Get JWT tokens - POST:
/users/token/refresh/
- Refresh JWT token - GET:
/users/me/
- Get user's profile information - PUT/PATCH:
/users/me/
- Update user's profile information
Description
The Borrowings Service in the Library API provides robust functionality for managing book borrowings. It includes the initialization of the borrowing app, a model with constraints for accurate tracking, and a read serializer for detailed book information. The service offers endpoints for listing, retrieving details, and creating borrowings, with validations for inventory and user permissions. Borrowings can be marked as returned, triggering inventory updates, and notifications are sent for new borrowings and overdue items. Telegram integration enables real-time notifications, and a scheduled task checks for daily overdue borrowings, providing detailed alerts or a notification of no overdue borrowings. This service ensures efficient borrowing processes and timely communication with users.API Endpoints
- POST:
/borrowings/
- Add a new borrowing (decrement inventory by 1) - GET:
/borrowings/?user_id=...&is_active=...
- Get borrowings by user id and active/inactive status - GET:
/borrowings/<id>/
- Get specific borrowing - POST:
/borrowings/<id>/return/
- Set actual return date (increment inventory by 1)
- Notifications are sent asynchronously using Django Celery.
- Interacts with other services to send notifications to library administrators.
- Uses Telegram API, Telegram Chats & Bots.
Description
Stripe is a widely used payment processing platform that enables businesses and individuals to accept online payments. Stripe offers a RESTful API that allows developers to interact with various resources, such as customers, payments, subscriptions, and more. Admins Only - Refund money to a user in case of unexpected issues. Accessible to users with is_staff = True.- Stripe API: https://stripe.com/docs/api
Payment Endpoints
- GET:
/api/payments
- Retrieve all payments for an authenticated user. - GET:
/api/payments/pk/
- Retrieve detailed information about a specific payment. - GET:
/api/payments/pk/success/
- Description: Check the success status of a Stripe payment by examining the payment status. - GET:
/api/payments/pk/cancel/
- Return a payment paused message, allowing the user's payment link to be available for 24 hours. - GET:
/api/payments/pk/refund/
- Admins Only - Refund money to a user in case of unexpected issues. Accessible to users with is_staff = True.
- Email:
[email protected]
- Cardholder name:
Joe Doe
- Card Number:
4242 4242 4242 4242
- Date MM/YY:
11/30
(random feature date) - CVC:
123
API Endpoints:
- GET:
/success/
- Check successful Stripe payment - GET:
/cancel/
- Return payment paused message
Interacts with Stripe API using the stripe
package.
The API is documented using the OpenAPI standard. Access the API documentation by running the server and navigating to http://localhost:8000/api/doc/swagger/ or http://localhost:8000/api/doc/redoc/.