Endpoint que devuelve las regiones. Cliente web se autentica a través de un token

This commit is contained in:
nat 2022-01-05 14:11:07 -03:00
parent bcbcf05c3f
commit b889dbf1e1
7 changed files with 49 additions and 5 deletions

View File

@ -44,3 +44,7 @@ PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
WEB_CLIENT_EMAIL=informaticamps@buzon.uy
WEB_CLIENT_NAME=web
WEB_CLIENT_PASS=pass

View File

@ -44,12 +44,15 @@ docker-compose exec app composer update
docker-compose exec app php artisan key:generate
```
6. Corré las migraciones de Laravel
6. Corré las migraciones y seeders de Laravel
```bash
docker-compose exec app php artisan migrate
docker-compose exec app php artisan migrate --seed
```
7. Copia el token que se imprime al correr los seeders. Lo necesitamos para autenticar las llamadas que hagamos desde nuestro cliente web
Ahora la aplicación está corriendo y la podés ver en el puerto 8000 de tu dominio o IP. En caso de que estés en tu máquina local, la vas a ver accediendo a `http://localhost:8000` desde tu navegador.
Podés usar el comando `logs` para ver los logs generados por tus servicios:

View File

@ -9,5 +9,11 @@ class GrupoDeCompra extends Model
public $timestamps = false;
protected $fillable = [ "nombre","region","telefono","correo","referente_finanzas","cantidad_de_nucleos"];
protected $table = 'grupos_de_compra';
public static $regiones = [
'NORTE',
'SUR',
'ESTE',
'OESTE'
];
}

View File

@ -20,6 +20,7 @@ class CreateUsersTable extends Migration
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->string('api_token',60);
$table->timestamps();
});
}

View File

@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UserSeeder::class);
$this->call(UserSeeder::class);
}
}

View File

@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$api_token = Str::random(60);
$web_client_name = env('WEB_CLIENT_NAME', 'web');
DB::table('users')->insert([
'name' => $web_client_name,
'email' => env('WEB_CLIENT_EMAIL', 'informaticamps@buzon.uy'),
'password' => Hash::make(env('WEB_CLIENT_PASS', 'pass')),
'api_token' => $api_token
]);
dump('Api token for ' . $web_client_name . ' is: ' . $api_token);
$api_token = Str::random(60);
}
}

View File

@ -2,6 +2,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\GrupoDeCompra;
/*
|--------------------------------------------------------------------------
@ -14,6 +15,8 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
Route::middleware('auth:api')->group(function () {
Route::get('/regiones', function() {
return GrupoDeCompra::$regiones;
});
});