mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-11 14:50:30 +00:00
✨ **Add authenticated API endpoints for managing Meetups, Cities, Venues, and Lecturers**
- ➕ Introduced `store`, `update`, `mine`, and `mineShow` endpoints for `Meetups`, `Cities`, `Venues`, and `Lecturers` with validation and authorization. - 🔒 Added `Policies` for `Meetups`, `Cities`, `Venues`, and `Lecturers` leveraging `ChecksCreatorOwnership` for ownership checks. - 🌐 Created `Resources` for structured API responses: `MeetupResource`, `CityResource`, `VenueResource`, and `LecturerResource`. - ✅ Added dedicated `Request` classes for input validation: `Store` and `Update` variants for all models. - 🛠️ Updated controllers to support new functionalities with localized error messages and proper HTTP responses.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Models\City;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreCityRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create', City::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'country_id' => ['required', 'integer', 'exists:countries,id'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'longitude' => ['required', 'numeric'],
|
||||
'latitude' => ['required', 'numeric'],
|
||||
'population' => ['nullable', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'country_id.exists' => 'Das angegebene Land existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Models\Lecturer;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreLecturerRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create', Lecturer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'subtitle' => ['nullable', 'string'],
|
||||
'intro' => ['nullable', 'string'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'active' => ['boolean'],
|
||||
'website' => ['nullable', 'url', 'max:255'],
|
||||
'twitter_username' => ['nullable', 'string', 'max:255'],
|
||||
'nostr' => ['nullable', 'string', 'max:255'],
|
||||
'lightning_address' => ['nullable', 'string', 'max:255'],
|
||||
'lnurl' => ['nullable', 'string'],
|
||||
'node_id' => ['nullable', 'string', 'max:255'],
|
||||
'paynym' => ['nullable', 'string'],
|
||||
'team_id' => ['nullable', 'integer', 'exists:teams,id'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'team_id.exists' => 'Das angegebene Team existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Enums\RecurrenceType;
|
||||
use App\Models\MeetupEvent;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreMeetupEventRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create', MeetupEvent::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'meetup_id' => ['required', 'integer', 'exists:meetups,id'],
|
||||
'start' => ['required', 'date'],
|
||||
'location' => ['nullable', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'link' => ['nullable', 'url', 'max:255'],
|
||||
'recurrence_type' => ['nullable', Rule::enum(RecurrenceType::class)],
|
||||
'recurrence_day_of_week' => ['nullable', 'string', 'max:255'],
|
||||
'recurrence_day_position' => ['nullable', 'string', 'max:255'],
|
||||
'recurrence_interval' => ['nullable', 'integer'],
|
||||
'recurrence_end_date' => ['nullable', 'date', 'after_or_equal:start'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'meetup_id.exists' => 'Das angegebene Meetup existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Models\Meetup;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreMeetupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create', Meetup::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'city_id' => ['required', 'integer', 'exists:cities,id'],
|
||||
'intro' => ['nullable', 'string'],
|
||||
'telegram_link' => ['nullable', 'url', 'max:255'],
|
||||
'webpage' => ['nullable', 'url', 'max:255'],
|
||||
'twitter_username' => ['nullable', 'string', 'max:255'],
|
||||
'matrix_group' => ['nullable', 'string', 'max:255'],
|
||||
'nostr' => ['nullable', 'string'],
|
||||
'simplex' => ['nullable', 'string'],
|
||||
'signal' => ['nullable', 'string', 'max:255'],
|
||||
'community' => ['nullable', 'string', 'max:255'],
|
||||
'visible_on_map' => ['boolean'],
|
||||
'is_active' => ['boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'city_id.exists' => 'Die angegebene Stadt existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Models\Venue;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreVenueRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create', Venue::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'city_id' => ['required', 'integer', 'exists:cities,id'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'street' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'city_id.exists' => 'Die angegebene Stadt existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateCityRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('update', $this->route('city'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'country_id' => ['sometimes', 'required', 'integer', 'exists:countries,id'],
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'longitude' => ['sometimes', 'required', 'numeric'],
|
||||
'latitude' => ['sometimes', 'required', 'numeric'],
|
||||
'population' => ['sometimes', 'nullable', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'country_id.exists' => 'Das angegebene Land existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateLecturerRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('update', $this->route('lecturer'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'subtitle' => ['sometimes', 'nullable', 'string'],
|
||||
'intro' => ['sometimes', 'nullable', 'string'],
|
||||
'description' => ['sometimes', 'nullable', 'string'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'website' => ['sometimes', 'nullable', 'url', 'max:255'],
|
||||
'twitter_username' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'nostr' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'lightning_address' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'lnurl' => ['sometimes', 'nullable', 'string'],
|
||||
'node_id' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'paynym' => ['sometimes', 'nullable', 'string'],
|
||||
'team_id' => ['sometimes', 'nullable', 'integer', 'exists:teams,id'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'team_id.exists' => 'Das angegebene Team existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Enums\RecurrenceType;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateMeetupEventRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('update', $this->route('meetupEvent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'meetup_id' => ['sometimes', 'required', 'integer', 'exists:meetups,id'],
|
||||
'start' => ['sometimes', 'required', 'date'],
|
||||
'location' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'description' => ['sometimes', 'nullable', 'string'],
|
||||
'link' => ['sometimes', 'nullable', 'url', 'max:255'],
|
||||
'recurrence_type' => ['sometimes', 'nullable', Rule::enum(RecurrenceType::class)],
|
||||
'recurrence_day_of_week' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'recurrence_day_position' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'recurrence_interval' => ['sometimes', 'nullable', 'integer'],
|
||||
'recurrence_end_date' => ['sometimes', 'nullable', 'date', 'after_or_equal:start'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'meetup_id.exists' => 'Das angegebene Meetup existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateMeetupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('update', $this->route('meetup'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'city_id' => ['sometimes', 'required', 'integer', 'exists:cities,id'],
|
||||
'intro' => ['sometimes', 'nullable', 'string'],
|
||||
'telegram_link' => ['sometimes', 'nullable', 'url', 'max:255'],
|
||||
'webpage' => ['sometimes', 'nullable', 'url', 'max:255'],
|
||||
'twitter_username' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'matrix_group' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'nostr' => ['sometimes', 'nullable', 'string'],
|
||||
'simplex' => ['sometimes', 'nullable', 'string'],
|
||||
'signal' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'community' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'visible_on_map' => ['sometimes', 'boolean'],
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'city_id.exists' => 'Die angegebene Stadt existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateVenueRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('update', $this->route('venue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'city_id' => ['sometimes', 'required', 'integer', 'exists:cities,id'],
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'street' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'city_id.exists' => 'Die angegebene Stadt existiert nicht.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user