Files
sam-api/app/Swagger/v1/CategoryExtras.php
hskwon d4e9f2a6e4 refactor: CategoryField API를 SAM API Rules에 맞게 리팩토링
- FormRequest 패턴 적용 (CategoryFieldStoreRequest, CategoryFieldUpdateRequest)
- Service에서 Validator::make() 제거
- Controller 메시지 i18n 키로 변경 (__('message.category_field.*'))
- is_required 타입을 'Y'/'N' → boolean으로 통일
- Swagger 스키마 is_required boolean 타입으로 업데이트
- Model scopeRequired() boolean 조건으로 변경
2025-11-14 13:45:54 +09:00

658 lines
23 KiB
PHP

<?php
namespace App\Swagger\v1;
/**
* @OA\Tag(name="Category-Fields", description="카테고리별 동적 필드 관리")
* @OA\Tag(name="Category-Templates", description="카테고리 템플릿 버전 관리")
* @OA\Tag(name="Category-Logs", description="카테고리 변경 이력 조회")
*/
/**
* =========================
* ===== Schemas ========
* =========================
*/
/**
* @OA\Schema(
* schema="CategoryField",
* type="object",
* required={"id","tenant_id","category_id","field_key","field_name","field_type"},
*
* @OA\Property(property="id", type="integer", example=11),
* @OA\Property(property="tenant_id", type="integer", example=1),
* @OA\Property(property="category_id", type="integer", example=7),
* @OA\Property(property="field_key", type="string", example="width"),
* @OA\Property(property="field_name", type="string", example="폭(mm)"),
* @OA\Property(property="field_type", type="string", example="number"),
* @OA\Property(property="is_required", type="boolean", example=false),
* @OA\Property(property="sort_order", type="integer", example=1),
* @OA\Property(property="default_value", type="string", nullable=true, example=null),
* @OA\Property(
* property="options",
* type="object",
* nullable=true,
* description="선택지(콤보박스 등)",
* example={"units": {"mm","cm","m"}}
* ),
* @OA\Property(property="description", type="string", nullable=true, example=null),
* @OA\Property(property="created_at", type="string", format="date-time", example="2025-08-25 10:00:00"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-08-25 10:20:00")
* )
*
* @OA\Schema(
* schema="CategoryFieldPagination",
* type="object",
*
* @OA\Property(property="current_page", type="integer", example=1),
* @OA\Property(
* property="data",
* type="array",
*
* @OA\Items(ref="#/components/schemas/CategoryField")
* ),
*
* @OA\Property(property="per_page", type="integer", example=20),
* @OA\Property(property="total", type="integer", example=3)
* )
*
* @OA\Schema(
* schema="CategoryFieldCreateRequest",
* type="object",
* required={"field_key","field_name","field_type"},
*
* @OA\Property(property="field_key", type="string", example="height"),
* @OA\Property(property="field_name", type="string", example="높이(mm)"),
* @OA\Property(property="field_type", type="string", example="number"),
* @OA\Property(property="is_required", type="string", enum={"Y","N"}, example="N"),
* @OA\Property(property="sort_order", type="integer", example=2),
* @OA\Property(property="default_value", type="string", nullable=true, example=null),
* @OA\Property(
* property="options",
* type="object",
* nullable=true,
* example={"min": 0, "max": 9999, "step": 1}
* ),
* @OA\Property(property="description", type="string", nullable=true, example="선택 입력")
* )
*
* @OA\Schema(
* schema="CategoryFieldUpdateRequest",
* type="object",
*
* @OA\Property(property="field_key", type="string", example="height"),
* @OA\Property(property="field_name", type="string", example="높이(mm)"),
* @OA\Property(property="field_type", type="string", example="number"),
* @OA\Property(property="is_required", type="string", enum={"Y","N"}, example="Y"),
* @OA\Property(property="sort_order", type="integer", example=1),
* @OA\Property(property="default_value", type="string", nullable=true, example=null),
* @OA\Property(
* property="options",
* type="object",
* nullable=true,
* example={"min": 0, "max": 9999, "step": 1}
* ),
* @OA\Property(property="description", type="string", nullable=true, example=null)
* )
*
* @OA\Schema(
* schema="CategoryFieldReorderRequest",
* type="array",
*
* @OA\Items(
* type="object",
* required={"id","sort_order"},
*
* @OA\Property(property="id", type="integer", example=11),
* @OA\Property(property="sort_order", type="integer", example=1)
* )
* )
*
* @OA\Schema(
* schema="CategoryFieldBulkUpsertRequest",
* type="object",
* required={"items"},
*
* @OA\Property(
* property="items",
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(property="id", type="integer", nullable=true, example=null),
* @OA\Property(property="field_key", type="string", example="thickness"),
* @OA\Property(property="field_name", type="string", example="두께(mm)"),
* @OA\Property(property="field_type", type="string", example="number"),
* @OA\Property(property="is_required", type="string", enum={"Y","N"}, example="N"),
* @OA\Property(property="sort_order", type="integer", example=3),
* @OA\Property(property="default_value", type="string", nullable=true, example=null),
* @OA\Property(property="options", type="object", nullable=true, example={"unit":"mm"}),
* @OA\Property(property="description", type="string", nullable=true, example=null)
* )
* )
* )
*
* @OA\Schema(
* schema="CategoryTemplate",
* type="object",
* required={"id","tenant_id","category_id","version_no","template_json","applied_at"},
*
* @OA\Property(property="id", type="integer", example=1001),
* @OA\Property(property="tenant_id", type="integer", example=1),
* @OA\Property(property="category_id", type="integer", example=7),
* @OA\Property(property="version_no", type="integer", example=3),
* @OA\Property(
* property="template_json",
* type="object",
* description="템플릿 스냅샷",
* example={"fields": {{"key":"width","type":"number","required":true}}}
* ),
* @OA\Property(property="applied_at", type="string", format="date-time", example="2025-08-25 11:00:00"),
* @OA\Property(property="remarks", type="string", nullable=true, example="높이 필드 추가"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2025-08-25 10:50:00"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-08-25 11:05:00")
* )
*
* @OA\Schema(
* schema="CategoryTemplateCreateRequest",
* type="object",
* required={"version_no","template_json","applied_at"},
*
* @OA\Property(property="version_no", type="integer", example=4),
* @OA\Property(
* property="template_json",
* type="object",
* example={
* "fields": {
* {"key":"width","type":"number","required":true},
* {"key":"height","type":"number","required":false}
* }
* }
* ),
* @OA\Property(property="applied_at", type="string", format="date-time", example="2025-08-25 13:00:00"),
* @OA\Property(property="remarks", type="string", nullable=true, example="높이 추가 버전")
* )
*
* @OA\Schema(
* schema="CategoryTemplateUpdateRequest",
* type="object",
*
* @OA\Property(
* property="template_json",
* type="object",
* example={"fields": {{"key":"width","type":"number"}}}
* ),
* @OA\Property(property="applied_at", type="string", format="date-time", example="2025-08-26 09:00:00"),
* @OA\Property(property="remarks", type="string", nullable=true, example="비고 수정")
* )
*
* @OA\Schema(
* schema="CategoryLog",
* type="object",
* required={"id","tenant_id","category_id","action","changed_at"},
*
* @OA\Property(property="id", type="integer", example=501),
* @OA\Property(property="tenant_id", type="integer", example=1),
* @OA\Property(property="category_id", type="integer", example=7),
* @OA\Property(property="action", type="string", example="update"),
* @OA\Property(property="changed_by", type="integer", nullable=true, example=1),
* @OA\Property(property="changed_at", type="string", format="date-time", example="2025-08-25 14:00:00"),
* @OA\Property(property="before_json", type="object", nullable=true, example={"name":"old"}),
* @OA\Property(property="after_json", type="object", nullable=true, example={"name":"new"}),
* @OA\Property(property="remarks", type="string", nullable=true, example=null)
* )
*/
class CategoryExtras
{
/**
* ===============================
* ==== Category Field APIs ======
* ===============================
*/
/**
* @OA\Get(
* path="/api/v1/categories/{id}/fields",
* tags={"Category-Fields"},
* summary="카테고리별 필드 목록",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer"), description="카테고리 ID"),
* @OA\Parameter(ref="#/components/parameters/Page"),
* @OA\Parameter(ref="#/components/parameters/Size"),
* @OA\Parameter(name="sort", in="query", @OA\Schema(type="string", example="sort_order")),
* @OA\Parameter(name="order", in="query", @OA\Schema(type="string", enum={"asc","desc"}, example="asc")),
*
* @OA\Response(
* response=200,
* description="목록 조회 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryFieldPagination"))
* })
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function fieldsIndex() {}
/**
* @OA\Post(
* path="/api/v1/categories/{id}/fields",
* tags={"Category-Fields"},
* summary="카테고리 필드 생성",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/CategoryFieldCreateRequest")),
*
* @OA\Response(
* response=200,
* description="생성 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryField"))
* })
* ),
*
* @OA\Response(response=400, description="검증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function fieldsStore() {}
/**
* @OA\Get(
* path="/api/v1/categories/fields/{field}",
* tags={"Category-Fields"},
* summary="카테고리 필드 단건 조회",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="field", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryField"))
* })
* ),
*
* @OA\Response(response=404, description="없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function fieldsShow() {}
/**
* @OA\Patch(
* path="/api/v1/categories/fields/{field}",
* tags={"Category-Fields"},
* summary="카테고리 필드 수정",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="field", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/CategoryFieldUpdateRequest")),
*
* @OA\Response(
* response=200,
* description="수정 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryField"))
* })
* )
* )
*/
public function fieldsUpdate() {}
/**
* @OA\Delete(
* path="/api/v1/categories/fields/{field}",
* tags={"Category-Fields"},
* summary="카테고리 필드 삭제",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="field", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="삭제 성공",
*
* @OA\JsonContent(ref="#/components/schemas/ApiResponse")
* )
* )
*/
public function fieldsDestroy() {}
/**
* @OA\Post(
* path="/api/v1/categories/{id}/fields/reorder",
* tags={"Category-Fields"},
* summary="카테고리 필드 정렬 저장",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/CategoryFieldReorderRequest")),
*
* @OA\Response(response=200, description="저장 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse"))
* )
*/
public function fieldsReorder() {}
/**
* @OA\Put(
* path="/api/v1/categories/{id}/fields/bulk-upsert",
* tags={"Category-Fields"},
* summary="카테고리 필드 일괄 업서트",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/CategoryFieldBulkUpsertRequest")),
*
* @OA\Response(
* response=200,
* description="업서트 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", type="object",
* @OA\Property(property="created", type="integer", example=2),
* @OA\Property(property="updated", type="integer", example=3)
* )
* )
* })
* )
* )
*/
public function fieldsBulkUpsert() {}
/**
* ==================================
* ==== Category Template APIs =====
* ==================================
*/
/**
* @OA\Get(
* path="/api/v1/categories/{id}/templates",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 버전 목록",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(ref="#/components/parameters/Page"),
* @OA\Parameter(ref="#/components/parameters/Size"),
*
* @OA\Response(
* response=200,
* description="목록 조회 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(
* property="data",
* type="array",
*
* @OA\Items(ref="#/components/schemas/CategoryTemplate")
* ),
*
* @OA\Property(property="total", type="integer", example=3)
* )
* )
* })
* )
* )
*/
public function templatesIndex() {}
/**
* @OA\Post(
* path="/api/v1/categories/{id}/templates",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 생성(새 버전)",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/CategoryTemplateCreateRequest")),
*
* @OA\Response(
* response=200,
* description="생성 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryTemplate"))
* })
* ),
*
* @OA\Response(response=409, description="버전 중복", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function templatesStore() {}
/**
* @OA\Get(
* path="/api/v1/categories/templates/{tpl}",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 단건 조회",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="tpl", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryTemplate"))
* })
* )
* )
*/
public function templatesShow() {}
/**
* @OA\Patch(
* path="/api/v1/categories/templates/{tpl}",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 수정",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="tpl", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/CategoryTemplateUpdateRequest")),
*
* @OA\Response(
* response=200,
* description="수정 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryTemplate"))
* })
* )
* )
*/
public function templatesUpdate() {}
/**
* @OA\Delete(
* path="/api/v1/categories/templates/{tpl}",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 삭제",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="tpl", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(response=200, description="삭제 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse"))
* )
*/
public function templatesDestroy() {}
/**
* @OA\Post(
* path="/api/v1/categories/{id}/templates/{tpl}/apply",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 적용(활성화)",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(name="tpl", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(response=200, description="적용 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse"))
* )
*/
public function templatesApply() {}
/**
* @OA\Get(
* path="/api/v1/categories/{id}/templates/{tpl}/preview",
* tags={"Category-Templates"},
* summary="카테고리 템플릿 미리보기",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(name="tpl", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="미리보기 성공",
*
* @OA\JsonContent(allOf={@OA\Schema(ref="#/components/schemas/ApiResponse")})
* )
* )
*/
public function templatesPreview() {}
/**
* @OA\Get(
* path="/api/v1/categories/{id}/templates/diff",
* tags={"Category-Templates"},
* summary="두 버전 비교(diff)",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(name="a", in="query", required=true, @OA\Schema(type="integer"), description="비교 기준 버전"),
* @OA\Parameter(name="b", in="query", required=true, @OA\Schema(type="integer"), description="비교 대상 버전"),
*
* @OA\Response(
* response=200,
* description="비교 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(property="data", type="object",
* @OA\Property(property="added", type="array", @OA\Items(type="string")),
* @OA\Property(property="removed", type="array", @OA\Items(type="string"))
* )
* )
* })
* )
* )
*/
public function templatesDiff() {}
/**
* ==============================
* ===== Category Log APIs =====
* ==============================
*/
/**
* @OA\Get(
* path="/api/v1/categories/{id}/logs",
* tags={"Category-Logs"},
* summary="카테고리 변경 이력 목록",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(name="action", in="query", @OA\Schema(type="string", enum={"insert","update","delete"})),
* @OA\Parameter(name="from", in="query", @OA\Schema(type="string", format="date")),
* @OA\Parameter(name="to", in="query", @OA\Schema(type="string", format="date")),
* @OA\Parameter(ref="#/components/parameters/Page"),
* @OA\Parameter(ref="#/components/parameters/Size"),
*
* @OA\Response(
* response=200,
* description="목록 조회 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(
* property="data",
* type="array",
*
* @OA\Items(ref="#/components/schemas/CategoryLog")
* ),
*
* @OA\Property(property="total", type="integer", example=12)
* )
* )
* })
* )
* )
*/
public function logsIndex() {}
/**
* @OA\Get(
* path="/api/v1/categories/logs/{log}",
* tags={"Category-Logs"},
* summary="카테고리 변경 이력 단건 조회",
* security={{"ApiKeyAuth": {}},{"BearerAuth": {}}},
*
* @OA\Parameter(name="log", in="path", required=true, @OA\Schema(type="integer")),
*
* @OA\Response(
* response=200,
* description="조회 성공",
*
* @OA\JsonContent(allOf={
*
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/CategoryLog"))
* })
* )
* )
*/
public function logsShow() {}
}