The Book Management API is a library system built using Ruby on Rails. It allows users to borrow and return books while keeping track of transactions, account balances The system ensures that users can only borrow books if they have sufficient balance.
- User Management
- Users have an account with an initial balance.
- Users can query their account balance and borrowing history.
- Book Borrowing & Returning
- Users can borrow books if they have sufficient balance
- A fee is deducted from the user's balance upon borrowing.
- Users must return borrowed books before borrowing again.
- Reporting & Queries
- Query a user's account and borrowed books.
- Query book loan counts
- Generate user reports for monthly and annual borrowing activity.
- Calculate book income over a time period.
POST /api/v1/users
- Create a new user with an initial balance.GET /api/v1/users/:id/account
- Retrieve a user's account details.GET /api/v1/users/:id/report?type=monthly|annual
- Get user borrowing report for a given period.
POST /api/v1/transactions/return
- Return a book (requiresuser_id
andbook_id
).POST /api/v1/transactions/borrow
- Borrow a book (requiresuser_id
andbook_id
).
GET /api/v1/books/:id/income?start_at=YYYY-MM-DD&end_at=YYYY-MM-DD
- Get total income for a book within a date range.
- Business logic is encapsulated in service objects (
BorrowBook
,ReturnBook
,BookIncome
).
- User: Manages user data and balance constraints.
- Book: Manages book details.
- Transaction: Tracks borrow and return transactions.
- Rswag is used to generate API documentation.
- Request examples are automatically included.
After creating a user, log in to retrieve your authentication token. Then, click the Authorize
button and enter the token obtained from the login response to secure your session.
- Clone the repository:
git clone https://github.com/your-repo/book-management-api.git cd book-management-api
- Install dependencies:
bundle install
- Set up the database:
rails db:create db:migrate db:seed
- Run the server:
rails s
- Run RSpec tests:
rspec
- Run API documentation tests:
rake rswag:specs:swaggerize
- Book availability management.
- Implementing transaction status.
- Add background jobs for overdue book notifications.
- Improvements to authentication system
- Implement validation to prevent users from borrowing a book that they have already checked out.