Files
sam-api/app/Swagger/v1/ClientGroupApi.php
hskwon c5ea6d189a feat: Swagger 문서 전면 수정 및 ClientGroup 자동 복원 기능 추가
- CommonComponents.php: ApiResponse/ErrorResponse 글로벌 스키마 수정
  - property="status" → property="success" (boolean)
  - property="data" → property="error" (object with code/details)

- AuthApi, AdminApi, UserApi: 개별 응답 스키마 수정
  - signup(): allOf 구조로 변경
  - index(): Laravel LengthAwarePaginator 구조 적용
  - updateMe(): Member schema 참조로 변경

- PermissionApi, MaterialApi, DepartmentApi: 로컬 스키마 재정의 제거

- ClientGroupService: 삭제된 데이터 자동 복원 기능 구현
  - store(): withTrashed()로 삭제된 데이터 확인 후 restore()
  - update(): 삭제된 코드 존재 시 에러 반환

- ClientApi: client_group_id 필드 추가
  - Client, ClientCreateRequest, ClientUpdateRequest 스키마에 추가

- lang/ko/error.php, lang/en/error.php: 에러 메시지 추가
  - duplicate_code, has_clients, code_exists_in_deleted

- Swagger 문서 재생성 및 검증 완료
2025-10-14 09:10:52 +09:00

177 lines
7.8 KiB
PHP

<?php
namespace App\Swagger\v1;
/**
* @OA\Tag(name="ClientGroup", description="고객 그룹 관리")
*
* @OA\Schema(
* schema="ClientGroup",
* type="object",
* required={"id","group_code","group_name","price_rate"},
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="tenant_id", type="integer", example=1),
* @OA\Property(property="group_code", type="string", example="VIP"),
* @OA\Property(property="group_name", type="string", example="VIP 고객"),
* @OA\Property(property="price_rate", type="number", format="decimal", example=0.9, description="가격 배율 (1.0=기준가, 0.9=90%, 1.1=110%)"),
* @OA\Property(property="is_active", type="boolean", example=true),
* @OA\Property(property="created_at", type="string", example="2025-10-01 12:00:00"),
* @OA\Property(property="updated_at", type="string", example="2025-10-01 12:00:00")
* )
*
* @OA\Schema(
* schema="ClientGroupPagination",
* type="object",
* @OA\Property(property="current_page", type="integer", example=1),
* @OA\Property(
* property="data",
* type="array",
* @OA\Items(ref="#/components/schemas/ClientGroup")
* ),
* @OA\Property(property="first_page_url", type="string", example="/api/v1/client-groups?page=1"),
* @OA\Property(property="from", type="integer", example=1),
* @OA\Property(property="last_page", type="integer", example=3),
* @OA\Property(property="last_page_url", type="string", example="/api/v1/client-groups?page=3"),
* @OA\Property(
* property="links",
* type="array",
* @OA\Items(type="object",
* @OA\Property(property="url", type="string", nullable=true, example=null),
* @OA\Property(property="label", type="string", example="&laquo; Previous"),
* @OA\Property(property="active", type="boolean", example=false)
* )
* ),
* @OA\Property(property="next_page_url", type="string", nullable=true, example="/api/v1/client-groups?page=2"),
* @OA\Property(property="path", type="string", example="/api/v1/client-groups"),
* @OA\Property(property="per_page", type="integer", example=20),
* @OA\Property(property="prev_page_url", type="string", nullable=true, example=null),
* @OA\Property(property="to", type="integer", example=20),
* @OA\Property(property="total", type="integer", example=50)
* )
*
* @OA\Schema(
* schema="ClientGroupCreateRequest",
* type="object",
* required={"group_code","group_name","price_rate"},
* @OA\Property(property="group_code", type="string", maxLength=30, example="VIP", description="그룹 코드"),
* @OA\Property(property="group_name", type="string", maxLength=100, example="VIP 고객", description="그룹명"),
* @OA\Property(property="price_rate", type="number", format="decimal", example=0.9, description="가격 배율 (1.0=기준가)"),
* @OA\Property(property="is_active", type="boolean", example=true, description="활성 여부")
* )
*
* @OA\Schema(
* schema="ClientGroupUpdateRequest",
* type="object",
* @OA\Property(property="group_code", type="string", maxLength=30),
* @OA\Property(property="group_name", type="string", maxLength=100),
* @OA\Property(property="price_rate", type="number", format="decimal"),
* @OA\Property(property="is_active", type="boolean")
* )
*/
class ClientGroupApi
{
/**
* @OA\Get(
* path="/api/v1/client-groups",
* tags={"ClientGroup"},
* summary="고객 그룹 목록",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="page", in="query", @OA\Schema(type="integer", example=1)),
* @OA\Parameter(name="size", in="query", @OA\Schema(type="integer", example=20)),
* @OA\Parameter(name="q", in="query", description="그룹 코드/이름 검색", @OA\Schema(type="string")),
* @OA\Parameter(name="only_active", in="query", @OA\Schema(type="boolean")),
* @OA\Response(response=200, description="조회 성공",
* @OA\JsonContent(allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/ClientGroupPagination"))
* })
* ),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function index() {}
/**
* @OA\Get(
* path="/api/v1/client-groups/{id}",
* tags={"ClientGroup"},
* summary="고객 그룹 단건 조회",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", 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/ClientGroup"))
* })
* ),
* @OA\Response(response=404, description="데이터 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function show() {}
/**
* @OA\Post(
* path="/api/v1/client-groups",
* tags={"ClientGroup"},
* summary="고객 그룹 생성",
* description="고객 그룹을 생성합니다. 같은 group_code로 이전에 삭제된 그룹이 있으면 자동으로 복원하고 새 데이터로 업데이트합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\RequestBody(required=true, @OA\JsonContent(ref="#/components/schemas/ClientGroupCreateRequest")),
* @OA\Response(response=200, description="생성 성공 (또는 삭제된 데이터 복원)",
* @OA\JsonContent(allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/ClientGroup"))
* })
* ),
* @OA\Response(response=400, description="검증 실패 또는 중복 코드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function store() {}
/**
* @OA\Put(
* path="/api/v1/client-groups/{id}",
* tags={"ClientGroup"},
* 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/ClientGroupUpdateRequest")),
* @OA\Response(response=200, description="수정 성공",
* @OA\JsonContent(allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/ClientGroup"))
* })
* )
* )
*/
public function update() {}
/**
* @OA\Delete(
* path="/api/v1/client-groups/{id}",
* tags={"ClientGroup"},
* summary="고객 그룹 삭제(soft)",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Response(response=200, description="삭제 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse"))
* )
*/
public function destroy() {}
/**
* @OA\Patch(
* path="/api/v1/client-groups/{id}/toggle",
* tags={"ClientGroup"},
* summary="활성/비활성 토글",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", 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/ClientGroup"))
* })
* )
* )
*/
public function toggle() {}
}