{"openapi":"3.0.0","info":{"title":"AgriTech Marketplace API","version":"1.0.0","description":"API cho hệ thống quản lý nông sản, mùa vụ, truy xuất nguồn gốc,\nthương mại điện tử và logistics.\n"},"servers":[{"url":"http://localhost:5000/api","description":"Local Development"}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"ApiResponse":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"data":{"type":"object"}}},"User":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"fullName":{"type":"string"},"email":{"type":"string"},"phone":{"type":"string"},"role":{"type":"string","enum":["ADMIN","FARMER","SELLER","TRADER","CUSTOMER","DELIVERY"]},"avatar":{"type":"string"},"createdAt":{"type":"string","format":"date-time"}}},"Farm":{"type":"object","properties":{"id":{"type":"string"},"farmerId":{"type":"string"},"farmName":{"type":"string"},"description":{"type":"string"},"province":{"type":"string"},"district":{"type":"string"},"ward":{"type":"string"},"area":{"type":"number"},"latitude":{"type":"number"},"longitude":{"type":"number"},"createdAt":{"type":"string","format":"date-time"}}},"Product":{"type":"object","properties":{"id":{"type":"string"},"sellerId":{"type":"string"},"productName":{"type":"string"},"description":{"type":"string"},"price":{"type":"number"},"stockQuantity":{"type":"integer"},"thumbnail":{"type":"string"},"status":{"type":"string","enum":["ACTIVE","INACTIVE","OUT_OF_STOCK"]},"createdAt":{"type":"string","format":"date-time"}}},"Order":{"type":"object","properties":{"id":{"type":"string"},"customerId":{"type":"string"},"totalAmount":{"type":"number"},"shippingFee":{"type":"number"},"status":{"type":"string","enum":["PENDING_PAYMENT","PAID","PROCESSING","SHIPPING","DELIVERED","CANCELLED"]},"paymentMethod":{"type":"string"},"createdAt":{"type":"string","format":"date-time"}}},"Payment":{"type":"object","properties":{"id":{"type":"string"},"orderId":{"type":"string"},"amount":{"type":"number"},"paymentMethod":{"type":"string"},"transactionId":{"type":"string"},"status":{"type":"string","enum":["PENDING","SUCCESS","FAILED","REFUNDED"]}}}}},"security":[{"bearerAuth":[]}],"paths":{"/auth/register":{"post":{"tags":["Auth"],"summary":"Đăng ký tài khoản","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["fullName","email","password","role"],"properties":{"fullName":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"},"phone":{"type":"string"},"role":{"type":"string"}}}}}},"responses":{"201":{"description":"Register success","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/ApiResponse"},{"type":"object","properties":{"data":{"$ref":"#/components/schemas/User"}}}]}}}}}}},"/auth/login":{"post":{"tags":["Auth"],"summary":"Đăng nhập","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["email","password"],"properties":{"email":{"type":"string"},"password":{"type":"string"}}}}}},"responses":{"200":{"description":"Login success","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"token":{"type":"string"},"user":{"$ref":"#/components/schemas/User"}}}}}}}}},"/users/profile":{"get":{"tags":["Users"],"summary":"Lấy profile user hiện tại","responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}}}},"put":{"tags":["Users"],"summary":"Cập nhật profile","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"fullName":{"type":"string"},"phone":{"type":"string"},"avatar":{"type":"string"}}}}}},"responses":{"200":{"description":"Updated"}}}},"/farms":{"post":{"tags":["Farms"],"summary":"Tạo nông trại","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["farmName","province"],"properties":{"farmName":{"type":"string"},"description":{"type":"string"},"province":{"type":"string"},"district":{"type":"string"},"ward":{"type":"string"},"area":{"type":"number"},"latitude":{"type":"number"},"longitude":{"type":"number"}}}}}},"responses":{"201":{"description":"Farm created"}}},"get":{"tags":["Farms"],"summary":"Danh sách nông trại","parameters":[{"in":"query","name":"page","schema":{"type":"integer"}},{"in":"query","name":"limit","schema":{"type":"integer"}}],"responses":{"200":{"description":"Success"}}}},"/farms/{id}":{"get":{"tags":["Farms"],"summary":"Chi tiết nông trại","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Farm"}}}}}},"put":{"tags":["Farms"],"summary":"Update nông trại","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Farm"}}}},"responses":{"200":{"description":"Updated"}}},"delete":{"tags":["Farms"],"summary":"Xóa nông trại","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Deleted"}}}},"/farming-logs":{"post":{"tags":["Farming Logs"],"summary":"Tạo nhật ký canh tác","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["farmId","activityType"],"properties":{"farmId":{"type":"string"},"activityType":{"type":"string"},"description":{"type":"string"},"images":{"type":"array","items":{"type":"string"}}}}}}},"responses":{"201":{"description":"Created"}}},"get":{"tags":["Farming Logs"],"summary":"Danh sách nhật ký canh tác","responses":{"200":{"description":"Success"}}}},"/crop-lots":{"post":{"tags":["Crop Lots"],"summary":"Tạo lô cây trồng","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"farmId":{"type":"string"},"treeId":{"type":"string"},"plantedDate":{"type":"string","format":"date"},"expectedHarvestDate":{"type":"string","format":"date"}}}}}},"responses":{"201":{"description":"Created"}}}},"/harvests":{"post":{"tags":["Harvests"],"summary":"Tạo đợt thu hoạch","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"cropLotId":{"type":"string"},"quantity":{"type":"number"},"harvestedAt":{"type":"string","format":"date-time"}}}}}},"responses":{"201":{"description":"Harvest created"}}}},"/products":{"post":{"tags":["Products"],"summary":"Tạo sản phẩm","description":"Seller/Farmer tạo sản phẩm mới","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["productName","categoryId","price","stockQuantity"],"properties":{"productName":{"type":"string","example":"Xoài Cát Hòa Lộc"},"slug":{"type":"string","example":"xoai-cat-hoa-loc"},"description":{"type":"string"},"shortDescription":{"type":"string"},"categoryId":{"type":"string"},"farmId":{"type":"string"},"cropLotId":{"type":"string"},"sku":{"type":"string"},"price":{"type":"number"},"comparePrice":{"type":"number"},"stockQuantity":{"type":"integer"},"minOrderQuantity":{"type":"integer"},"weight":{"type":"number"},"unit":{"type":"string","example":"kg"},"thumbnail":{"type":"string"},"gallery":{"type":"array","items":{"type":"string"}},"tags":{"type":"array","items":{"type":"string"}},"isOrganic":{"type":"boolean"},"originProvince":{"type":"string"},"status":{"type":"string","enum":["DRAFT","ACTIVE","OUT_OF_STOCK"]}}}}}},"responses":{"201":{"description":"Product created","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"data":{"$ref":"#/components/schemas/Product"}}}}}}}},"get":{"tags":["Products"],"summary":"Danh sách sản phẩm","parameters":[{"in":"query","name":"page","schema":{"type":"integer"}},{"in":"query","name":"limit","schema":{"type":"integer"}},{"in":"query","name":"keyword","schema":{"type":"string"}},{"in":"query","name":"categoryId","schema":{"type":"string"}},{"in":"query","name":"minPrice","schema":{"type":"number"}},{"in":"query","name":"maxPrice","schema":{"type":"number"}},{"in":"query","name":"province","schema":{"type":"string"}},{"in":"query","name":"isOrganic","schema":{"type":"boolean"}},{"in":"query","name":"sortBy","schema":{"type":"string","enum":["newest","oldest","price_asc","price_desc","best_seller"]}}],"responses":{"200":{"description":"Product list"}}}},"/products/my-products":{"get":{"tags":["Products"],"summary":"Danh sách sản phẩm của seller hiện tại","responses":{"200":{"description":"Success"}}}},"/products/search/suggestions":{"get":{"tags":["Products"],"summary":"Search suggestions","parameters":[{"in":"query","name":"keyword","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Suggestions success"}}}},"/products/{id}":{"get":{"tags":["Products"],"summary":"Chi tiết sản phẩm","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Product detail","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"allOf":[{"$ref":"#/components/schemas/Product"},{"type":"object","properties":{"farm":{"type":"object"},"harvest":{"type":"object"},"reviews":{"type":"array","items":{"type":"object"}}}}]}}}}}}}},"put":{"tags":["Products"],"summary":"Update sản phẩm","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"productName":{"type":"string"},"description":{"type":"string"},"price":{"type":"number"},"stockQuantity":{"type":"integer"},"status":{"type":"string"}}}}}},"responses":{"200":{"description":"Product updated"}}},"delete":{"tags":["Products"],"summary":"Soft delete sản phẩm","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Product deleted"}}}},"/products/{id}/status":{"patch":{"tags":["Products"],"summary":"Đổi trạng thái sản phẩm","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["DRAFT","ACTIVE","OUT_OF_STOCK","HIDDEN"]}}}}}},"responses":{"200":{"description":"Status updated"}}}},"/products/{id}/inventory":{"patch":{"tags":["Products"],"summary":"Cập nhật tồn kho","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"type":{"type":"string","enum":["IMPORT","EXPORT","ADJUSTMENT"]},"quantity":{"type":"integer"},"note":{"type":"string"}}}}}},"responses":{"200":{"description":"Inventory updated"}}}},"/products/{id}/media":{"post":{"tags":["Products"],"summary":"Upload media sản phẩm","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"multipart/form-data":{"schema":{"type":"object","properties":{"files":{"type":"array","items":{"type":"string","format":"binary"}}}}}}},"responses":{"201":{"description":"Uploaded"}}}},"/products/{id}/reviews":{"get":{"tags":["Products"],"summary":"Danh sách đánh giá sản phẩm","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success"}}}},"/products/{id}/related":{"get":{"tags":["Products"],"summary":"Sản phẩm liên quan","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success"}}}},"/cart":{"get":{"tags":["Cart"],"summary":"Lấy giỏ hàng","responses":{"200":{"description":"Success"}}}},"/cart/items":{"post":{"tags":["Cart"],"summary":"Thêm sản phẩm vào giỏ","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["productId","quantity"],"properties":{"productId":{"type":"string"},"quantity":{"type":"integer"}}}}}},"responses":{"201":{"description":"Added to cart"}}}},"/orders":{"post":{"tags":["Orders"],"summary":"Tạo đơn hàng","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"addressId":{"type":"string"},"paymentMethod":{"type":"string"}}}}}},"responses":{"201":{"description":"Order created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Order"}}}}}},"get":{"tags":["Orders"],"summary":"Danh sách đơn hàng","responses":{"200":{"description":"Success"}}}},"/orders/{id}":{"get":{"tags":["Orders"],"summary":"Chi tiết đơn hàng","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success"}}}},"/orders/{id}/status":{"patch":{"tags":["Orders"],"summary":"Cập nhật trạng thái đơn hàng","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string"}}}}}},"responses":{"200":{"description":"Updated"}}}},"/payments":{"post":{"tags":["Payments"],"summary":"Thanh toán đơn hàng","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"orderId":{"type":"string"},"paymentMethod":{"type":"string"}}}}}},"responses":{"200":{"description":"Payment success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payment"}}}}}}},"/deliveries":{"post":{"tags":["Deliveries"],"summary":"Tạo vận chuyển","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"orderId":{"type":"string"},"deliveryPartner":{"type":"string"}}}}}},"responses":{"201":{"description":"Delivery created"}}}},"/deliveries/{id}/tracking":{"get":{"tags":["Deliveries"],"summary":"Tracking đơn hàng","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Tracking success"}}}},"/reviews":{"post":{"tags":["Reviews"],"summary":"Đánh giá sản phẩm","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"productId":{"type":"string"},"rating":{"type":"integer"},"comment":{"type":"string"}}}}}},"responses":{"201":{"description":"Review created"}}}},"/complaints":{"post":{"tags":["Complaints"],"summary":"Gửi khiếu nại","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"orderId":{"type":"string"},"reason":{"type":"string"},"description":{"type":"string"}}}}}},"responses":{"201":{"description":"Complaint created"}}}},"/purchase-requests":{"post":{"tags":["Trader"],"summary":"Trader gửi yêu cầu thu mua","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"farmId":{"type":"string"},"quantity":{"type":"number"},"offeredPrice":{"type":"number"}}}}}},"responses":{"201":{"description":"Created"}}}},"/negotiations/messages":{"post":{"tags":["Negotiations"],"summary":"Gửi tin nhắn thương lượng","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"negotiationId":{"type":"string"},"message":{"type":"string"}}}}}},"responses":{"201":{"description":"Message sent"}}}},"/qr-codes/{code}":{"get":{"tags":["QR Tracking"],"summary":"Truy xuất nguồn gốc bằng QR","parameters":[{"in":"path","name":"code","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Traceability success"}}}},"/notifications":{"get":{"tags":["Notifications"],"summary":"Danh sách thông báo","responses":{"200":{"description":"Success"}}}},"/admin/dashboard":{"get":{"tags":["Admin"],"summary":"Dashboard admin","responses":{"200":{"description":"Success"}}}},"/admin/users":{"get":{"tags":["Admin"],"summary":"Quản lý users","responses":{"200":{"description":"Success"}}}},"/admin/reports":{"get":{"tags":["Admin"],"summary":"Báo cáo hệ thống","responses":{"200":{"description":"Success"}}}}}}