From 9ada8d0ba0eb2070ca1101497759721a2ca49328 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Sun, 9 Mar 2025 20:25:47 +0100 Subject: [PATCH] Repuestas las modificaciones que se han sobrescrito --- ci4/app/Controllers/API/ImprimelibrosApi.php | 47 ++++++--- ci4/app/Controllers/API/ItemsController.php | 103 ------------------- 2 files changed, 34 insertions(+), 116 deletions(-) delete mode 100644 ci4/app/Controllers/API/ItemsController.php diff --git a/ci4/app/Controllers/API/ImprimelibrosApi.php b/ci4/app/Controllers/API/ImprimelibrosApi.php index aeff2713..04450d68 100644 --- a/ci4/app/Controllers/API/ImprimelibrosApi.php +++ b/ci4/app/Controllers/API/ImprimelibrosApi.php @@ -57,10 +57,10 @@ class ImprimelibrosApi extends ResourceController 'precios' => $response['precio_u'] ] ]; - }else{ + } else { $response = [ 'status' => 400, - 'error' => $response + 'error' => $response ]; } @@ -79,19 +79,40 @@ class ImprimelibrosApi extends ResourceController // Instancia de presupuesto cliente $presupuestocliente = new Presupuestocliente(); - $response = $presupuestocliente->guardar($post_data); + try { + $response = $presupuestocliente->guardar($post_data); - return $this->respond($response); + // DEBUG LINE + //return $this->respond($response); - $response = [ - 'status' => 200, - 'error' => null, - 'data' => [ - 'tiradas' => $response['tiradas'], - 'precios' => $response['precio_u'] - ] - ]; - return $this->respond($response); + if (!isset($response['sk_id'])) { + return $this->respond([ + 'status' => 400, + 'error' => 'Missing sk_id', + 'message' => 'El identificador sk_id es requerido pero no se recibió.' + ], 400); + } + + $response = [ + 'status' => 200, + 'error' => null, + 'data' => [ + 'sk_id' => $response['sk_id'], + 'sk_url' => $response['sk_url'] ?? null + ] + ]; + + return $this->respond($response); + + } catch (\Exception $e) { + + return $this->respond([ + 'status' => 500, + 'error' => 'Server error', + 'message' => 'Error inesperado durante el procesado' + ]); + + } } diff --git a/ci4/app/Controllers/API/ItemsController.php b/ci4/app/Controllers/API/ItemsController.php deleted file mode 100644 index b4ccbfe8..00000000 --- a/ci4/app/Controllers/API/ItemsController.php +++ /dev/null @@ -1,103 +0,0 @@ -findAll(); - return $this->respond($data); - } - - public function show($id = null) - { - $model = new ItemModel(); - $data = $model->find(['id' => $id]); - if (!$data) - return $this->failNotFound('No Data Found'); - return $this->respond($data[0]); - } - - public function create() - { - helper(['form']); - $rules = [ - 'title' => 'required', - 'price' => 'required' - ]; - $data = [ - 'title' => $this->request->getVar('title'), - 'price' => $this->request->getVar('price') - ]; - - if (!$this->validate($rules)) - return $this->fail($this->validator->getErrors()); - $model = new ItemModel(); - $model->save($data); - $response = [ - 'status' => 201, - 'error' => null, - 'messages' => [ - 'success' => 'Data Inserted' - ] - ]; - return $this->respondCreated($response); - } - - public function update($id = null) - { - helper(['form']); - $rules = [ - 'title' => 'required', - 'price' => 'required' - ]; - $data = [ - 'title' => $this->request->getVar('title'), - 'price' => $this->request->getVar('price') - ]; - - if (!$this->validate($rules)) - return $this->fail($this->validator->getErrors()); - $model = new ItemModel(); - $find = $model->find(['id' => $id]); - if (!$find) - return $this->failNotFound('No Data Found'); - $model->update($id, $data); - - $response = [ - 'status' => 200, - 'error' => null, - 'messages' => [ - 'success' => 'Data updated' - ] - ]; - return $this->respond($response); - } - - public function delete($id = null) - { - $model = new ItemModel(); - $find = $model->find(['id' => $id]); - if (!$find) - return $this->failNotFound('No Data Found'); - $model->delete($id); - - $response = [ - 'status' => 200, - 'error' => null, - 'messages' => [ - 'success' => 'Data deleted' - ] - ]; - return $this->respond($response); - } -}