Cambios en la API con imprimelibros

This commit is contained in:
imnavajas
2025-01-20 14:58:59 +01:00
parent c478659124
commit 5ffb52d6e8
2 changed files with 16 additions and 44 deletions

View File

@ -19,45 +19,17 @@ class ImprimelibrosApi extends ResourceController
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 calcular()
{
helper(['form']);
// Access the entire POST data
$post_data = $this->request->getJSON(true);
//return $this->respond(var_dump($post_data));
$data_tmp = array
(
'clienteId' => 1870,
@ -131,16 +103,16 @@ class ImprimelibrosApi extends ResourceController
$client = \Config\Services::curlrequest();
$presupuestocliente = new Presupuestocliente();
$response = $presupuestocliente->calcular($data_tmp);
$response = $presupuestocliente->calcular($post_data);
/*$response = [
$response = [
'status' => 200,
'error' => null,
'messages' => [
'success' => 'Data updated'
'precio' => $response['precio_u']
]
];*/
return $this->respond($response['precio_u']);
];
return $this->respond($response);
}
public function delete($id = null)