Skip to content

Commit 27ddb41

Browse files
smarcetromanetar
andauthored
feat: user stories get public endpoint (#251)
* WIP Change-Id: I9302fa3d9c4437a0b94bf19be7abeb4d2e60471c * feat: get user stories endpoint Signed-off-by: romanetar <roman_ag@hotmail.com> --------- Signed-off-by: romanetar <roman_ag@hotmail.com> Co-authored-by: romanetar <roman_ag@hotmail.com>
1 parent 9e29233 commit 27ddb41

14 files changed

Lines changed: 908 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php namespace App\Http\Controllers;
2+
/**
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use App\Models\Foundation\Main\Repositories\IUserStoryRepository;
16+
use models\oauth2\IResourceServerContext;
17+
use models\utils\IEntity;
18+
use ModelSerializers\SerializerRegistry;
19+
20+
/**
21+
* Class OAuth2UserStoriesApiController
22+
* @package App\Http\Controllers
23+
*/
24+
final class OAuth2UserStoriesApiController extends OAuth2ProtectedController
25+
{
26+
27+
use ParametrizedGetAll;
28+
29+
/**
30+
* OAuth2UserStoriesApiController constructor.
31+
* @param IUserStoryRepository $repository
32+
* @param IResourceServerContext $resource_server_context
33+
*/
34+
public function __construct
35+
(
36+
IUserStoryRepository $repository,
37+
IResourceServerContext $resource_server_context
38+
)
39+
{
40+
parent::__construct($resource_server_context);
41+
$this->repository = $repository;
42+
}
43+
44+
/**
45+
* @return mixed
46+
*/
47+
public function getAllUserStories()
48+
{
49+
return $this->_getAll(
50+
function () {
51+
return [
52+
'name' => ['=@', '==', '@@'],
53+
];
54+
},
55+
function () {
56+
return [
57+
'name' => 'sometimes|string',
58+
];
59+
},
60+
function () {
61+
return [
62+
'name',
63+
'id',
64+
];
65+
},
66+
function ($filter) {
67+
return $filter;
68+
},
69+
function () {
70+
return $this->getEntitySerializerType();
71+
}
72+
);
73+
}
74+
75+
protected function getEntitySerializerType(): string
76+
{
77+
$currentUser = $this->resource_server_context->getCurrentUser();
78+
return !is_null($currentUser) ? SerializerRegistry::SerializerType_Private :
79+
SerializerRegistry::SerializerType_Public;
80+
}
81+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php namespace App\ModelSerializers;
2+
/**
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
use ModelSerializers\SilverStripeSerializer;
15+
16+
/**
17+
* Class ContinentSerializer
18+
* @package App\ModelSerializers
19+
*/
20+
final class ContinentSerializer extends SilverStripeSerializer
21+
{
22+
protected static $array_mappings = [
23+
'Name' => 'name:json_string'
24+
];
25+
}

app/ModelSerializers/SerializerRegistry.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use App\ModelSerializers\Audit\SummitEventAuditLogSerializer;
1818
use App\ModelSerializers\CCLA\TeamSerializer;
1919
use App\ModelSerializers\Companies\BaseCompanySerializer;
20+
use App\ModelSerializers\ContinentSerializer;
2021
use App\ModelSerializers\Elections\CandidateSerializer;
2122
use App\ModelSerializers\Elections\ElectionSerializer;
2223
use App\ModelSerializers\Elections\NominationSerializer;
@@ -116,6 +117,8 @@
116117
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupAllowedTagSerializer;
117118
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupSerializer;
118119
use App\ModelSerializers\SummitScheduleFilterElementConfigSerializer;
120+
use App\ModelSerializers\UserStoriesIndustrySerializer;
121+
use App\ModelSerializers\UserStorySerializer;
119122
use Illuminate\Support\Facades\App;
120123
use Illuminate\Support\Facades\Log;
121124
use Libs\ModelSerializers\AbstractSerializer;
@@ -658,6 +661,12 @@ private function __construct()
658661

659662
// summit lead report setting
660663
$this->registry['SummitLeadReportSetting'] = SummitLeadReportSettingSerializer::class;
664+
665+
// user stories
666+
$this->registry['UserStory'] = UserStorySerializer::class;
667+
$this->registry['UserStoriesIndustry'] = UserStoriesIndustrySerializer::class;
668+
669+
$this->registry['Continent'] = ContinentSerializer::class;
661670
}
662671

663672
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php namespace App\ModelSerializers;
2+
/*
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use ModelSerializers\SilverStripeSerializer;
16+
17+
/**
18+
* Class UserStoriesIndustrySerializer
19+
* @package App\ModelSerializers
20+
*/
21+
class UserStoriesIndustrySerializer extends SilverStripeSerializer
22+
{
23+
protected static $array_mappings = [
24+
'Name' => 'name:json_string',
25+
'Active' => 'active:json_boolean',
26+
];
27+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php namespace App\ModelSerializers;
2+
/*
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use App\Models\Foundation\UserStories\UserStory;
16+
use Libs\ModelSerializers\Many2OneExpandSerializer;
17+
use Libs\ModelSerializers\One2ManyExpandSerializer;
18+
use ModelSerializers\SilverStripeSerializer;
19+
20+
/**
21+
* Class UserStorySerializer
22+
* @package App\ModelSerializers
23+
*/
24+
class UserStorySerializer extends SilverStripeSerializer
25+
{
26+
protected static $array_mappings = [
27+
'Name' => 'name:json_string',
28+
'Description' => 'description:json_string',
29+
'ShortDescription' => 'short_description:json_string',
30+
'Link' => 'link:json_string',
31+
'Active' => 'active:json_boolean',
32+
'MillionCoreClub' => 'is_million_core_club:json_boolean',
33+
'OrganizationId' => 'organization_id:json_int',
34+
'IndustryId' => 'industry_id:json_int',
35+
'LocationId' => 'location_id:json_int',
36+
'ImageId' => 'image_id:json_int',
37+
];
38+
39+
protected static $allowed_relations = [
40+
'tags'
41+
];
42+
43+
/**
44+
* @param null $expand
45+
* @param array $fields
46+
* @param array $relations
47+
* @param array $params
48+
* @return array
49+
*/
50+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
51+
{
52+
$user_story = $this->object;
53+
if(!$user_story instanceof UserStory) return [];
54+
$values = parent::serialize($expand, $fields, $relations, $params);
55+
56+
if(in_array('tags', $relations) && !isset($values['tags'])) {
57+
$tags = [];
58+
foreach ($user_story->getTags() as $tag) {
59+
$tags[] = $tag->getId();
60+
}
61+
$values['tags'] = $tags;
62+
}
63+
64+
return $values;
65+
}
66+
67+
protected static $expand_mappings = [
68+
'organization' => [
69+
'type' => One2ManyExpandSerializer::class,
70+
'original_attribute' => 'organization_id',
71+
'getter' => 'getOrganization',
72+
'has' => 'hasOrganization'
73+
],
74+
'industry' => [
75+
'type' => One2ManyExpandSerializer::class,
76+
'original_attribute' => 'industry_id',
77+
'getter' => 'getIndustry',
78+
'has' => 'hasIndustry'
79+
],
80+
'location' => [
81+
'type' => One2ManyExpandSerializer::class,
82+
'original_attribute' => 'location_id',
83+
'getter' => 'getLocation',
84+
'has' => 'hasLocation'
85+
],
86+
'image' => [
87+
'type' => One2ManyExpandSerializer::class,
88+
'original_attribute' => 'image_id',
89+
'getter' => 'getImage',
90+
'has' => 'hasImage'
91+
],
92+
'tags' => [
93+
'type' => Many2OneExpandSerializer::class,
94+
'getter' => 'getTags',
95+
],
96+
];
97+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php namespace App\Models\Foundation\Main;
2+
/**
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
use Doctrine\ORM\Mapping AS ORM;
15+
use models\utils\SilverstripeBaseModel;
16+
/**
17+
* @ORM\Entity
18+
* @ORM\Table(name="Continent")
19+
* Class Continent
20+
* @package App\Models\Foundation\Main
21+
*/
22+
class Continent extends SilverstripeBaseModel
23+
{
24+
/**
25+
* @ORM\Column(name="Name", type="string")
26+
* @var string
27+
*/
28+
private $name;
29+
30+
/**
31+
* @return string
32+
*/
33+
public function getName(): string
34+
{
35+
return $this->name;
36+
}
37+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php namespace App\Models\Foundation\Main\Repositories;
2+
3+
/**
4+
* Copyright 2024 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
16+
use models\utils\IBaseRepository;
17+
18+
/**
19+
* Interface IUserStoryRepository
20+
* @package App\Models\Foundation\Main\Repositories
21+
*/
22+
interface IUserStoryRepository extends IBaseRepository
23+
{
24+
25+
}

0 commit comments

Comments
 (0)