daemon-idc init
This commit is contained in:
parent
08578efd40
commit
7bffcd2727
@ -96,6 +96,7 @@ abstract class AbstractWebController extends Controller
|
|||||||
case 'critical':
|
case 'critical':
|
||||||
case 'alert':
|
case 'alert':
|
||||||
case 'emergency':
|
case 'emergency':
|
||||||
|
case 'success':
|
||||||
log_message($type, $message);
|
log_message($type, $message);
|
||||||
$result = redirect()->back()->withInput()->with('message', $message);
|
$result = redirect()->back()->withInput()->with('message', $message);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -75,4 +75,46 @@ abstract class AjaxController extends AbstractCRUDController
|
|||||||
|
|
||||||
return $this->fail('처리 중 오류가 발생했습니다.', 500);
|
return $this->fail('처리 중 오류가 발생했습니다.', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function create(): ResponseInterface
|
||||||
|
{
|
||||||
|
if (!$this->request->isAJAX()) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'ok' => false,
|
||||||
|
'message' => static::class . '->' . __FUNCTION__ . "에서 오류발생: AJAX요청 형식이 아닙니다."
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$formDatas = $this->request->getPost();
|
||||||
|
// log_message('error', 'POST=' . json_encode($formDatas, JSON_UNESCAPED_UNICODE));
|
||||||
|
$entity = $this->service->create($formDatas);
|
||||||
|
return $this->response->setStatusCode(201)->setJSON([
|
||||||
|
'ok' => true,
|
||||||
|
'message' => '문의가 접수되었습니다.',
|
||||||
|
'data' => ['pk' => $entity->getPK()],
|
||||||
|
]);
|
||||||
|
} catch (FormValidationException $e) {
|
||||||
|
// log_message('error', 'CAUGHT FormValidationException: ' . print_r($e->getErrors(), true));
|
||||||
|
return $this->response->setStatusCode(422)->setJSON([
|
||||||
|
'ok' => false,
|
||||||
|
'message' => '입력값을 확인해 주세요.',
|
||||||
|
'errors' => $e->getErrors(),
|
||||||
|
]);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// ✅ 혹시 서비스에서 예외를 감싸버린 경우에도 에러를 최대한 복구
|
||||||
|
$errors = service('validation')->getErrors();
|
||||||
|
if (!empty($errors)) {
|
||||||
|
log_message('error', 'FALLBACK validation errors: ' . print_r($errors, true));
|
||||||
|
return $this->response->setStatusCode(422)->setJSON([
|
||||||
|
'ok' => false,
|
||||||
|
'message' => '입력값을 확인해 주세요.',
|
||||||
|
'errors' => $errors,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $this->response->setStatusCode(500)->setJSON([
|
||||||
|
'ok' => false,
|
||||||
|
'message' => '처리 중 오류가 발생했습니다.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,6 @@ use CodeIgniter\HTTP\RequestInterface;
|
|||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
use App\Exceptions\FormValidationException;
|
|
||||||
|
|
||||||
class InquiryController extends AjaxController
|
class InquiryController extends AjaxController
|
||||||
{
|
{
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
@ -21,58 +19,4 @@ class InquiryController extends AjaxController
|
|||||||
//Action작업관련
|
//Action작업관련
|
||||||
//기본 함수 작업
|
//기본 함수 작업
|
||||||
//Custom 추가 함수
|
//Custom 추가 함수
|
||||||
|
|
||||||
public function create(): ResponseInterface
|
|
||||||
{
|
|
||||||
log_message('error', 'HIT InquiryController::create');
|
|
||||||
|
|
||||||
if (!$this->request->isAJAX()) {
|
|
||||||
return $this->response->setStatusCode(400)->setJSON([
|
|
||||||
'ok' => false,
|
|
||||||
'message' => 'Invalid request'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$formDatas = $this->request->getPost();
|
|
||||||
log_message('error', 'POST=' . json_encode($formDatas, JSON_UNESCAPED_UNICODE));
|
|
||||||
|
|
||||||
$entity = $this->service->create($formDatas);
|
|
||||||
|
|
||||||
return $this->response->setStatusCode(201)->setJSON([
|
|
||||||
'ok' => true,
|
|
||||||
'message' => '문의가 접수되었습니다.',
|
|
||||||
'data' => ['pk' => $entity->getPK()],
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (FormValidationException $e) {
|
|
||||||
log_message('error', 'CAUGHT FormValidationException: ' . print_r($e->getErrors(), true));
|
|
||||||
|
|
||||||
return $this->response->setStatusCode(422)->setJSON([
|
|
||||||
'ok' => false,
|
|
||||||
'message' => '입력값을 확인해 주세요.',
|
|
||||||
'errors' => $e->getErrors(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
// ✅ 혹시 서비스에서 예외를 감싸버린 경우에도 에러를 최대한 복구
|
|
||||||
$errors = service('validation')->getErrors();
|
|
||||||
if (!empty($errors)) {
|
|
||||||
log_message('error', 'FALLBACK validation errors: ' . print_r($errors, true));
|
|
||||||
|
|
||||||
return $this->response->setStatusCode(422)->setJSON([
|
|
||||||
'ok' => false,
|
|
||||||
'message' => '입력값을 확인해 주세요.',
|
|
||||||
'errors' => $errors,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message('error', '[AJAX create] ' . $e->getMessage());
|
|
||||||
|
|
||||||
return $this->response->setStatusCode(500)->setJSON([
|
|
||||||
'ok' => false,
|
|
||||||
'message' => '처리 중 오류가 발생했습니다.',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -217,10 +217,6 @@ abstract class CommonService
|
|||||||
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 저장 작업이 실패했습니다.";
|
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 저장 작업이 실패했습니다.";
|
||||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . $errorMsg);
|
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . $errorMsg);
|
||||||
}
|
}
|
||||||
// CodeIgniter 모델의 getInsertID()를 사용하여 새로 생성된 PK를 확실히 가져옵니다.
|
|
||||||
if ($this->model->useAutoIncrement()) {
|
|
||||||
$entity->{$this->getPKField()} = $this->model->getInsertID();
|
|
||||||
}
|
|
||||||
return $entity;
|
return $entity;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
log_message('debug', __FUNCTION__ . ":" . var_export($entity, true));
|
log_message('debug', __FUNCTION__ . ":" . var_export($entity, true));
|
||||||
@ -255,7 +251,12 @@ abstract class CommonService
|
|||||||
throw new RuntimeException("Return Type은 {$entityClass}만 가능");
|
throw new RuntimeException("Return Type은 {$entityClass}만 가능");
|
||||||
}
|
}
|
||||||
$entity->fill($formDatas);
|
$entity->fill($formDatas);
|
||||||
return $this->save_process($entity);
|
$entity = $this->save_process($entity);
|
||||||
|
//생성PK 설정
|
||||||
|
if ($this->model->useAutoIncrement()) {
|
||||||
|
$entity->{$this->getPKField()} = $this->model->getInsertID();
|
||||||
|
}
|
||||||
|
return $entity;
|
||||||
} catch (FormValidationException $e) {
|
} catch (FormValidationException $e) {
|
||||||
throw $e; // ✅ 감싸지 말고 그대로
|
throw $e; // ✅ 감싸지 말고 그대로
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@ -289,7 +290,8 @@ abstract class CommonService
|
|||||||
if (!$entity->hasChanged()) {
|
if (!$entity->hasChanged()) {
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
return $this->save_process($entity);
|
$entity = $this->save_process($entity);
|
||||||
|
return $entity;
|
||||||
} catch (FormValidationException $e) {
|
} catch (FormValidationException $e) {
|
||||||
throw $e; // ✅ 감싸지 말고 그대로
|
throw $e; // ✅ 감싸지 말고 그대로
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user