ADD: api consulta
This commit is contained in:
parent
f3dd6cd32c
commit
71788ddd2e
@ -6,15 +6,65 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Notsoweb\ApiResponse\Enums\ApiResponse;
|
use Notsoweb\ApiResponse\Enums\ApiResponse;
|
||||||
|
use App\Http\Requests\Repuve\VehicleRequest;
|
||||||
|
use App\Models\Vehicle;
|
||||||
|
use App\Models\Record;
|
||||||
|
|
||||||
class RepuveController extends Controller
|
class RepuveController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
public function consultarVehiculo(VehicleRequest $request)
|
||||||
* Obtener información de vehículo (datos hardcodeados)
|
|
||||||
*/
|
|
||||||
public function information()
|
|
||||||
{
|
{
|
||||||
$data = [
|
// La validación por el Request
|
||||||
|
$folio = $request->input('folio');
|
||||||
|
|
||||||
|
// Simular consulta de robo
|
||||||
|
$isStolen = (bool) rand(0, 1);
|
||||||
|
$stolenMessage = $isStolen
|
||||||
|
? 'El vehículo reporta robo'
|
||||||
|
: 'El vehículo no reporta robo';
|
||||||
|
|
||||||
|
// Obtener datos del vehículo
|
||||||
|
$vehicleData = $this->getVehicle();
|
||||||
|
|
||||||
|
$vehicle = Vehicle::updateOrCreate(
|
||||||
|
['placa' => $vehicleData['PLACA']],
|
||||||
|
[
|
||||||
|
'modelo' => $vehicleData['MODELO'],
|
||||||
|
'marca' => $vehicleData['MARCA'],
|
||||||
|
'nrpv' => $vehicleData['NUMERO_SERIE'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Crear registro con folio + vehicle_id
|
||||||
|
$record = Record::create([
|
||||||
|
'folio' => $folio,
|
||||||
|
'vehicle_id' => $vehicle->id,
|
||||||
|
'user_id' => auth()->id() ?? null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Responder al cliente
|
||||||
|
return ApiResponse::OK->response([
|
||||||
|
'folio' => $folio,
|
||||||
|
'stolen' => $isStolen,
|
||||||
|
'message' => $stolenMessage,
|
||||||
|
'vehicle' => [
|
||||||
|
'id' => $vehicle->id,
|
||||||
|
'placa' => $vehicleData['PLACA'],
|
||||||
|
'modelo' => $vehicleData['MODELO'],
|
||||||
|
'marca' => $vehicleData['MARCA'],
|
||||||
|
'numero_serie' => $vehicleData['NUMERO_SERIE'],
|
||||||
|
'color' => $vehicleData['COLOR'],
|
||||||
|
'tipo' => $vehicleData['TIPO'],
|
||||||
|
'linea' => $vehicleData['LINEA'],
|
||||||
|
],
|
||||||
|
'record_id' => $record->id,
|
||||||
|
'created_at' => $record->created_at->toDateTimeString(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getVehicle(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
"ANIO_PLACA" => "2020",
|
"ANIO_PLACA" => "2020",
|
||||||
"PLACA" => "WNU700B",
|
"PLACA" => "WNU700B",
|
||||||
"NO_SERIE" => "LSGHD52H0ND032457",
|
"NO_SERIE" => "LSGHD52H0ND032457",
|
||||||
@ -45,59 +95,7 @@ public function information()
|
|||||||
"SERIE_FOLIO" => "D3962243",
|
"SERIE_FOLIO" => "D3962243",
|
||||||
"SFOLIO" => "3962243"
|
"SFOLIO" => "3962243"
|
||||||
];
|
];
|
||||||
|
|
||||||
return ApiResponse::OK->response($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
$data = $request->all();
|
|
||||||
$data['id'] = rand(01, 1000);
|
|
||||||
$data['created_at'] = now()->toDateTimeString();
|
|
||||||
|
|
||||||
return ApiResponse::CREATED->response([
|
|
||||||
'message' => 'Información almacenada correctamente', 'Registro' => $data
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
|
||||||
{
|
|
||||||
$data = $this->information();
|
|
||||||
$updata['id'] = $id;
|
|
||||||
$updata['updated_at'] = now()->toDateTimeString();
|
|
||||||
|
|
||||||
return ApiResponse::OK->response([
|
|
||||||
'message' => 'Información actualizada correctamente',
|
|
||||||
'data' => $updata
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($id)
|
|
||||||
{
|
|
||||||
return ApiResponse::OK->response();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function stolen(Request $request)
|
|
||||||
{
|
|
||||||
$vehicleId = $request->input('epc');
|
|
||||||
|
|
||||||
if (!$vehicleId) {
|
|
||||||
return ApiResponse::BAD_REQUEST->response([
|
|
||||||
'message' => 'El parámetro epc es requerido'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$isStolen = (bool) rand(0, 1);
|
|
||||||
|
|
||||||
$response = [
|
|
||||||
'stolen' => $isStolen,
|
|
||||||
'message' => $isStolen
|
|
||||||
? 'El vehículo reporta robo'
|
|
||||||
: 'El vehículo no reporta robo',
|
|
||||||
'date' => now()->toDateTimeString()
|
|
||||||
];
|
|
||||||
|
|
||||||
return ApiResponse::OK->response($response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
28
app/Http/Requests/Repuve/VehicleRequest.php
Normal file
28
app/Http/Requests/Repuve/VehicleRequest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php namespace App\Http\Requests\Repuve;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class VehicleRequest extends FormRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'folio' => ['required', 'string', 'max:50'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'folio.required' => 'El folio es requerido',
|
||||||
|
'folio.string' => 'El folio debe ser una cadena de texto',
|
||||||
|
'folio.max' => 'El folio no puede exceder 50 caracteres',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,6 +10,7 @@ class Record extends Model
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'folio',
|
||||||
'vehicle_id',
|
'vehicle_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
'error_id',
|
'error_id',
|
||||||
|
|||||||
@ -13,7 +13,6 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('devices', function (Blueprint $table) {
|
Schema::create('devices', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('type_id')->nullable()->constrained('device_types')->nullOnDelete();
|
|
||||||
$table->string('brand');
|
$table->string('brand');
|
||||||
$table->string('serie')->unique();
|
$table->string('serie')->unique();
|
||||||
$table->boolean('status')->default(true);
|
$table->boolean('status')->default(true);
|
||||||
|
|||||||
@ -13,10 +13,34 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('vehicle', function (Blueprint $table) {
|
Schema::create('vehicle', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('placa')->unique();
|
$table->string('anio_placa')->nullable();
|
||||||
$table->string('modelo');
|
$table->string('placa')->unique()->nullable();
|
||||||
$table->string('marca');
|
$table->string('numero_serie')->unique()->nullable();
|
||||||
$table->string('nrpv')->unique()->nullable(); // Número REPUVE
|
$table->string('rfc')->nullable();
|
||||||
|
$table->string('vigencia')->nullable();
|
||||||
|
$table->string('fecha_impresion')->nullable();
|
||||||
|
$table->string('qr_hash')->nullable();
|
||||||
|
$table->boolean('valido')->nullable();
|
||||||
|
$table->boolean('foliotemp')->nullable();
|
||||||
|
$table->string('nombre')->nullable();
|
||||||
|
$table->string('nombre2')->nullable();
|
||||||
|
$table->string('municipio')->nullable();
|
||||||
|
$table->string('localidad')->nullable();
|
||||||
|
$table->string('calle')->nullable();
|
||||||
|
$table->string('calle2')->nullable();
|
||||||
|
$table->string('tipo')->nullable();
|
||||||
|
$table->string('tipo_servicio')->nullable();
|
||||||
|
$table->string('marca')->nullable();
|
||||||
|
$table->string('linea')->nullable();
|
||||||
|
$table->string('sublinea')->nullable();
|
||||||
|
$table->string('modelo')->nullable();
|
||||||
|
$table->string('numero_motor')->nullable();
|
||||||
|
$table->string('descripcion_origen')->nullable();
|
||||||
|
$table->string('color')->nullable();
|
||||||
|
$table->string('codigo_postal')->nullable();
|
||||||
|
$table->string('serie_folio')->unique()->nullable();
|
||||||
|
$table->string('sfolio')->unique()->nullable();
|
||||||
|
$table->string('nrpv')->unique()->nullable();
|
||||||
$table->foreignId('owner_id')->nullable()->constrained('owners')->nullOnDelete();
|
$table->foreignId('owner_id')->nullable()->constrained('owners')->nullOnDelete();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,6 +13,7 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('records', function (Blueprint $table) {
|
Schema::create('records', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->string('folio');
|
||||||
$table->foreignId('vehicle_id')->constrained('vehicle')->cascadeOnDelete();
|
$table->foreignId('vehicle_id')->constrained('vehicle')->cascadeOnDelete();
|
||||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||||
$table->foreignId('error_id')->nullable()->constrained('errors')->nullOnDelete();
|
$table->foreignId('error_id')->nullable()->constrained('errors')->nullOnDelete();
|
||||||
|
|||||||
@ -19,14 +19,10 @@
|
|||||||
/** Rutas protegidas (requieren autenticación) */
|
/** Rutas protegidas (requieren autenticación) */
|
||||||
Route::middleware('auth:api')->group(function() {
|
Route::middleware('auth:api')->group(function() {
|
||||||
// Tus rutas protegidas
|
// Tus rutas protegidas
|
||||||
Route::post('stolen', [RepuveController::class, 'stolen']);
|
Route::post('consultar', [RepuveController::class, 'consultarVehiculo']);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Rutas públicas */
|
/** Rutas públicas */
|
||||||
// Tus rutas públicas
|
// Tus rutas públicas
|
||||||
|
|
||||||
Route::get('information', [RepuveController::class, 'information']);
|
|
||||||
Route::post('information', [RepuveController::class, 'store']);
|
|
||||||
Route::put('information/{id}', [RepuveController::class, 'update']);
|
|
||||||
Route::delete('information/{id}', [RepuveController::class, 'delete']);
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user