eCourt-Doc-Edit/backend/WordVersioning.Api/Models/TemplateDtos.cs
Suphonchai Phoonsawat 9bb4a48c00 Phase 10: field editor (FR-14)
เพิ่ม editor ต่อ template field — ผู้ดูแลเลือกรูปแบบช่องกรอกในฟอร์มสร้างเอกสารได้:
text → textbox/textarea, number/date → control ตาม type (presentation metadata
ล้วน — validation ยังยึด Type, ค่า field เป็น string ทั้ง flow, ไม่แตะ generate/sync/add-in)

- Backend: TemplateField.Editor (nullable, null = default ของ type) +
  migration AddTemplateFieldEditor + validate ตาม type ใน PUT templates
  (ค่าไม่รู้จัก/ไม่เข้ากับ type → 400, normalize-on-write, API คืน resolved เสมอ)
- Web: util fieldEditor.ts + editor select หน้าแก้ template (desktop+mobile,
  ซ่อนเมื่อ type มีทางเดียว) + ฟอร์มสร้างเอกสาร render ตาม editor +
  แก้ prefill re-generate ของ field date จาก ISO timestamp เต็ม (input[type=date]
  รับเฉพาะ yyyy-MM-dd เดิมแสดงว่าง)
- Docs: spec v6 (FR-14/AC-17) + plan Phase 10 + sub-plan field-editor.md +
  acceptance-review AC-17 + README/CLAUDE.md
- Tests: backend 60/60 (FieldEditorTests ใหม่ 8 กรณี) · web 46/46 + build ผ่าน

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-22 09:17:15 +07:00

84 lines
2.9 KiB
C#

using System.ComponentModel.DataAnnotations;
namespace WordVersioning.Api.Models;
/// <summary>body ของ POST /api/templates (multipart/form-data)</summary>
public class CreateTemplateRequest
{
[Required]
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
[Required]
public IFormFile File { get; set; } = null!;
}
/// <summary>body ของ PUT /api/templates/{id} — Fields เป็น optional (ไม่ส่ง = แก้ metadata อย่างเดียว)</summary>
public class UpdateTemplateRequest
{
public string? Name { get; set; }
public string? Description { get; set; }
public bool? IsActive { get; set; }
public List<TemplateFieldDefinition>? Fields { get; set; }
}
/// <summary>นิยาม field หนึ่งตัวที่ admin ตั้ง — Key ต้องตรงกับที่ detect จากไฟล์ (เพิ่ม/ลบ key ต้องผ่าน replace ไฟล์)</summary>
public class TemplateFieldDefinition
{
[Required]
public string Key { get; set; } = string.Empty;
public string Label { get; set; } = string.Empty;
/// <summary>text | number | date</summary>
public string Type { get; set; } = "text";
/// <summary>editor ต่อ field (FR-14) — textbox|textarea ตาม type · ไม่ส่ง/ว่าง = default ของ type</summary>
public string? Editor { get; set; }
public bool IsRequired { get; set; }
public int SortOrder { get; set; }
}
/// <summary>body ของ PUT /api/templates/{id}/file (multipart/form-data)</summary>
public class ReplaceTemplateFileRequest
{
[Required]
public IFormFile File { get; set; } = null!;
}
public record TemplateFieldDto(Guid Id, string Key, string Label, string Type, string Editor, bool IsRequired, int SortOrder);
public record TemplateListItem(
Guid Id,
string Name,
string? Description,
bool IsActive,
int FieldCount,
DateTimeOffset CreatedAt,
DateTimeOffset UpdatedAt);
public record TemplateDetail(
Guid Id,
string Name,
string? Description,
bool IsActive,
DateTimeOffset CreatedAt,
DateTimeOffset UpdatedAt,
IReadOnlyList<TemplateFieldDto> Fields);
/// <summary>response ของ POST /api/templates — fields ที่ detect อัตโนมัติพร้อมค่า default
/// ให้ admin ไปตั้ง label/type/required ต่อผ่าน PUT (FR-9)</summary>
public record CreateTemplateResponse(Guid Id, IReadOnlyList<TemplateFieldDto> Fields);
/// <summary>response ของ PUT /api/templates/{id}/file — เตือน tag ที่หายไป/เพิ่มมาหลัง replace ไฟล์</summary>
public record ReplaceTemplateFileResponse(
Guid Id,
IReadOnlyList<TemplateFieldDto> Fields,
IReadOnlyList<string> AddedTags,
IReadOnlyList<string> RemovedTags);