mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'fix/overwirte_api' into 'main'
Repuestas las modificaciones que se han sobrescrito See merge request jjimenez/safekat!591
This commit is contained in:
@ -57,10 +57,10 @@ class ImprimelibrosApi extends ResourceController
|
|||||||
'precios' => $response['precio_u']
|
'precios' => $response['precio_u']
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}else{
|
} else {
|
||||||
$response = [
|
$response = [
|
||||||
'status' => 400,
|
'status' => 400,
|
||||||
'error' => $response
|
'error' => $response
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -79,19 +79,40 @@ class ImprimelibrosApi extends ResourceController
|
|||||||
|
|
||||||
// Instancia de presupuesto cliente
|
// Instancia de presupuesto cliente
|
||||||
$presupuestocliente = new Presupuestocliente();
|
$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 = [
|
if (!isset($response['sk_id'])) {
|
||||||
'status' => 200,
|
return $this->respond([
|
||||||
'error' => null,
|
'status' => 400,
|
||||||
'data' => [
|
'error' => 'Missing sk_id',
|
||||||
'tiradas' => $response['tiradas'],
|
'message' => 'El identificador sk_id es requerido pero no se recibió.'
|
||||||
'precios' => $response['precio_u']
|
], 400);
|
||||||
]
|
}
|
||||||
];
|
|
||||||
return $this->respond($response);
|
$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'
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,103 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\API;
|
|
||||||
|
|
||||||
use CodeIgniter\RESTful\ResourceController;
|
|
||||||
use CodeIgniter\API\ResponseTrait;
|
|
||||||
use App\Models\API\ItemModel;
|
|
||||||
|
|
||||||
class ItemsController extends ResourceController
|
|
||||||
{
|
|
||||||
|
|
||||||
use ResponseTrait;
|
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
$model = new ItemModel();
|
|
||||||
$data = $model->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user