Compare commits
4 Commits
e6cf452501
...
2b3251d41a
Author | SHA1 | Date |
---|---|---|
renovate[bot] | 2b3251d41a | |
Matteo Gheza | 193710d14c | |
Matteo Gheza | 687d7613a0 | |
Matteo Gheza | 6b7ed390a8 |
|
@ -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()]);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
];
|
||||
}
|
|
@ -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 .= " 🚒";
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
};
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue