diff --git a/app/Activity.php b/app/Activity.php index 2ab00d8f..61218012 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -2,10 +2,8 @@ namespace App; -use App\Http\Views\ActivityFilterScope; use App\Nami\HasNamiField; use Cviebrock\EloquentSluggable\Sluggable; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -33,16 +31,6 @@ class Activity extends Model ]; } - /** - * @param Builder $query - * - * @return Builder - */ - public function scopeWithFilter(Builder $query, ActivityFilterScope $filter): Builder - { - return $filter->apply($query); - } - /** * @return BelongsToMany */ diff --git a/app/Activity/Actions/IndexAction.php b/app/Activity/Actions/IndexAction.php index 5c194231..f86ae731 100644 --- a/app/Activity/Actions/IndexAction.php +++ b/app/Activity/Actions/IndexAction.php @@ -4,7 +4,6 @@ namespace App\Activity\Actions; use App\Activity; use App\Activity\Resources\ActivityResource; -use App\Http\Views\ActivityFilterScope; use Illuminate\Http\Resources\Json\AnonymousResourceCollection; use Inertia\Inertia; use Inertia\Response; @@ -15,19 +14,18 @@ class IndexAction { use AsAction; - public function handle(ActivityFilterScope $filter): AnonymousResourceCollection + public function handle(): AnonymousResourceCollection { - return ActivityResource::collection(Activity::withFilter($filter)->paginate(20)); + return ActivityResource::collection(Activity::paginate(20)); } public function asController(ActionRequest $request): Response { session()->put('menu', 'activity'); session()->put('title', 'Tätigkeiten'); - $filter = ActivityFilterScope::fromRequest($request->input('filter')); return Inertia::render('activity/VIndex', [ - 'data' => $this->handle($filter), + 'data' => $this->handle(), ]); } } diff --git a/app/Activity/Resources/ActivityResource.php b/app/Activity/Resources/ActivityResource.php index 4bf99653..78f5339e 100644 --- a/app/Activity/Resources/ActivityResource.php +++ b/app/Activity/Resources/ActivityResource.php @@ -3,7 +3,6 @@ namespace App\Activity\Resources; use App\Activity; -use App\Http\Views\ActivityFilterScope; use App\Lib\HasMeta; use App\Resources\SubactivityResource; use App\Subactivity; @@ -51,7 +50,6 @@ class ActivityResource extends JsonResource { return [ 'subactivities' => SubactivityResource::collectionWithoutMeta(Subactivity::get()), - 'filter' => ActivityFilterScope::fromRequest(request()->input('filter')), 'links' => [ 'index' => route('activity.index'), 'create' => route('activity.create'), diff --git a/app/Http/Views/ActivityFilterScope.php b/app/Http/Views/ActivityFilterScope.php deleted file mode 100644 index e557e55c..00000000 --- a/app/Http/Views/ActivityFilterScope.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -#[MapInputName(SnakeCaseMapper::class)] -#[MapOutputName(SnakeCaseMapper::class)] -class ActivityFilterScope extends Filter -{ - public function __construct( - public ?int $subactivityId = null, - ) { - } - - public function getQuery(): ScoutBuilder - { - return Activity::search(''); - } - - /** - * @param Builder $query - * - * @return Builder - */ - public function apply(Builder $query): Builder - { - if ($this->subactivityId) { - $query->whereHas('subactivities', fn ($query) => $query->where('id', $this->subactivityId)); - } - - return $query; - } -} diff --git a/app/Lib/Filter.php b/app/Lib/Filter.php index 23345679..f2a0d54b 100644 --- a/app/Lib/Filter.php +++ b/app/Lib/Filter.php @@ -14,7 +14,7 @@ abstract class Filter extends Data { /** - * @return self + * @return Builder */ abstract public function getQuery(): Builder; protected Builder $query; diff --git a/app/Member/Member.php b/app/Member/Member.php index 3320b758..d508014e 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -499,7 +499,7 @@ class Member extends Model implements Geolocatable 'lastname' => $this->lastname, 'birthday' => $this->birthday?->format('Y-m-d'), 'ausstand' => $this->getAusstand(), - 'bill_kind' => $this->bill_kind?->value, + 'bill_kind' => $this->bill_kind->value, 'group_id' => $this->group->id, 'memberships' => $this->memberships()->active()->get() ->map(fn ($membership) => [...$membership->only('activity_id', 'subactivity_id'), 'both' => $membership->activity_id . '|' . $membership->subactivity_id]), diff --git a/tests/Feature/Activity/IndexTest.php b/tests/Feature/Activity/IndexTest.php index 5ff9e1b0..97b3cc9d 100644 --- a/tests/Feature/Activity/IndexTest.php +++ b/tests/Feature/Activity/IndexTest.php @@ -25,26 +25,4 @@ class IndexTest extends TestCase $this->assertInertiaHas(route('membership.masslist.index'), $response, 'data.meta.links.membership_masslist'); $this->assertCount(2, $this->inertia($response, 'data.data')); } - - public function testItDisplaysDefaultFilter(): void - { - $this->login()->loginNami()->withoutExceptionHandling(); - - $response = $this->callFilter('activity.index', []); - - $this->assertInertiaHas(null, $response, 'data.meta.filter.subactivity'); - } - - public function testItFiltersActivityBySubactivity(): void - { - $this->login()->loginNami()->withoutExceptionHandling(); - $subactivity = Subactivity::factory()->name('jjon')->create(); - Activity::factory()->name('Local')->hasAttached($subactivity)->create(); - Activity::factory()->count(2)->name('Local')->create(); - - $response = $this->callFilter('activity.index', ['subactivity_id' => $subactivity->id]); - - $this->assertInertiaHas($subactivity->id, $response, 'data.meta.filter.subactivity_id'); - $this->assertCount(1, $this->inertia($response, 'data.data')); - } }