feat(events): add exact_location field to events and update related logic
This commit is contained in:
@@ -12,14 +12,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['tenant_code', 'title', 'subtitle', 'description', 'location', 'date_text', 'published_at', 'attachment_id'])]
|
||||
#[Fillable(['tenant_code', 'title', 'subtitle', 'description', 'location', 'exact_location', 'date_text', 'published_at', 'attachment_id'])]
|
||||
class Event extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['published_at' => 'datetime'];
|
||||
return ['published_at' => 'datetime', 'exact_location' => 'array'];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Tenant, $this> */
|
||||
|
||||
@@ -19,6 +19,9 @@ class UpdateEventRequest extends FormRequest
|
||||
return [
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'location' => ['required', 'string', 'max:255'],
|
||||
'exact_location' => ['sometimes', 'nullable', 'array:latitude,longitude'],
|
||||
'exact_location.latitude' => ['required_with:exact_location', 'numeric', 'between:-90,90'],
|
||||
'exact_location.longitude' => ['required_with:exact_location', 'numeric', 'between:-180,180'],
|
||||
'attachment_id' => ['sometimes', 'nullable', 'integer', Rule::exists('attachments', 'id')->where('type', 'image')],
|
||||
'social_media' => ['sometimes', 'array'],
|
||||
'social_media.*' => ['required', 'array:code,url,orden'],
|
||||
|
||||
@@ -21,6 +21,7 @@ class EventResource extends JsonResource
|
||||
'subtitle' => $this->subtitle,
|
||||
'description' => $this->description,
|
||||
'location' => $this->location,
|
||||
'exact_location' => $this->exact_location,
|
||||
'date_text' => $this->date_text,
|
||||
'published_at' => $this->published_at?->toIso8601String(),
|
||||
'attachment_id' => $this->attachment_id,
|
||||
|
||||
@@ -15,6 +15,7 @@ class PublicEventResource extends JsonResource
|
||||
'subtitle' => $this->subtitle,
|
||||
'description' => $this->description,
|
||||
'location' => $this->location,
|
||||
'exact_location' => $this->exact_location,
|
||||
'date_text' => $this->date_text,
|
||||
'attachment_id' => $this->attachment_id,
|
||||
'image' => $this->attachment?->getTemporaryUrl(1440),
|
||||
|
||||
@@ -47,7 +47,7 @@ class EventService
|
||||
$event->update([
|
||||
'title' => $data['title'],
|
||||
'location' => $data['location'],
|
||||
...array_intersect_key($data, ['attachment_id' => true]),
|
||||
...array_intersect_key($data, ['attachment_id' => true, 'exact_location' => true]),
|
||||
]);
|
||||
$tenant->update([
|
||||
...array_intersect_key($data, array_flip([
|
||||
|
||||
@@ -10,6 +10,8 @@ Administra los eventos de un tenant, sus fechas y sus redes sociales.
|
||||
ubicación, texto de fechas y `published_at`. Sus fechas se guardan en `event_dates`
|
||||
mediante `event_id`. El catálogo `social_media` define las plataformas;
|
||||
`event_social_media` guarda la URL y el orden de cada cuenta del evento.
|
||||
`exact_location` guarda opcionalmente un objeto JSON con `latitude` (-90 a 90)
|
||||
y `longitude` (-180 a 180). `location` sigue siendo la dirección legible.
|
||||
|
||||
La migración `2026_09_18_000500_restore_events` crea un evento por cada tenant que
|
||||
tenía datos de evento o fechas, y migra las fechas y redes correspondientes.
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('events', function (Blueprint $table): void {
|
||||
$table->json('exact_location')->nullable()->after('location');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('events', function (Blueprint $table): void {
|
||||
$table->dropColumn('exact_location');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user