Skip to content

Commit

Permalink
Fix code review
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Feb 28, 2024
1 parent 6d9e54e commit f0d033c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
16 changes: 14 additions & 2 deletions app/Http/Controllers/OrganizationController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Resources\OrganizationResource;
Expand All @@ -12,14 +14,24 @@ public function __invoke()
return OrganizationResource::collection(
Organisation::query()
->withoutEagerLoads(['city'])
->select(['id', 'name', 'county_id'])
->select([
'id',
'name',
'county_id',
'type',
'status',
'area',
'created_at',
'updated_at',
])
->with([
'riskCategories',
'activityCounties',
'expertises',
'resourceTypes',
'county',
])
->with('volunteers')
->withCount('volunteers')
->get()
);
}
Expand Down
17 changes: 11 additions & 6 deletions app/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Resources\ResourceResource;
Expand All @@ -11,13 +13,16 @@ public function __invoke()
{
return ResourceResource::collection(
Resource::query()
->with('county')
->with('organisation')
->with('category')
->with('subcategory')
->with('types')
->with([
'county',
'category',
'subcategory',
'types',
'organisation' => fn ($query) => $query
->withoutEagerLoads()
->select('id', 'name'),
])
->get()
);
}

}
22 changes: 13 additions & 9 deletions app/Http/Resources/OrganizationResource.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
Expand All @@ -14,18 +16,20 @@ class OrganizationResource extends JsonResource
*/
public function toArray(Request $request): array
{
return ['id' => $this->id,
return [
'id' => $this->id,
'name' => $this->name,
'type' => $this->type,
'status' => $this->status,
'expertises_area' => IdAndNameResource::collection($this->expertises),
'risc_category' => IdAndNameResource::collection($this->riskCategories),
'action_type' => IdAndNameResource::collection($this->resourceTypes),
'activity_area' => $this->area,
'county' => IdAndNameResource::collection($this->activityCounties),
'created_at' => $this->created_at->format("Y-m-d H:i:s"),
'updated_at' => $this->updated_at->format("Y-m-d H:i:s"),
'volunteers_count' => $this->volunteers->count(),
'expertises' => IdAndNameResource::collection($this->expertises),
'risk_categories' => IdAndNameResource::collection($this->riskCategories),
'resource_types' => IdAndNameResource::collection($this->resourceTypes),
'area' => $this->area,
'county' => $this->county->name,
'activity_counties' => IdAndNameResource::collection($this->activityCounties),
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at->format('Y-m-d H:i:s'),
'volunteers_count' => $this->volunteers_count,
];
}
}
14 changes: 8 additions & 6 deletions app/Http/Resources/ResourceResource.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
Expand All @@ -14,16 +16,16 @@ class ResourceResource extends JsonResource
*/
public function toArray(Request $request): array
{
return ['id' => $this->id,
return [
'id' => $this->id,
'name' => $this->name,
'county' => IdAndNameResource::make($this->county),
'county' => $this->county->name,
'organization' => IdAndNameResource::make($this->organisation),
'category' => IdAndNameResource::make($this->category),
'subcategory' => IdAndNameResource::make($this->subcategory),
// 'types' => IdAndNameResource::collection($this->types),
'created_at' => $this->created_at->format("Y-m-d H:i:s"),
'updated_at' => $this->updated_at->format("Y-m-d H:i:s"),
'types' => IdAndNameResource::collection($this->types),
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at->format('Y-m-d H:i:s'),
];

}
}

0 comments on commit f0d033c

Please sign in to comment.