Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
25 changes: 25 additions & 0 deletions app/ModelSerializers/ContinentSerializer.php
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'
];
}
9 changes: 9 additions & 0 deletions app/ModelSerializers/SerializerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\ModelSerializers\Audit\SummitEventAuditLogSerializer;
use App\ModelSerializers\CCLA\TeamSerializer;
use App\ModelSerializers\Companies\BaseCompanySerializer;
use App\ModelSerializers\ContinentSerializer;
use App\ModelSerializers\Elections\CandidateSerializer;
use App\ModelSerializers\Elections\ElectionSerializer;
use App\ModelSerializers\Elections\NominationSerializer;
Expand Down Expand Up @@ -116,6 +117,8 @@
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupAllowedTagSerializer;
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupSerializer;
use App\ModelSerializers\SummitScheduleFilterElementConfigSerializer;
use App\ModelSerializers\UserStoriesIndustrySerializer;
use App\ModelSerializers\UserStorySerializer;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Libs\ModelSerializers\AbstractSerializer;
Expand Down Expand Up @@ -658,6 +661,12 @@ private function __construct()

// summit lead report setting
$this->registry['SummitLeadReportSetting'] = SummitLeadReportSettingSerializer::class;

// user stories
$this->registry['UserStory'] = UserStorySerializer::class;
$this->registry['UserStoriesIndustry'] = UserStoriesIndustrySerializer::class;

$this->registry['Continent'] = ContinentSerializer::class;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions app/ModelSerializers/UserStoriesIndustrySerializer.php
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',
];
}
97 changes: 97 additions & 0 deletions app/ModelSerializers/UserStorySerializer.php
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',
Comment thread
romanetar marked this conversation as resolved.
'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,
Comment thread
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',
],
];
}
37 changes: 37 additions & 0 deletions app/Models/Foundation/Main/Continent.php
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 app/Models/Foundation/Main/Repositories/IUserStoryRepository.php
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
{

}
Loading