ยินดีต้อนรับสู่การจัดส่ง API! API นี้เป็นโซลูชันสำหรับการจัดการผลิตภัณฑ์และการขายในแอปพลิเคชันของคุณ สร้างขึ้นด้วย. NET มันมีส่วนต่อประสานที่เหลือสำหรับการสร้างและจัดการผลิตภัณฑ์และประมวลผลธุรกรรมการขาย เอกสารนี้ให้ภาพรวมของจุดสิ้นสุดการจัดส่ง API รวมถึงคำอธิบายโดยละเอียดพารามิเตอร์การร้องขอและรูปแบบการตอบกลับ API รวมถึงจุดสิ้นสุดสำหรับการตรวจสุขภาพการจัดการผลิตภัณฑ์และการจัดการการขาย
โคลนที่เก็บ:
git clone https://github.com/anthonyvii27/delivery-apiเปลี่ยนเป็นไดเรกทอรีที่เก็บ:
cd delivery-apiเรียกใช้คำสั่งเพื่อเริ่มสภาพแวดล้อมคอนเทนเนอร์:
make compose-up-v2 API จะทำงานบนพอร์ต :8080 บนคอมพิวเตอร์ของคุณ
ทางเลือกในรูทของพื้นที่เก็บข้อมูลนี้มีไฟล์ชื่อ delivery-api.http ที่ให้อินเทอร์เฟซที่ใช้งานง่ายสำหรับการดำเนินการปลายทางที่นำไปใช้
GET /healthสรุป : ตรวจสอบสถานะสุขภาพของ API
คำตอบ :
200 ตกลง
" Database connection is healthy. "503 บริการไม่พร้อมใช้งาน
" Database connection isn't available. "500 ข้อผิดพลาดเซิร์ฟเวอร์ภายใน
" An error occurred while checking the database connection. "GET /productsสรุป : ดึงผลิตภัณฑ์ทั้งหมด
คำตอบ :
[
{
"id" : 1 ,
"name" : " Product Name " ,
"unitOfMeasurement" : " UN " ,
"price" : 9.99
}
]GET /products/{id}สรุป : ดึงผลิตภัณฑ์ด้วย ID
พารามิเตอร์ :
id (จำนวนเต็ม): ID ของผลิตภัณฑ์เพื่อดึงข้อมูลคำตอบ :
200 ตกลง
{
"id" : 1 ,
"name" : " Product Name " ,
"unitOfMeasurement" : " UN " ,
"price" : 9.99
}ไม่พบ 404
{
"message" : " Product with ID {id} not found. "
}POST /productsสรุป : สร้างผลิตภัณฑ์ใหม่
ขอร่าง :
{
"name" : " Product Name " ,
"unitOfMeasurement" : " Unit " ,
"price" : 9.99
}คำตอบ :
201 สร้างขึ้น
{
"id" : 1 ,
"name" : " Product Name " ,
"unitOfMeasurement" : " Unit " ,
"price" : 9.99
}400 คำขอไม่ดี
{
"message" : " Validation error messages "
}PUT /products/{id}สรุป : อัปเดตผลิตภัณฑ์ที่มีอยู่
พารามิเตอร์ :
id (จำนวนเต็ม): ID ของผลิตภัณฑ์ที่จะอัปเดตขอร่าง :
{
"name" : " Updated Product Name " ,
"unitOfMeasurement" : " Updated Unit " ,
"price" : 9.99
}คำตอบ :
200 ตกลง
{
"id" : 1 ,
"name" : " Updated Product Name " ,
"unitOfMeasurement" : " Updated Unit " ,
"price" : 9.99
}400 คำขอไม่ดี
{
"message" : " Validation error messages "
}ไม่พบ 404
{
"message" : " Product with ID {id} not found. "
}DELETE /products/{id}สรุป : ลบผลิตภัณฑ์ด้วย ID
พารามิเตอร์ :
id (จำนวนเต็ม): ID ของผลิตภัณฑ์ที่จะลบคำตอบ :
204 ไม่มีเนื้อหา
400 คำขอไม่ดี
{
"message" : " Error message "
}ไม่พบ 404
{
"message" : " Product with ID {id} not found. "
}409 ความขัดแย้ง
{
"message" : " Cannot delete the product as it has associated sale items. "
}GET /salesสรุป : ดึงยอดขายทั้งหมด (ประวัติศาสตร์)
คำตอบ :
[
{
"id" : 1 ,
"saleDate" : " 2024-08-14T00:00:00Z " ,
"totalAmount" : 100.00 ,
"saleItems" : [
{
"id" : 1 ,
"productId" : 1 ,
"quantity" : 2 ,
"unitPrice" : 50.00
}
]
}
]GET /sales/{id}สรุป : ดึงการขายโดย ID
พารามิเตอร์ :
id (จำนวนเต็ม): ID ของการขายเพื่อเรียกคืนคำตอบ :
200 ตกลง
{
"id" : 1 ,
"saleDate" : " 2024-08-14T00:00:00Z " ,
"totalAmount" : 100.00 ,
"saleItems" : [
{
"id" : 1 ,
"productId" : 1 ,
"quantity" : 2 ,
"unitPrice" : 50.00
}
]
}ไม่พบ 404
{
"message" : " Sale with ID {id} not found. "
}POST /salesสรุป : สร้างการขายใหม่
ขอร่าง :
{
"saleDate" : " 2024-08-14T00:00:00Z " ,
"zipCode" : " 12345678 " ,
"saleItems" : [
{
"productId" : 1 ,
"quantity" : 2
}
]
}คำตอบ :
201 สร้างขึ้น
{
"id" : 1 ,
"saleDate" : " 2024-08-14T00:00:00Z " ,
"totalAmount" : 100.00 ,
"saleItems" : [
{
"id" : 1 ,
"productId" : 1 ,
"quantity" : 2 ,
"unitPrice" : 50.00 ,
"product" : {
"id" : 1 ,
"name" : " Product Name " ,
"unitOfMeasurement" : " Unit " ,
"price" : 50.00
}
}
]
}400 คำขอไม่ดี
{
"message" : " Validation error messages "
}DELETE /sales/{id}สรุป : ลบ (ยกเลิก) การขายตามรหัส
พารามิเตอร์ :
id (จำนวนเต็ม): ID ของการขายเพื่อลบคำตอบ :
204 ไม่มีเนื้อหา
400 คำขอไม่ดี
{
"message" : " Error message "
}ไม่พบ 404
{
"message" : " Sale with ID {id} not found. "
}