Files
sam-api/app/Swagger/v1/AdminApi.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

357 lines
21 KiB
PHP

<?php
namespace App\Swagger\v1;
/**
* @OA\Tag(name="Admin-Users", description="관리자 전용 사용자 관리")
*/
class AdminApi
{
/**
* @OA\Get(
* path="/api/v1/admin/users",
* tags={"Admin-Users"},
* summary="사용자 목록",
* description="필터/검색/페이지네이션으로 사용자 목록을 조회합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="q", in="query", description="이름/이메일 검색어", @OA\Schema(type="string")),
* @OA\Parameter(name="tenant_id", in="query", description="특정 테넌트로 필터", @OA\Schema(type="integer", example=1)),
* @OA\Parameter(name="role", in="query", description="역할 코드", @OA\Schema(type="string", example="manager")),
* @OA\Parameter(name="is_active", in="query", description="활성여부", @OA\Schema(type="boolean", example=1)),
* @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="current_page", type="integer", example=1),
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/User")),
* @OA\Property(property="first_page_url", type="string", example="/api/v1/admin/users?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/admin/users?page=3"),
* @OA\Property(property="next_page_url", type="string", nullable=true, example="/api/v1/admin/users?page=2"),
* @OA\Property(property="path", type="string", example="/api/v1/admin/users"),
* @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\Response(response=400, description="필수 파라미터 누락", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function index() {}
/**
* @OA\Post(
* path="/api/v1/admin/users",
* tags={"Admin-Users"},
* summary="사용자 생성",
* description="새 사용자를 생성합니다. (초기 비밀번호/역할 포함 가능)",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* type="object",
* required={"name","email","password"},
* @OA\Property(property="user_id", type="string", example="test001"),
* @OA\Property(property="name", type="string", example="김관리"),
* @OA\Property(property="email", type="string", example="admin@kdcorp.co.kr"),
* @OA\Property(property="password", type="string", example="Init!2345"),
* @OA\Property(property="phone", type="string", example="010-3333-4444"),
* @OA\Property(property="roles", type="array", @OA\Items(type="string"), example={"manager"})
* )
* ),
* @OA\Response(
* response=201,
* description="생성됨",
* @OA\JsonContent(
* allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/User"))
* }
* )
* ),
* @OA\Response(response=400, description="필수 파라미터 누락", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=409, description="이메일 중복", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function store() {}
/**
* @OA\Get(
* path="/api/v1/admin/users/{id}",
* tags={"Admin-Users"},
* summary="사용자 단건 조회",
* description="ID 기준 사용자 상세",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer", example=101)),
* @OA\Response(
* response=200,
* description="조회 성공",
* @OA\JsonContent(
* allOf={@OA\Schema(ref="#/components/schemas/ApiResponse")},
* @OA\Schema(@OA\Property(property="data", ref="#/components/schemas/User"))
* )
* ),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function show() {}
/**
* @OA\Put(
* path="/api/v1/admin/users/{id}",
* tags={"Admin-Users"},
* summary="사용자 수정",
* description="이름/연락처/역할/활성여부 등 변경",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* type="object",
* @OA\Property(property="name", type="string", example="김관리"),
* @OA\Property(property="phone", type="string", example="010-3333-4444"),
* @OA\Property(property="is_active", type="integer", example=1),
* @OA\Property(property="roles", type="array", @OA\Items(type="string"), example={"manager","staff"})
* )
* ),
* @OA\Response(response=200, description="수정 성공", @OA\JsonContent(ref="#/components/schemas/ApiResponse")),
* @OA\Response(response=400, description="필수 파라미터 누락", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function update() {}
/**
* @OA\Patch(
* path="/api/v1/admin/users/{id}/status",
* tags={"Admin-Users"},
* summary="활성/비활성 전환",
* description="지정된 사용자의 is_active 상태를 변경합니다.",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="사용자 고유 ID",
* @OA\Schema(type="integer")
* ),
* @OA\Response(
* response=200,
* description="변경 성공",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="테넌트 사용자 활성/비활성 성공"),
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(property="is_active", type="integer", example=1)
* )
* )
* ),
* @OA\Response(response=400, description="필수 파라미터 누락", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function toggleStatus() {}
/**
* @OA\Delete(
* path="/api/v1/admin/users/{id}",
* tags={"Admin-Users"},
* summary="사용자 삭제(소프트 삭제)",
* description="deleted_at / deleted_by 기록",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Response(
* response=204,
* description="삭제성공",
* @OA\JsonContent(
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="변경 성공"),
* @OA\Property(property="data", type="string", example="Success")
* )
* ),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function destroy() {}
/**
* @OA\Post(
* path="/api/v1/admin/users/{id}/restore",
* tags={"Admin-Users"},
* summary="삭제 복구",
* description="소프트 삭제 복구",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Response(
* response=204,
* description="삭제 성공",
* @OA\JsonContent(
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="변경 성공"),
* @OA\Property(property="data", type="string", example="Success")
* )
* ),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function restore() {}
/**
* @OA\Post(
* path="/api/v1/admin/users/{id}/roles",
* tags={"Admin-Users"},
* summary="역할 부여",
* description="사용자에게 역할 추가",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\RequestBody(required=true,
* @OA\JsonContent(type="object",
* required={"roles"},
* @OA\Property(property="roles", type="array", @OA\Items(type="string"), example={"manager"})
* )
* ),
*
* @OA\Response(
* response=204,
* description="부여 성공",
* @OA\JsonContent(
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="변경 성공"),
* @OA\Property(property="data", type="object", nullable=true, example=null)
* )
* ),
* @OA\Response(response=400, description="필수 파라미터 누락", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=409, description="이메일/역할 중복 등 충돌", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function attachRoles() {}
/**
* @OA\Delete(
* path="/api/v1/admin/users/{id}/roles/{role}",
* tags={"Admin-Users"},
* summary="역할 해제",
* description="사용자에서 특정 역할 제거",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(name="role", in="path", required=true, @OA\Schema(type="string", example="manager")),
* @OA\Response(
* response=204,
* description="부여 성공",
* @OA\JsonContent(
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="변경 성공"),
* @OA\Property(property="data", type="object", nullable=true, example=null)
* )
* ),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=409, description="요청 충돌(없는 역할/이미 제거됨 등)", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function detachRole() {}
/**
* @OA\Post(
* path="/api/v1/admin/users/{id}/reset-password",
* tags={"Admin-Users"},
* summary="비밀번호 초기화",
* description="지정된 사용자의 비밀번호를 새 임시 비밀번호로 초기화합니다.
* - 관리자 권한 확인은 미들웨어/가드에서 처리됩니다.
* - 기본적으로 응답에 비밀번호를 노출하지 않으며, return_password=1일 때만 임시 비밀번호를 반환합니다(운영 환경에서는 노출 비권장).",
* security={{"ApiKeyAuth":{}},{"BearerAuth":{}}},
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="사용자 고유 ID",
* @OA\Schema(type="integer")
* ),
* @OA\RequestBody(
* required=false,
* @OA\JsonContent(
* type="object",
* @OA\Property(property="new_password", type="string", minLength=8, maxLength=64, example="Temp!1234", description="지정 시 해당 값으로 비밀번호 초기화, 미지정 시 서버에서 랜덤 생성"),
* @OA\Property(property="return_password", type="integer", enum={0,1}, example=0, description="1이면 응답에 임시 비밀번호 포함(개발/테스트용)")
* )
* ),
* @OA\Response(
* response=200,
* description="초기화 성공",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="테넌트 사용자 비밀번호 초기화 성공"),
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(property="status", type="string", example="ok"),
* @OA\Property(property="temp_password", type="string", example="Temp!1234", nullable=true, description="return_password=1일 때만 포함")
* )
* )
* ),
* @OA\Response(response=400, description="필수 파라미터 누락", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="존재하지 않는 URI 또는 데이터", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=405, description="허용되지 않는 메서드", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=409, description="요청 충돌(정책 위반 등)", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=500, description="서버 에러", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function resetPassword() {}
}