นิยามคุณสมบัติลูกค้า (Attribute Master)
ภาพรวม
Attribute Master คือจุดที่นิยาม custom attribute ของ LINE user แยกตาม LINE OA เช่น "ระดับสมาชิก" "วันเกิด" หรือ "สาขาที่ใช้บริการ" ทำหน้าที่เป็น schema ที่บอกระบบว่าแต่ละ attribute ชื่ออะไร เก็บข้อมูลชนิดใด นำไปใช้กรอง audience ได้หรือไม่ และแสดงในรายงานได้หรือไม่
attribute ที่นิยามไว้ที่นี่จะถูกนำไปใช้ต่อในหลายจุดทั่วระบบ ได้แก่ field ปลายทางของ Import Mapping, merge tag ของ Template Message, เงื่อนไขของ Audience Filter และคอลัมน์ของรายงานเพื่อนทั้งหมด
ฟีเจอร์ที่โดดเด่นคือ การนำเข้าจาก JSON schema ผู้ใช้วาง JSON ตัวอย่างเข้ามา แล้วระบบ parse ออกมาเป็นชุด attribute ให้ทันที ไม่ต้องนิยามทีละตัว
Business Flow
- ดูรายการ —
GET /api/attribute-masterคืน attribute ทั้งหมดแบบแบ่งหน้า กรองได้ตามAttributeMasterQueryParamDto - ดึงเฉพาะที่ใช้กรองได้ —
GET /api/attribute-master/filterableคืนเฉพาะ attribute ที่ใช้เป็นเงื่อนไขกรอง audience ได้ ใช้โดยหน้า Audience Filter - ดึงเฉพาะที่แสดงในรายงานได้ —
GET /api/attribute-master/reportableคืนเฉพาะ attribute ที่แสดงเป็นคอลัมน์รายงานได้ ใช้โดยหน้ารายงาน - สร้างใหม่ —
POST /api/attribute-masterสร้าง attribute ใหม่ โดยตรวจโควตาmaxAttributesตามแพ็กเกจก่อนเสมอ - แปลง JSON เป็น attribute —
POST /api/attribute-master/parse-jsonรับ body ที่มี fieldjsonและrootPath(ไม่บังคับ) แล้วคืน preview ว่าจะได้ attribute ใดบ้าง โดยยังไม่บันทึกลงฐานข้อมูล - ยืนยันนำเข้า —
POST /api/attribute-master/import-jsonสร้าง attribute จาก schema ที่ preview ไว้ทั้งชุดในครั้งเดียว - ดูรายละเอียดและแก้ไข —
GET /api/attribute-master/:idและPUT /api/attribute-master/:id - ตรวจก่อนลบ — ควรเรียก
GET /api/attribute-master/:id/check-attribute-usage?attributeKey=...ก่อนเสมอ เพื่อดูว่า attribute นี้ถูกใช้อยู่ที่ใดบ้าง ทั้งใน audience, รายงาน, ฟอร์ม และ import mapping จะได้ไม่ลบทิ้งจนทำให้ส่วนอื่นเสียหาย - ลบ —
DELETE /api/attribute-master/:id
ไฟล์และฟังก์ชันหลัก
โค้ดอยู่ที่ internal/modules/attributemaster/ ประกอบด้วย controller.go, service.go,
parser.go, ordered.go, time.go, dto.go และ module.go
parser.goทำหน้าที่ parse JSON schema เป็นชุด attributeordered.goรักษาลำดับ key เพื่อให้ผลลัพธ์ JSON ตรงกับระบบเดิม
Route ทั้งหมดลงทะเบียนบน authed.Group("/attribute-master") และครอบด้วย
modulegate.ModuleGate(d, "attribute-master")
| Method | Route | Handler | Policy |
|---|---|---|---|
| GET | /api/attribute-master | svc.getListHandler | readAll attribute-master |
| GET | /api/attribute-master/filterable | svc.getFilterableHandler | read attribute-master |
| GET | /api/attribute-master/reportable | svc.getReportableHandler | read attribute-master |
| GET | /api/attribute-master/:id/check-attribute-usage | svc.checkAttributeUsageHandler | read attribute-master |
| GET | /api/attribute-master/:id | svc.getByIDHandler | read attribute-master |
| POST | /api/attribute-master | svc.createHandler | create attribute-master |
| POST | /api/attribute-master/import-json | svc.importJsonHandler | create attribute-master |
| POST | /api/attribute-master/parse-json | svc.parseJsonHandler | read attribute-master |
| PUT | /api/attribute-master/:id | svc.updateHandler | update attribute-master |
| DELETE | /api/attribute-master/:id | svc.deleteHandler | delete attribute-master |
จุดเชื่อมต่อกับ Service อื่น
- Permission — ต้องผ่าน
ModuleGate("attribute-master")และมีPolicyModuleAttributeMasterเป็น metadata - ตารางที่เกี่ยวข้อง —
attribute_master,line_user(ในส่วน custom attribute),audience,form_builder,import_mapping_jobและtemplate_message - Cross-module — เรียกโมดูล Plan Limits เพื่อตรวจโควตา
maxAttributes - Error handling — ใช้
throwInstanceofErrorซึ่งปล่อย error 401, 404, 400 และ 409 ผ่านไปตามเดิม ส่วน error อื่นถูกแปลงเป็น 500 พร้อมรหัสAPP_000 - โมดูลที่เกี่ยวข้อง — System Attribute (attribute ระดับระบบ), LINE User Management, Audience Filter, Template Message, All Friend Listing และ Import Mapping