



Preview text:
I.
Thiết kế database : FireBase || Mongodb a. User o Id o Username: String o Password: String o
Role : String ( “admin”: ” user”) o Email: String o Phone: String o Address: { City: String Street: String } o CreatedAt : Timestamp o UpdatedAt : TimeStamp b. Devices o Id o Device_id: String o Type : String o Name: String o Location :{ Lat: “float” Long: “float” } c. Sensor_data o Id: o Device_id : o Sensor_Type : String o Value: Float o CreatedAt : TimeStamp d. Alerts: o Id o Device_id o Alert_type: String o Message : String o Is_resolved : Boolean o CreatedAt : TimeStamp o UpdatedAt: TimeStamp e. Payments: o Id o User_id: o Billing_period: { Start :Time End: Time } o Amount_due: Float o
Payment_status: String (pending, completed) o CreatedAt :TimeStamp f. Water_usage: o Id: o Device_id: o Volume: float o TimeStamp : TimeStamp II. Api a. Auth i. POST: /api/users/register Req.body :{ "username": "string", "password": "string", "email": "string", "phone": "string", "address": { "city": "string", "street": "string", "zipcode": "string" } } Res : code(201) Created ii. POST: /api/users/login { "username": "string", "password": "string" } iii. GET: /api/users/me Header: Authorization: Bearer
Res: Trả về các thông tin của người dùng trừ password b. Api Crud Devices i. POST /api/devices { "device_id": "string", "type": "sensor | actuator", "name": "string", "location": { "lat": "float", "long": "float" } } Res : code(201) Created ii. Get /api/devices
Headers: Authorization: Bearer
Res : trả về danh sách các thiết bị đã lắp của người dùng
iii. Cập nhật thông tin thiết bị iv. Xóa Thiết bị c. Api cho cảm biến i. POST /api/sensors { "device_id": "string",
"sensor_type": "temperature | ph | tds | turbidity", "value": "float", "timestamp": "ISODate" } ii. GET /api/sensors/real-time Query Params:
device_id: Lọc theo thiết bị
sensor_type: Lọc theo loại cảm biến
Res : Dữ liệu mới nhất từ thiết bị iii. GET /api/sensors/history Query Param: Device_id start end d. Api cho cảnh báo i. GET /api/alerts Query Params:
device_id: Lọc theo thiết bị
alert_type: Lọc theo loại cảnh báo
ii. POST /api/alerts - Thêm cảnh báo mới Req.body: { "device_id": "string",
"alert_type": "quality | leakage | high_usage", "message": "string", "timestamp": "ISODate" } Response 201 Created
iii. PUT /api/alerts/{id}/resolve - Cập nhật các cảnh báo đã được xử lý Response: 200 OK e. Payment Dùng api test của vnpay f.
Lấy dữ liệu sử dụng nguồn nước GET /api/water-usage Query Params:
device_id: Lọc theo thiết bị
start: Thời gian bắt đầu (ISODate)
end: Thời gian kết thúc (ISODate)
Response :Dữ liệu sử dụng nước của thiết bị.