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 문서 재생성 및 검증 완료
This commit is contained in:
@@ -68,11 +68,27 @@ public function store(array $params)
|
||||
|
||||
$data = $v->validated();
|
||||
|
||||
// group_code 중복 검사
|
||||
$exists = ClientGroup::where('tenant_id', $tenantId)
|
||||
// group_code 중복 검사 (삭제된 레코드 포함)
|
||||
$existing = ClientGroup::withTrashed()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('group_code', $data['group_code'])
|
||||
->exists();
|
||||
if ($exists) {
|
||||
->first();
|
||||
|
||||
// 삭제된 레코드가 있으면 복원하고 업데이트
|
||||
if ($existing && $existing->trashed()) {
|
||||
$existing->restore();
|
||||
$existing->update([
|
||||
'group_name' => $data['group_name'],
|
||||
'price_rate' => $data['price_rate'],
|
||||
'is_active' => $data['is_active'] ?? 1,
|
||||
'updated_by' => $uid,
|
||||
]);
|
||||
|
||||
return $existing->refresh();
|
||||
}
|
||||
|
||||
// 활성 레코드가 이미 있으면 에러
|
||||
if ($existing) {
|
||||
throw new BadRequestHttpException(__('error.duplicate_code'));
|
||||
}
|
||||
|
||||
@@ -107,12 +123,21 @@ public function update(int $id, array $params)
|
||||
|
||||
$payload = $v->validated();
|
||||
|
||||
// group_code 변경 시 중복 검사
|
||||
// group_code 변경 시 중복 검사 (삭제된 레코드 포함)
|
||||
if (isset($payload['group_code']) && $payload['group_code'] !== $group->group_code) {
|
||||
$exists = ClientGroup::where('tenant_id', $tenantId)
|
||||
$existingCode = ClientGroup::withTrashed()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('group_code', $payload['group_code'])
|
||||
->exists();
|
||||
if ($exists) {
|
||||
->where('id', '!=', $id) // 자기 자신 제외
|
||||
->first();
|
||||
|
||||
// 삭제된 레코드가 있으면 에러 (update는 복원하지 않음)
|
||||
if ($existingCode && $existingCode->trashed()) {
|
||||
throw new BadRequestHttpException(__('error.code_exists_in_deleted'));
|
||||
}
|
||||
|
||||
// 활성 레코드가 있으면 에러
|
||||
if ($existingCode) {
|
||||
throw new BadRequestHttpException(__('error.duplicate_code'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user