http://localhost:3000
http://localhost:3000/api
ทุก API ใช้ Response format เดียวกัน:
interface ApiResponse<T> {
success: boolean;
message: string;
data: T | null;
}ดึงรายการหนังสือทั้งหมด (รองรับ ค้นหา, กรอง และ แบ่งหน้า)
- Query Parameters:
page(number, default: 1)limit(number, default: 10)search(string) — ค้นหาจาก title, author, หรือ isbncategory(string) — กรองตามหมวดหมู่status(string) — กรองตามสถานะ
- Response:
200 OK
{
"success": true,
"message": "Books retrieved successfully",
"data": [
{
"id": "uuid",
"isbn": "978-616-123-456-7",
"title": "TypeScript Design Patterns",
"author": "John Doe",
"publisher": "Tech Publishing",
"publishedYear": 2024,
"category": "TECHNOLOGY",
"description": "A comprehensive guide",
"status": "AVAILABLE",
"isAvailableForLoan": true,
"currentBorrowerId": null,
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
]
}ดึงหนังสือตาม ID
- Parameters:
id(UUID) - Response:
200 OK|404 Not Found
ดึงสถิติของข้อมูลหนังสือทั้งหมด (รวมจำนวนหนังสือทั้งหมด, ว่าง, ถูกยืม และแบ่งตามหมวดหมู่)
- Response:
200 OK
ยืมหนังสือ โดยระบุรหัสสมาชิกผู้ยืม
- Parameters:
id(UUID ของหนังสือ) - Response:
200 OK|400 Bad Request|404 Not Found - Body:
{
"memberId": "member-uuid"
}คืนหนังสือที่ถูกยืม และระบบจะคำนวณค่าปรับอัตโนมัติ (และเปลี่ยนสถานะเป็น RESERVED ถัดไปหากมีคิว)
- Parameters:
id(UUID ของหนังสือ) - Response:
200 OK|400 Bad Request|404 Not Found - Response Data Example:
{
"success": true,
"message": "Book returned successfully",
"data": {
"book": { ... },
"fine": 150,
"overdueDays": 3
}
}จองหนังสือ (ต้องเป็นหนังสือที่มีสถานะ BORROWED หรือ RESERVED อยู่ และยังไม่ถึงคิวตัวเอง)
- Parameters:
id(UUID ของหนังสือ) - Response:
200 OK|400 Bad Request|404 Not Found - Body:
{
"memberId": "member-uuid"
}สร้างหนังสือใหม่
- Response:
201 Created|400 Bad Request - Body:
{
"isbn": "978-616-123-456-7",
"title": "TypeScript Design Patterns",
"author": "John Doe",
"publisher": "Tech Publishing",
"publishedYear": 2024,
"category": "TECHNOLOGY",
"description": "A comprehensive guide",
"status": "AVAILABLE",
"isAvailableForLoan": true
}| Field | Type | Required | Validation |
|---|---|---|---|
isbn |
string | ✅ | ไม่เป็นค่าว่าง |
title |
string | ✅ | ไม่เป็นค่าว่าง |
author |
string | ✅ | ไม่เป็นค่าว่าง |
publisher |
string | ✅ | ไม่เป็นค่าว่าง |
publishedYear |
number | ✅ | 1000-2100 |
category |
BookCategory | ✅ | ค่าใน enum |
description |
string | ✅ | ไม่เป็นค่าว่าง |
status |
BookStatus | ❌ | default: AVAILABLE |
isAvailableForLoan |
boolean | ❌ | default: true |
อัปเดตข้อมูลหนังสือทั้งหมด (Full Update)
- Parameters:
id(UUID) - Response:
200 OK|400 Bad Request|404 Not Found - Body: เหมือน POST แต่ทุก field บังคับ (รวม
statusและisAvailableForLoan)
อัปเดตข้อมูลหนังสือบางส่วน (Partial Update)
- Parameters:
id(UUID) - Response:
200 OK|400 Bad Request|404 Not Found - Body: ส่งเฉพาะ field ที่ต้องการอัปเดต
ลบหนังสือตาม ID (ใช้วิธีนำไป Soft Delete โดยปรับค่า deletedAt แทนการลบจากตารางจริง)
- Parameters:
id(UUID) - Response:
200 OK|404 Not Found
ดึงรายการสมาชิกทั้งหมด (รองรับ ค้นหา, กรอง และ แบ่งหน้า)
- Query Parameters:
page(number, default: 1)limit(number, default: 10)search(string) — ค้นหาจาก firstName, lastName, หรือ memberCodestatus(string) — กรองตามสถานะ
- Response:
200 OK
ดึงสมาชิกตาม ID
- Parameters:
id(UUID) - Response:
200 OK|404 Not Found
ดึงสถิติข้อมูลสมาชิก (รวมจำนวนสมาชิกทั้งหมด, ใช้งานอยู่, ปิดใช้งาน, ระงับ)
- Response:
200 OK
สมัครสมาชิกใหม่
- Response:
201 Created|400 Bad Request - Body:
{
"firstName": "สมชาย",
"lastName": "ใจดี",
"email": "somchai@example.com",
"phone": "081-234-5678",
"address": "123 ถ.สุขุมวิท กรุงเทพฯ 10110",
"status": "ACTIVE",
"maxBooksAllowed": 5
}| Field | Type | Required | Validation |
|---|---|---|---|
firstName |
string | ✅ | ไม่เป็นค่าว่าง |
lastName |
string | ✅ | ไม่เป็นค่าว่าง |
email |
string | ✅ | ต้องเป็น format email |
phone |
string | ✅ | ไม่เป็นค่าว่าง |
address |
string | ✅ | ไม่เป็นค่าว่าง |
status |
MemberStatus | ❌ | default: ACTIVE |
maxBooksAllowed |
number | ❌ | 1-20, default: 5 |
อัปเดตข้อมูลสมาชิกทั้งหมด (Full Update)
- Parameters:
id(UUID) - Response:
200 OK|400 Bad Request|404 Not Found
อัปเดตข้อมูลสมาชิกบางส่วน (Partial Update)
- Parameters:
id(UUID) - Response:
200 OK|400 Bad Request|404 Not Found
ลบสมาชิกตาม ID (Soft Delete)
- Parameters:
id(UUID) - Response:
200 OK|404 Not Found
ดึงรายการประวัติการยืม-คืนหนังสือทั้งหมด (รองรับ กรอง และ แบ่งหน้า)
- Query Parameters:
page(number, default: 1)limit(number, default: 10)bookId(string) — กรองตามรหัสหนังสือmemberId(string) — กรองตามรหัสสมาชิก
- Response:
200 OK
{
"success": false,
"message": "Book with ID \"invalid-id\" not found",
"data": null
}| Code | Description |
|---|---|
200 |
OK — สำเร็จ (GET, PUT, PATCH, DELETE) |
201 |
Created — สร้างข้อมูลสำเร็จ (POST) |
400 |
Bad Request — ข้อมูลไม่ถูกต้อง (Validation error) |
404 |
Not Found — ไม่พบข้อมูล |
500 |
Internal Server Error — ข้อผิดพลาดภายในระบบ |
ตรวจสอบสถานะการทำงานของระบบ
- Response:
200 OK
{
"status": "ok",
"uptime": 120.5,
"timestamp": "2024-01-01T00:00:00.000Z",
"message": "Library Management System API is running smoothly."
}