Lint
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2024-01-28 18:28:09 +01:00
parent d14a373a76
commit 52b7e39d4c
7 changed files with 5 additions and 86 deletions

View File

@ -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<self> $query
*
* @return Builder<self>
*/
public function scopeWithFilter(Builder $query, ActivityFilterScope $filter): Builder
{
return $filter->apply($query);
}
/**
* @return BelongsToMany<Subactivity>
*/

View File

@ -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(),
]);
}
}

View File

@ -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'),

View File

@ -1,43 +0,0 @@
<?php
namespace App\Http\Views;
use App\Activity;
use App\Lib\Filter;
use Illuminate\Database\Eloquent\Builder;
use Laravel\Scout\Builder as ScoutBuilder;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
/**
* @extends Filter<Activity>
*/
#[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<Activity> $query
*
* @return Builder<Activity>
*/
public function apply(Builder $query): Builder
{
if ($this->subactivityId) {
$query->whereHas('subactivities', fn ($query) => $query->where('id', $this->subactivityId));
}
return $query;
}
}

View File

@ -14,7 +14,7 @@ abstract class Filter extends Data
{
/**
* @return self<T>
* @return Builder
*/
abstract public function getQuery(): Builder;
protected Builder $query;

View File

@ -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]),

View File

@ -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'));
}
}