-
Notifications
You must be signed in to change notification settings - Fork 2
feat: user stories get public endpoint #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
app/Http/Controllers/Apis/Protected/Main/OAuth2UserStoriesApiController.php
This file contains hidden or 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,81 @@ | ||
| <?php namespace App\Http\Controllers; | ||
| /** | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Models\Foundation\Main\Repositories\IUserStoryRepository; | ||
| use models\oauth2\IResourceServerContext; | ||
| use models\utils\IEntity; | ||
| use ModelSerializers\SerializerRegistry; | ||
|
|
||
| /** | ||
| * Class OAuth2UserStoriesApiController | ||
| * @package App\Http\Controllers | ||
| */ | ||
| final class OAuth2UserStoriesApiController extends OAuth2ProtectedController | ||
| { | ||
|
|
||
| use ParametrizedGetAll; | ||
|
|
||
| /** | ||
| * OAuth2UserStoriesApiController constructor. | ||
| * @param IUserStoryRepository $repository | ||
| * @param IResourceServerContext $resource_server_context | ||
| */ | ||
| public function __construct | ||
| ( | ||
| IUserStoryRepository $repository, | ||
| IResourceServerContext $resource_server_context | ||
| ) | ||
| { | ||
| parent::__construct($resource_server_context); | ||
| $this->repository = $repository; | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getAllUserStories() | ||
| { | ||
| return $this->_getAll( | ||
| function () { | ||
| return [ | ||
| 'name' => ['=@', '==', '@@'], | ||
| ]; | ||
| }, | ||
| function () { | ||
| return [ | ||
| 'name' => 'sometimes|string', | ||
| ]; | ||
| }, | ||
| function () { | ||
| return [ | ||
| 'name', | ||
| 'id', | ||
| ]; | ||
| }, | ||
| function ($filter) { | ||
| return $filter; | ||
| }, | ||
| function () { | ||
| return $this->getEntitySerializerType(); | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| protected function getEntitySerializerType(): string | ||
| { | ||
| $currentUser = $this->resource_server_context->getCurrentUser(); | ||
| return !is_null($currentUser) ? SerializerRegistry::SerializerType_Private : | ||
| SerializerRegistry::SerializerType_Public; | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| <?php namespace App\ModelSerializers; | ||
| /** | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
| use ModelSerializers\SilverStripeSerializer; | ||
|
|
||
| /** | ||
| * Class ContinentSerializer | ||
| * @package App\ModelSerializers | ||
| */ | ||
| final class ContinentSerializer extends SilverStripeSerializer | ||
| { | ||
| protected static $array_mappings = [ | ||
| 'Name' => 'name:json_string' | ||
| ]; | ||
| } |
This file contains hidden or 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 hidden or 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,27 @@ | ||
| <?php namespace App\ModelSerializers; | ||
| /* | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use ModelSerializers\SilverStripeSerializer; | ||
|
|
||
| /** | ||
| * Class UserStoriesIndustrySerializer | ||
| * @package App\ModelSerializers | ||
| */ | ||
| class UserStoriesIndustrySerializer extends SilverStripeSerializer | ||
| { | ||
| protected static $array_mappings = [ | ||
| 'Name' => 'name:json_string', | ||
| 'Active' => 'active:json_boolean', | ||
| ]; | ||
| } |
This file contains hidden or 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,97 @@ | ||
| <?php namespace App\ModelSerializers; | ||
| /* | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Models\Foundation\UserStories\UserStory; | ||
| use Libs\ModelSerializers\Many2OneExpandSerializer; | ||
| use Libs\ModelSerializers\One2ManyExpandSerializer; | ||
| use ModelSerializers\SilverStripeSerializer; | ||
|
|
||
| /** | ||
| * Class UserStorySerializer | ||
| * @package App\ModelSerializers | ||
| */ | ||
| class UserStorySerializer extends SilverStripeSerializer | ||
| { | ||
| protected static $array_mappings = [ | ||
| 'Name' => 'name:json_string', | ||
| 'Description' => 'description:json_string', | ||
| 'ShortDescription' => 'short_description:json_string', | ||
| 'Link' => 'link:json_string', | ||
| 'Active' => 'active:json_boolean', | ||
| 'MillionCoreClub' => 'is_million_core_club:json_boolean', | ||
| 'OrganizationId' => 'organization_id:json_int', | ||
| 'IndustryId' => 'industry_id:json_int', | ||
| 'LocationId' => 'location_id:json_int', | ||
| 'ImageId' => 'image_id:json_int', | ||
| ]; | ||
|
|
||
| protected static $allowed_relations = [ | ||
| 'tags' | ||
| ]; | ||
|
|
||
| /** | ||
| * @param null $expand | ||
| * @param array $fields | ||
| * @param array $relations | ||
| * @param array $params | ||
| * @return array | ||
| */ | ||
| public function serialize($expand = null, array $fields = [], array $relations = [], array $params = []) | ||
| { | ||
| $user_story = $this->object; | ||
| if(!$user_story instanceof UserStory) return []; | ||
| $values = parent::serialize($expand, $fields, $relations, $params); | ||
|
|
||
| if(in_array('tags', $relations) && !isset($values['tags'])) { | ||
| $tags = []; | ||
| foreach ($user_story->getTags() as $tag) { | ||
| $tags[] = $tag->getId(); | ||
| } | ||
| $values['tags'] = $tags; | ||
| } | ||
|
|
||
| return $values; | ||
| } | ||
|
|
||
| protected static $expand_mappings = [ | ||
| 'organization' => [ | ||
| 'type' => One2ManyExpandSerializer::class, | ||
| 'original_attribute' => 'organization_id', | ||
| 'getter' => 'getOrganization', | ||
| 'has' => 'hasOrganization' | ||
| ], | ||
| 'industry' => [ | ||
| 'type' => One2ManyExpandSerializer::class, | ||
| 'original_attribute' => 'industry_id', | ||
| 'getter' => 'getIndustry', | ||
| 'has' => 'hasIndustry' | ||
| ], | ||
| 'location' => [ | ||
| 'type' => One2ManyExpandSerializer::class, | ||
|
romanetar marked this conversation as resolved.
|
||
| 'original_attribute' => 'location_id', | ||
| 'getter' => 'getLocation', | ||
| 'has' => 'hasLocation' | ||
| ], | ||
| 'image' => [ | ||
| 'type' => One2ManyExpandSerializer::class, | ||
| 'original_attribute' => 'image_id', | ||
| 'getter' => 'getImage', | ||
| 'has' => 'hasImage' | ||
| ], | ||
| 'tags' => [ | ||
| 'type' => Many2OneExpandSerializer::class, | ||
| 'getter' => 'getTags', | ||
| ], | ||
| ]; | ||
| } | ||
This file contains hidden or 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,37 @@ | ||
| <?php namespace App\Models\Foundation\Main; | ||
| /** | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
| use Doctrine\ORM\Mapping AS ORM; | ||
| use models\utils\SilverstripeBaseModel; | ||
| /** | ||
| * @ORM\Entity | ||
| * @ORM\Table(name="Continent") | ||
| * Class Continent | ||
| * @package App\Models\Foundation\Main | ||
| */ | ||
| class Continent extends SilverstripeBaseModel | ||
| { | ||
| /** | ||
| * @ORM\Column(name="Name", type="string") | ||
| * @var string | ||
| */ | ||
| private $name; | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getName(): string | ||
| { | ||
| return $this->name; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
app/Models/Foundation/Main/Repositories/IUserStoryRepository.php
This file contains hidden or 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,25 @@ | ||
| <?php namespace App\Models\Foundation\Main\Repositories; | ||
|
|
||
| /** | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use models\utils\IBaseRepository; | ||
|
|
||
| /** | ||
| * Interface IUserStoryRepository | ||
| * @package App\Models\Foundation\Main\Repositories | ||
| */ | ||
| interface IUserStoryRepository extends IBaseRepository | ||
| { | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.