ADD: Implementa respuesta de API y nuevas rutas para la consulta de vehículos recuperados
This commit is contained in:
parent
f648ea39eb
commit
216c1644e1
@ -6,6 +6,7 @@
|
||||
use App\Services\ConsultaEstatalService;
|
||||
use App\Services\ReporteRoboService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Notsoweb\ApiResponse\Enums\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
@ -33,11 +34,11 @@ public function consultarVehiculo(Request $request): JsonResponse
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
return ApiResponse::INTERNAL_ERROR->response([
|
||||
'success' => false,
|
||||
'message' => 'Datos inválidos',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -52,10 +53,10 @@ public function consultarVehiculo(Request $request): JsonResponse
|
||||
$datosEstatal = $this->consultaEstatal->consultarPorEpc($criterio);
|
||||
|
||||
if (!$datosEstatal || (!$datosEstatal['vin'] && !$datosEstatal['placa'])) {
|
||||
return response()->json([
|
||||
return ApiResponse::BAD_REQUEST->response([
|
||||
'success' => false,
|
||||
'message' => 'No se encontró información del vehículo en el padrón estatal'
|
||||
], 404);
|
||||
]);
|
||||
}
|
||||
|
||||
// Obtener VIN y Placa completos
|
||||
@ -84,7 +85,7 @@ public function consultarVehiculo(Request $request): JsonResponse
|
||||
'autoridad' => $reporteRobo['datos']['autoridad'] ?? null
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
return ApiResponse::OK->response([
|
||||
'success' => true,
|
||||
'tiene_reporte_robo' => true,
|
||||
'message' => '¡ALERTA! El vehículo tiene reporte de robo',
|
||||
@ -102,7 +103,7 @@ public function consultarVehiculo(Request $request): JsonResponse
|
||||
'placa' => $placaCompleta
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
return ApiResponse::OK->response([
|
||||
'success' => true,
|
||||
'tiene_reporte_robo' => false,
|
||||
'message' => 'Vehículo sin reporte de robo',
|
||||
@ -119,11 +120,11 @@ public function consultarVehiculo(Request $request): JsonResponse
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
return ApiResponse::INTERNAL_ERROR->response([
|
||||
'success' => false,
|
||||
'message' => 'Error al consultar vehículo',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,11 +167,11 @@ public function recuperarVehiculo(Request $request): JsonResponse
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
return ApiResponse::BAD_REQUEST->response([
|
||||
'success' => false,
|
||||
'message' => 'Datos inválidos',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -183,10 +184,10 @@ public function recuperarVehiculo(Request $request): JsonResponse
|
||||
$vehiculoEncontrado = $this->buscarEnRedis($vin, $placa);
|
||||
|
||||
if (!$vehiculoEncontrado) {
|
||||
return response()->json([
|
||||
return ApiResponse::NOT_FOUND->response([
|
||||
'success' => false,
|
||||
'message' => 'El vehículo no se encuentra en la lista de robados activos'
|
||||
], 404);
|
||||
]);
|
||||
}
|
||||
|
||||
$datosRedis = $vehiculoEncontrado['datos'];
|
||||
@ -221,7 +222,7 @@ public function recuperarVehiculo(Request $request): JsonResponse
|
||||
'placa' => $vehiculoRecuperado->placa
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
return ApiResponse::OK->response([
|
||||
'success' => true,
|
||||
'message' => 'Vehículo registrado como recuperado exitosamente',
|
||||
'vehiculo' => [
|
||||
@ -243,11 +244,11 @@ public function recuperarVehiculo(Request $request): JsonResponse
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
return ApiResponse::INTERNAL_ERROR->response([
|
||||
'success' => false,
|
||||
'message' => 'Error al registrar vehículo como recuperado',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,24 +286,48 @@ private function buscarEnRedis(?string $vin, ?string $placa): ?array
|
||||
* Listar todos los vehículos robados activos
|
||||
* GET /api/vehicles/robados
|
||||
*/
|
||||
public function listarRobados(): JsonResponse
|
||||
public function listarRobados(Request $request)
|
||||
{
|
||||
try {
|
||||
$vehiculos = $this->vehicleService->listarVehiculosRobados();
|
||||
|
||||
return response()->json([
|
||||
$collection = collect($vehiculos);
|
||||
|
||||
$perPage = $request->input('per_page', config('app.pagination', 15));
|
||||
$page = $request->input('page', 1);
|
||||
|
||||
$paginatedVehiculos = new \Illuminate\Pagination\LengthAwarePaginator(
|
||||
$collection->forPage($page, $perPage),
|
||||
$collection->count(),
|
||||
$perPage,
|
||||
$page,
|
||||
['path' => $request->url(), 'query' => $request->query()]
|
||||
);
|
||||
|
||||
return ApiResponse::OK->response([
|
||||
'success' => true,
|
||||
'total' => count($vehiculos),
|
||||
'vehiculos' => $vehiculos
|
||||
'total' => $collection->count(),
|
||||
'vehiculos' => $paginatedVehiculos
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
return ApiResponse::BAD_REQUEST->response([
|
||||
'success' => false,
|
||||
'message' => 'Error al listar vehículos robados',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function listarRecuperados()
|
||||
{
|
||||
$vehiculos = Vehicle::orderBy('fecha_recuperacion', 'desc')
|
||||
->paginate(config('app.pagination'));
|
||||
|
||||
return ApiResponse::OK->response([
|
||||
'success' => true,
|
||||
'vehiculos' => $vehiculos
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
/**
|
||||
* Seeder de desarrollo
|
||||
*
|
||||
*
|
||||
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
||||
*
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
class DevSeeder extends Seeder
|
||||
@ -22,5 +22,6 @@ public function run(): void
|
||||
$this->call(RoleSeeder::class);
|
||||
$this->call(UserSeeder::class);
|
||||
$this->call(SettingSeeder::class);
|
||||
$this->call(VehicleTestSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
153
database/seeders/VehicleTestSeeder.php
Normal file
153
database/seeders/VehicleTestSeeder.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class VehicleTestSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->command->info('Creando datos de prueba de vehículos...');
|
||||
|
||||
// Limpiar Redis antes de empezar
|
||||
$keys = Redis::keys('vehiculo:*');
|
||||
if (count($keys) > 0) {
|
||||
foreach ($keys as $key) {
|
||||
Redis::del($key);
|
||||
}
|
||||
$this->command->warn('Redis limpiado: ' . count($keys) . ' vehículos eliminados');
|
||||
}
|
||||
|
||||
// VEHÍCULOS CON REPORTE DE ROBO
|
||||
|
||||
$vehiculosRobados = [
|
||||
[
|
||||
'epc' => 'E2801170000001111AAAA',
|
||||
'vin' => '3VWDX7AJ9CM111111',
|
||||
'placa' => 'ABC1111',
|
||||
'fecha_robo' => '2024-01-15',
|
||||
'autoridad' => 'PGJ - BAJA CALIFORNIA',
|
||||
'acta' => 'BC/ROB/2024/001',
|
||||
'denunciante' => 'JUAN GARCIA LOPEZ',
|
||||
'fecha_acta' => '2024-01-15',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000002222BBBB',
|
||||
'vin' => '1HGBH41JXMN222222',
|
||||
'placa' => 'XYZ2222',
|
||||
'fecha_robo' => '2024-03-20',
|
||||
'autoridad' => 'FISCALÍA GENERAL DEL ESTADO',
|
||||
'acta' => 'FGE/ROB/2024/002',
|
||||
'denunciante' => 'MARIA RODRIGUEZ SANCHEZ',
|
||||
'fecha_acta' => '2024-03-20',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000003333CCCC',
|
||||
'vin' => '2HGFG12858H333333',
|
||||
'placa' => 'DEF3333',
|
||||
'fecha_robo' => '2024-06-10',
|
||||
'autoridad' => 'PGJ - SONORA',
|
||||
'acta' => 'SON/ROB/2024/003',
|
||||
'denunciante' => 'CARLOS MARTINEZ GONZALEZ',
|
||||
'fecha_acta' => '2024-06-10',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000004444DDDD',
|
||||
'vin' => '5FNRL5H64GB444444',
|
||||
'placa' => 'GHI4444',
|
||||
'fecha_robo' => '2024-08-05',
|
||||
'autoridad' => 'FISCALÍA ESPECIALIZADA EN ROBO DE VEHÍCULOS',
|
||||
'acta' => 'FERV/2024/004',
|
||||
'denunciante' => 'ANA LOPEZ HERNANDEZ',
|
||||
'fecha_acta' => '2024-08-05',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000005555EEEE',
|
||||
'vin' => '1G1ZD5ST0LF555555',
|
||||
'placa' => 'JKL5555',
|
||||
'fecha_robo' => '2024-11-25',
|
||||
'autoridad' => 'PGJ - CHIHUAHUA',
|
||||
'acta' => 'CHI/ROB/2024/005',
|
||||
'denunciante' => 'PEDRO RAMIREZ FLORES',
|
||||
'fecha_acta' => '2024-11-25',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000006666HHHH',
|
||||
'vin' => 'KNDJT2A27G7666666',
|
||||
'placa' => 'MNO6666',
|
||||
'fecha_robo' => '2024-12-01',
|
||||
'autoridad' => 'PGJ - SINALOA',
|
||||
'acta' => 'SIN/ROB/2024/006',
|
||||
'denunciante' => 'LUIS FERNANDEZ TORRES',
|
||||
'fecha_acta' => '2024-12-01',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000007777IIII',
|
||||
'vin' => '3FADP4BJ6FM777777',
|
||||
'placa' => 'PQR7777',
|
||||
'fecha_robo' => '2024-12-05',
|
||||
'autoridad' => 'FISCALÍA GENERAL - JALISCO',
|
||||
'acta' => 'JAL/ROB/2024/007',
|
||||
'denunciante' => 'ROSA MARTINEZ DIAZ',
|
||||
'fecha_acta' => '2024-12-05',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000008888JJJJ',
|
||||
'vin' => '1N4AL3AP5JC888888',
|
||||
'placa' => 'STU8888',
|
||||
'fecha_robo' => '2024-12-10',
|
||||
'autoridad' => 'PGJ - NUEVO LEON',
|
||||
'acta' => 'NL/ROB/2024/008',
|
||||
'denunciante' => 'MIGUEL ANGEL RUIZ',
|
||||
'fecha_acta' => '2024-12-10',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000009999KKKK',
|
||||
'vin' => 'JN1CV6AP3BM999999',
|
||||
'placa' => 'VWX9999',
|
||||
'fecha_robo' => '2024-12-12',
|
||||
'autoridad' => 'FISCALÍA - VERACRUZ',
|
||||
'acta' => 'VER/ROB/2024/009',
|
||||
'denunciante' => 'PATRICIA GOMEZ CASTRO',
|
||||
'fecha_acta' => '2024-12-12',
|
||||
],
|
||||
[
|
||||
'epc' => 'E2801170000010000LLLL',
|
||||
'vin' => 'WBAFR9C58BC000000',
|
||||
'placa' => 'YZA0000',
|
||||
'fecha_robo' => '2024-12-15',
|
||||
'autoridad' => 'PGJ - TAMAULIPAS',
|
||||
'acta' => 'TAM/ROB/2024/010',
|
||||
'denunciante' => 'FRANCISCO HERNANDEZ SILVA',
|
||||
'fecha_acta' => '2024-12-15',
|
||||
],
|
||||
];
|
||||
|
||||
// Guardar vehículos robados en Redis
|
||||
foreach ($vehiculosRobados as $vehiculo) {
|
||||
$key = "vehiculo:robado:{$vehiculo['epc']}";
|
||||
|
||||
$datos = [
|
||||
'epc' => $vehiculo['epc'],
|
||||
'vin' => $vehiculo['vin'],
|
||||
'placa' => $vehiculo['placa'],
|
||||
'fecha_robo' => $vehiculo['fecha_robo'],
|
||||
'autoridad' => $vehiculo['autoridad'],
|
||||
'acta' => $vehiculo['acta'],
|
||||
'denunciante' => $vehiculo['denunciante'],
|
||||
'fecha_acta' => $vehiculo['fecha_acta'],
|
||||
'primera_deteccion' => now()->subDays(rand(1, 30))->toIso8601String(),
|
||||
'ultima_deteccion' => now()->subHours(rand(1, 24))->toIso8601String(),
|
||||
'detecciones' => rand(1, 50),
|
||||
'origen' => 'SEEDER_PRUEBA'
|
||||
];
|
||||
|
||||
Redis::set($key, json_encode($datos));
|
||||
|
||||
$this->command->info("Robado: {$vehiculo['placa']} - {$vehiculo['vin']}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ services:
|
||||
redis-commander:
|
||||
image: rediscommander/redis-commander:latest
|
||||
environment:
|
||||
- ${REDIS_HOST}:redis:6379
|
||||
- REDIS_HOSTS=local:redis:6379
|
||||
ports:
|
||||
- "${REDIS_COMMANDER_PORT}:8081"
|
||||
networks:
|
||||
|
||||
@ -17,6 +17,11 @@ RUN apk add --no-cache \
|
||||
mysql-client \
|
||||
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
|
||||
|
||||
# Instalar extensión de Redis
|
||||
RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \
|
||||
&& pecl install redis \
|
||||
&& docker-php-ext-enable redis
|
||||
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
|
||||
COPY composer.json composer.lock ./
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
Route::post('/vehicles/consultar', [VehicleController::class, 'consultarVehiculo']);
|
||||
Route::post('/vehicles/recuperar', [VehicleController::class, 'recuperarVehiculo']);
|
||||
Route::get('/vehicles/robados', [VehicleController::class, 'listarRobados']);
|
||||
Route::get('/vehicles', [VehicleController::class, 'listarRecuperados']);
|
||||
});
|
||||
|
||||
/** Rutas públicas */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user