Phase 3
This commit is contained in:
parent
9321f5a370
commit
25c2ce53cd
23 changed files with 1746 additions and 68 deletions
|
|
@ -10,10 +10,11 @@ public class Document
|
|||
/// <summary>ค่า custom property `SavedByAddIn` ที่ stamp ไว้ในไฟล์ (FR-1)</summary>
|
||||
public string AddInSignature { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>เอกสารที่สร้างจาก template (FR-10) — null ถ้า track เอกสารเปล่า
|
||||
/// (Phase 3 จะเติม FK ไป Template เมื่อมี entity)</summary>
|
||||
/// <summary>เอกสารที่สร้างจาก template (FR-10) — null ถ้า track เอกสารเปล่า</summary>
|
||||
public Guid? TemplateId { get; set; }
|
||||
|
||||
public Template? Template { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public List<DocumentVersion> Versions { get; set; } = new();
|
||||
|
|
|
|||
20
backend/WordVersioning.Api/Models/DocumentFieldValue.cs
Normal file
20
backend/WordVersioning.Api/Models/DocumentFieldValue.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
namespace WordVersioning.Api.Models;
|
||||
|
||||
/// <summary>ค่าล่าสุดต่อ field ของ document (FR-11) — PK คือ (DocumentId, FieldKey)</summary>
|
||||
public class DocumentFieldValue
|
||||
{
|
||||
public Guid DocumentId { get; set; }
|
||||
|
||||
public string FieldKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>เก็บเป็น string ทุก type (number/date ก็ตามที่ผู้ใช้กรอก/extract มา)</summary>
|
||||
public string Value { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>version ล่าสุดที่อัปเดตค่านี้</summary>
|
||||
public Guid SourceVersionId { get; set; }
|
||||
|
||||
/// <summary>จาก claim `sub` ของผู้กด Save & Version / ผู้ generate</summary>
|
||||
public string UpdatedByUserId { get; set; } = string.Empty;
|
||||
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
}
|
||||
25
backend/WordVersioning.Api/Models/Template.cs
Normal file
25
backend/WordVersioning.Api/Models/Template.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
namespace WordVersioning.Api.Models;
|
||||
|
||||
/// <summary>Template เอกสาร .docx ที่มี content controls (FR-9) — ไฟล์เก็บใน MinIO bucket docx-templates</summary>
|
||||
public class Template
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>MinIO object key ใน bucket docx-templates (เปลี่ยนทุกครั้งที่ replace ไฟล์)</summary>
|
||||
public string ObjectKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>soft-delete flag — ห้ามลบแถวจริงเพราะ document เก่ายังอ้าง TemplateId อยู่</summary>
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
public List<TemplateField> Fields { get; set; } = new();
|
||||
|
||||
public List<Document> Documents { get; set; } = new();
|
||||
}
|
||||
81
backend/WordVersioning.Api/Models/TemplateDtos.cs
Normal file
81
backend/WordVersioning.Api/Models/TemplateDtos.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
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";
|
||||
|
||||
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, 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);
|
||||
27
backend/WordVersioning.Api/Models/TemplateField.cs
Normal file
27
backend/WordVersioning.Api/Models/TemplateField.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
namespace WordVersioning.Api.Models;
|
||||
|
||||
/// <summary>นิยาม field หนึ่งตัวของ template (FR-9) — Key = content control (SDT) tag ที่ detect ตอน upload</summary>
|
||||
public class TemplateField
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid TemplateId { get; set; }
|
||||
|
||||
public Template? Template { get; set; }
|
||||
|
||||
/// <summary>= SDT tag — unique ต่อ template ใช้ค่าเดียวกันทั้ง generate/extract/sync</summary>
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>ชื่อที่แสดงในฟอร์ม (default = Key จนกว่า admin จะตั้ง)</summary>
|
||||
public string Label { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>text | number | date</summary>
|
||||
public string Type { get; set; } = "text";
|
||||
|
||||
public bool IsRequired { get; set; }
|
||||
|
||||
/// <summary>ลำดับตอนแสดงฟอร์ม (default = ลำดับที่ปรากฏในไฟล์ตอน detect)</summary>
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
public static readonly string[] ValidTypes = ["text", "number", "date"];
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace WordVersioning.Api.Models;
|
||||
|
||||
|
|
@ -12,12 +13,24 @@ public class UploadVersionRequest
|
|||
[Required]
|
||||
public string ClientVersionId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>JSON object map tag→text จาก content controls (FR-11 — Phase 3 จะใช้ sync เต็มรูปแบบ)</summary>
|
||||
/// <summary>JSON object map tag→text จาก content controls (FR-11)</summary>
|
||||
public string? Fields { get; set; }
|
||||
}
|
||||
|
||||
public record UploadVersionResponse(Guid VersionId, int VersionNumber);
|
||||
|
||||
/// <summary>body ของ POST /api/documents/generate (FR-10)</summary>
|
||||
public class GenerateDocumentRequest
|
||||
{
|
||||
[Required]
|
||||
public Guid TemplateId { get; set; }
|
||||
|
||||
/// <summary>map fieldKey → value (ค่า scalar ทั้งหมด)</summary>
|
||||
public JsonElement Values { get; set; }
|
||||
}
|
||||
|
||||
public record GenerateDocumentResponse(Guid DocumentId, Guid VersionId, int VersionNumber, string DownloadUrl);
|
||||
|
||||
/// <summary>item ของ version history — fields คือ snapshot ที่ parse แล้ว (ถ้ามี)</summary>
|
||||
public record VersionListItem(
|
||||
Guid VersionId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue