跳至主要内容

Scenario 3: 新增客戶備註

User Story: US-303: 客戶訂單歷史與統計

Given: 系統初始狀態

已登入用戶

{
"userId": "staff-001",
"name": "王店員"
}

現有客戶備註

[
{
"id": "note-001",
"content": "喜歡粉色玫瑰",
"createdAt": "2025-10-01T10:00:00Z",
"createdBy": {
"id": "staff-002",
"name": "張店員"
}
}
]

When: 執行操作

API 請求

POST /api/v1/customers/cust-001/notes
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json

{
"content": "不要百合花"
}

Then: 預期結果

1. HTTP 響應狀態碼

201 Created

2. 響應 Payload

{
"id": "note-002",
"content": "不要百合花",
"createdAt": "2025-11-04T10:00:00Z",
"createdBy": {
"id": "staff-001",
"name": "王店員"
}
}

3. 資料庫狀態變更

customer_notes 表新增記錄

{
"id": "note-002",
"customerId": "cust-001",
"content": "不要百合花",
"createdAt": "2025-11-04T10:00:00Z",
"createdBy": "staff-001"
}

4. 業務規則驗證

✅ 備註自動記錄時間與人員

  • 記錄時間: 當前時間(2025-11-04T10:00:00Z)
  • 記錄人: 當前用戶(staff-001 / 王店員)

✅ 備註為內部使用

  • 不顯示給客戶
  • 僅內部員工可查看

✅ 備註不可刪除

  • 僅支援新增
  • 歷史記錄保留

5. 審計日誌

{
"action": "ADD_CUSTOMER_NOTE",
"tenantId": "ROLE_FLORIST-abc",
"userId": "staff-001",
"resourceType": "customer",
"resourceId": "cust-001",
"details": {
"noteId": "note-002",
"content": "不要百合花"
},
"timestamp": "2025-11-04T10:00:00Z"
}

驗證重點

  • 備註成功新增
  • 時間與記錄人自動記錄
  • 備註列表正確顯示(時間降序)
  • 審計日誌正確記錄

相關場景