https://github.com/mahimdev/mongodb-b5a3
https://github.com/mahimdev/mongodb-b5a3
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mahimdev/mongodb-b5a3
- Owner: mahimDev
- Created: 2025-06-20T19:54:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-20T20:01:07.000Z (about 1 year ago)
- Last Synced: 2025-06-28T00:12:50.934Z (about 1 year ago)
- Language: TypeScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📚 Library Management System API
This is a Library Management System backend built with **Express**, **TypeScript**, and **MongoDB (Mongoose)**.
## 🚀 Features
- Add, update, delete, and retrieve books
- Borrow books with quantity & due date
- Auto-update availability based on copies
- Summary of all borrowed books (with aggregation)
- Mongoose validation, static methods, and middleware used
- Filtering, sorting, and pagination support
## 📦 Technologies Used
- Node.js + Express
- TypeScript
- MongoDB with Mongoose
- ts-node-dev for development
## 🛠️ Setup Instructions
1. **Clone the repository**
```bash
git clone
cd assignment-3
```
2. **Install dependencies**
```bash
npm install
```
3. **Create `.env` file**
```env
PORT=5000
MONGODB_URI=mongodb://localhost:27017/library-api
```
4. **Run the development server**
```bash
npm run dev
```
## 📁 API Endpoints
### 📘 Books
#### ➕ Create Book
`POST /api/books`
```json
{
"title": "The Theory of Everything",
"author": "Stephen Hawking",
"genre": "SCIENCE",
"isbn": "9780553380163",
"description": "An overview of cosmology and black holes.",
"copies": 5
}
```
#### 📚 Get All Books (with filters)
`GET /api/books?filter=FANTASY&sortBy=createdAt&sort=desc&limit=5`
#### 📖 Get Book by ID
`GET /api/books/:bookId`
#### ✏️ Update Book
`PUT /api/books/:bookId`
```json
{
"copies": 10
}
```
#### ❌ Delete Book
`DELETE /api/books/:bookId`
---
### 📗 Borrow
#### ➕ Borrow a Book
`POST /api/borrow`
```json
{
"book": "",
"quantity": 2,
"dueDate": "2025-07-18"
}
```
#### 📊 Borrow Summary
`GET /api/borrow`
```json
[
{
"book": { "title": "The Theory of Everything", "isbn": "9780553380163" },
"totalQuantity": 5
}
]
```