2026-08-19 12:15:20 +07:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2026-09-10 10:51:13 +07:00
|
|
|
using System.Text.Json;
|
2026-08-19 12:15:20 +07:00
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
2026-08-22 09:17:15 +07:00
|
|
|
/// <summary>editor ต่อ field (FR-14) — textbox|textarea ตาม type · ไม่ส่ง/ว่าง = default ของ type</summary>
|
|
|
|
|
public string? Editor { get; set; }
|
|
|
|
|
|
2026-08-19 12:15:20 +07:00
|
|
|
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!;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-10 10:51:13 +07:00
|
|
|
/// <summary>body ของ POST /api/templates/{id}/generate-draft (FR-16) — ไม่มี message เพราะไฟล์ร่างยังไม่เกิด version</summary>
|
|
|
|
|
public class GenerateDraftRequest
|
|
|
|
|
{
|
|
|
|
|
/// <summary>map fieldKey → value (ค่า scalar ทั้งหมด) — pattern เดียวกับ GenerateDocumentRequest</summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public JsonElement Values { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-10 11:49:16 +07:00
|
|
|
/// <summary>response ของ POST /api/templates/{id}/generate-draft (FR-16) — presigned URL อายุสั้น
|
|
|
|
|
/// ให้เว็บเปิดใน Word ผ่าน ms-word:ofe พร้อมลิงก์ดาวน์โหลดสำรอง (object ใต้ drafts/ หมดอายุรายวันตาม lifecycle)</summary>
|
|
|
|
|
public record GenerateDraftResponse(string Url, DateTimeOffset ExpiresAt);
|
|
|
|
|
|
2026-08-22 09:17:15 +07:00
|
|
|
public record TemplateFieldDto(Guid Id, string Key, string Label, string Type, string Editor, bool IsRequired, int SortOrder);
|
2026-08-19 12:15:20 +07:00
|
|
|
|
|
|
|
|
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);
|