Compare commits

..

4 Commits

7 changed files with 136 additions and 4 deletions

View File

@ -13,7 +13,7 @@ class PlacesController extends Controller
/**
* Search place using OSM APIs.
*/
public function search(Request $request)
public function reverseSearch(Request $request)
{
User::where('id', $request->user()->id)->update(['last_access' => now()]);
@ -30,6 +30,35 @@ class PlacesController extends Controller
return response()->json($result);
}
public function italyListRegions()
{
$seconds = 60 * 60 * 24 * 365 * 10; // 10 years
$result = Cache::remember('italy_regions', $seconds, function () {
return Http::get('https://axqvoqvbfjpaamphztgd.functions.supabase.co/regioni')->object();
});
return response()->json($result);
}
public function italyListProvincesByRegion(Request $request, string $region_name)
{
$region_name = strtolower($region_name);
$seconds = 60 * 60 * 24 * 365; // 1 year
$result = Cache::remember('italy_provinces_'.$region_name, $seconds, function () use ($region_name) {
return Http::get('https://axqvoqvbfjpaamphztgd.functions.supabase.co/province/'.$region_name)->object();
});
return response()->json($result);
}
public function italyListMunicipalitiesByProvince(Request $request, string $province_name)
{
$province_name = strtolower($province_name);
$seconds = 60 * 60 * 24 * 365; // 1 year
$result = Cache::remember('italy_municipalities_'.$province_name, $seconds, function () use ($province_name) {
return Http::get('https://axqvoqvbfjpaamphztgd.functions.supabase.co/comuni/provincia/'.$province_name)->object();
});
return response()->json($result);
}
public function show(Request $request, $id)
{
User::where('id', $request->user()->id)->update(['last_access' => now()]);

View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\PlaceProvince;
class PlaceMunicipality extends Model
{
use HasFactory;
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'code', 'name', 'foreign_name', 'cadastral_code', 'postal_code', 'prefix', 'email', 'pec', 'phone', 'fax', 'latitude', 'longitude'
];
/**
* Get the province
*/
public function province(): BelongsTo
{
return $this->belongsTo(PlaceProvince::class);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PlaceProvince extends Model
{
use HasFactory;
public $timestamps = false;
protected $fillable = [
'code', 'name', 'short_name', 'region'
];
}

View File

@ -144,6 +144,7 @@ class WebhookController extends
$this->replyToUserChat(
" Informazioni sul profilo:".
"\n<i>Nome:</i> <b>".$user["name"]."</b>".
(!empty($user["surname"])&& !is_null($user["surname"]) ? "\n<i>Cognome:</i> <b>".$user["surname"]."</b>" : "").
"\n<i>Disponibile:</i> ".($user["available"] ? "<b>SI</b>" : "<b>NO</b>").
"\n<i>Caposquadra:</i> ".($user["chief"] === 1 ? "<b>SI</b>" : "<b>NO</b>").
"\n<i>Autista:</i> ".($user["driver"] === 1 ? "<b>SI</b>" : "<b>NO</b>").
@ -202,13 +203,14 @@ class WebhookController extends
->orderBy('trainings', 'desc')
->orderBy('availability_minutes', 'desc')
->orderBy('name', 'asc')
->orderBy('surname', 'asc')
->get();
if(count($users) == 0) {
$text = "⚠️ Nessun vigile attualmente disponibile.";
} else {
$text = "👨‍🚒 Elenco dei vigili attualmente disponibili:";
foreach ($users as $user) {
$text .= "\n- <i>".$user->name."</i>";
$text .= "\n- <i>".(!empty($user->surname)&&!is_null($user->surname) ? $user->surname : "")." ".$user->name."</i>";
if($user->chief) $text .= " CS";
if($user->driver) $text .= " 🚒";
}

View File

@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('PlaceProvince', function (Blueprint $table) {
$table->id();
$table->string('code', 2)->unique();
$table->string('name', 100);
$table->string('short_name', 2);
$table->string('region', 25);
});
Schema::create('PlaceMunicipality', function (Blueprint $table) {
$table->id();
$table->string('code', 6)->unique();
$table->string('name', 200);
$table->string('foreign_name', 200)->nullable();
$table->string('cadastral_code', 4)->nullable();
$table->string('postal_code', 5)->nullable();
$table->string('prefix', 4)->nullable();
$table->string('email', 200)->nullable();
$table->string('pec', 200)->nullable();
$table->string('phone', 30)->nullable();
$table->string('fax', 30)->nullable();
$table->decimal('latitude', 10, 8)->nullable();
$table->decimal('longitude', 11, 8)->nullable();
$table->foreignId('province_id')->constrained('PlaceProvince');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('PlaceMunicipality');
Schema::dropIfExists('PlaceProvince');
}
};

View File

@ -77,7 +77,12 @@ Route::middleware('auth:sanctum')->group( function () {
Route::get('/service_types', [ServiceTypeController::class, 'index']);
Route::post('/service_types', [ServiceTypeController::class, 'create']);
Route::get('/places/search', [PlacesController::class, 'search']);
Route::get('/places/reverse/search', [PlacesController::class, 'reverseSearch']);
Route::get('/places/italy/regions', [PlacesController::class, 'italyListRegions']);
Route::get('/places/italy/provinces/{region_name}', [PlacesController::class, 'italyListProvincesByRegion']);
Route::get('/places/italy/municipalities/{province_name}', [PlacesController::class, 'italyListMunicipalitiesByProvince']);
Route::get('/places/{id}', [PlacesController::class, 'show']);
Route::get('/trainings', [TrainingController::class, 'index'])->middleware(ETag::class);

View File

@ -101,7 +101,7 @@ export class MapPickerComponent implements OnInit {
});
return;
}
this.api.get("places/search", {
this.api.get("places/reverse/search", {
q: this.placeName
}).then((places) => {
this.isPlaceSearchResultsOpen = true;