-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create necessary endpoints and filters
- Loading branch information
1 parent
afaae1c
commit b9593b8
Showing
14 changed files
with
298 additions
and
24 deletions.
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,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\OrganizationsRequest; | ||
use App\Http\Resources\OrganizationResource; | ||
use App\Models\Organization; | ||
|
||
class OrganizationController extends Controller | ||
{ | ||
public function index(OrganizationsRequest $request) { | ||
$organizations = Organization::with(['building', 'activities']) | ||
->filter($request->get('filter')) | ||
->jsonPaginate(); | ||
|
||
return OrganizationResource::collection($organizations) | ||
->response(); | ||
} | ||
|
||
public function show(Organization $organization) { | ||
if ($organization->status != Organization::STATUS_ACTIVE) { | ||
abort(404); | ||
} | ||
$organization->load(['building', 'activities']); | ||
|
||
return (new OrganizationResource($organization))->response(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class OrganizationsRequest extends FormRequest | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'filter' => ['sometimes', 'nullable', 'array'], | ||
'filter.building_id' => ['sometimes', 'nullable', 'exists:buildings,id'], | ||
'filter.activity_id' => ['sometimes', 'nullable', 'exists:activities,id'], | ||
'filter.name' => ['sometimes', 'nullable', 'string', 'min:2', 'max:15'], | ||
'filter.activity_name' => ['sometimes', 'nullable', 'string', 'min:2', 'max:15'], | ||
'filter.circle' => ['sometimes', 'nullable', 'array', 'min:3', 'max:3'], | ||
'filter.circle.latitude' => ['required_with:filter.circle', 'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'], | ||
'filter.circle.longitude' => ['required_with:filter.circle', 'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'], | ||
'filter.circle.radius' => ['required_with:filter.circle', 'numeric', 'min:0.1', 'max:250'], | ||
'filter.square' => ['sometimes', 'nullable', 'array', 'min:4', 'max:4'], | ||
'filter.square.latitude' => ['required_with:filter.square', 'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'], | ||
'filter.square.longitude' => ['required_with:filter.square', 'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'], | ||
'filter.square.width' => ['required_with:filter.square', 'numeric', 'min:0.1', 'max:250'], | ||
'filter.square.height' => ['required_with:filter.square', 'numeric', 'min:0.1', 'max:250'], | ||
]; | ||
} | ||
|
||
public function messages() | ||
{ | ||
return [ | ||
|
||
]; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
class OrganizationResource extends JsonResource | ||
{ | ||
public function toArray($request) | ||
{ | ||
return parent::toArray($request); | ||
} | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,64 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
* The maximum number of results that will be returned | ||
* when using the JSON API paginator. | ||
*/ | ||
'max_results' => 30, | ||
|
||
/* | ||
* The default number of results that will be returned | ||
* when using the JSON API paginator. | ||
*/ | ||
'default_size' => 10, | ||
|
||
/* | ||
* The key of the page[x] query string parameter for page number. | ||
*/ | ||
'number_parameter' => 'number', | ||
|
||
/* | ||
* The key of the page[x] query string parameter for page size. | ||
*/ | ||
'size_parameter' => 'size', | ||
|
||
/* | ||
* The key of the page[x] query string parameter for cursor. | ||
*/ | ||
'cursor_parameter' => 'cursor', | ||
|
||
/* | ||
* The name of the macro that is added to the Eloquent query builder. | ||
*/ | ||
'method_name' => 'jsonPaginate', | ||
|
||
/* | ||
* If you only need to display Next and Previous links, you may use | ||
* simple pagination to perform a more efficient query. | ||
*/ | ||
'use_simple_pagination' => false, | ||
|
||
/* | ||
* If you want to use cursor pagination, set this to true. | ||
* This would override use_simple_pagination. | ||
*/ | ||
'use_cursor_pagination' => false, | ||
|
||
/* | ||
* use simpleFastPaginate() or fastPaginate from https://github.com/hammerstonedev/fast-paginate | ||
* use may installed it via `composer require hammerstone/fast-paginate` | ||
*/ | ||
'use_fast_pagination' => false, | ||
|
||
/* | ||
* Here you can override the base url to be used in the link items. | ||
*/ | ||
'base_url' => null, | ||
|
||
/* | ||
* The name of the query parameter used for pagination | ||
*/ | ||
'pagination_parameter' => 'page', | ||
]; |
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
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
Oops, something went wrong.