-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Api DSU * Apply suggestions from code review * Fix code review * rename organization in organisation --------- Co-authored-by: Andrei Ioniță <[email protected]>
- Loading branch information
1 parent
a2831ce
commit d4628a5
Showing
7 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Resources\OrganisationResource; | ||
use App\Models\Organisation; | ||
|
||
class OrganisationController extends Controller | ||
{ | ||
public function __invoke() | ||
{ | ||
return OrganisationResource::collection( | ||
Organisation::query() | ||
->withoutEagerLoads(['city']) | ||
->select([ | ||
'id', | ||
'name', | ||
'county_id', | ||
'type', | ||
'status', | ||
'area', | ||
'created_at', | ||
'updated_at', | ||
]) | ||
->with([ | ||
'riskCategories', | ||
'activityCounties', | ||
'expertises', | ||
'resourceTypes', | ||
'county', | ||
]) | ||
->withCount('volunteers') | ||
->get() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Resources\ResourceResource; | ||
use App\Models\Resource; | ||
|
||
class ResourceController extends Controller | ||
{ | ||
public function __invoke() | ||
{ | ||
return ResourceResource::collection( | ||
Resource::query() | ||
->with([ | ||
'county', | ||
'category', | ||
'subcategory', | ||
'types', | ||
'organisation' => fn ($query) => $query | ||
->withoutEagerLoads() | ||
->select('id', 'name'), | ||
]) | ||
->get() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class IdAndNameResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'name' => $this->name | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class OrganisationResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'name' => $this->name, | ||
'type' => $this->type, | ||
'status' => $this->status, | ||
'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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ResourceResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'name' => $this->name, | ||
'county' => $this->county->name, | ||
'organisation' => 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'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters