Added new endpoint get track tag group allowed tags per Summit

GET /api/v1/summits/{id}/track-tag-groups/all/allowed-tag

params

page
per_page
filter: (tag ['=@', '=='])
order: tag, id
expand: tag, track_tag_group

required scopes

%s/summits/read/all

Change-Id: I2da843bb36ab1a51ade665e55e532146d89f853b
This commit is contained in:
Sebastian Marcet 2018-09-05 18:36:42 -03:00
parent 92bd96de5b
commit 8cf26d9f11
13 changed files with 519 additions and 4 deletions

View File

@ -80,7 +80,6 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
*/
private $selection_plan_repository;
/**
* @var ISummitService
*/
@ -316,6 +315,9 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
}
}
/**
* @return mixed
*/
public function getMySpeaker()
{
try {

View File

@ -0,0 +1,144 @@
<?php namespace App\Http\Controllers;
/**
* Copyright 2018 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\Summit\Repositories\ITrackTagGroupAllowedTagsRepository;
use models\oauth2\IResourceServerContext;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use utils\Filter;
use utils\FilterParser;
use utils\FilterParserException;
use utils\OrderParser;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Log;
use utils\PagingInfo;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\summit\ISummitRepository;
/**
* Class OAuth2SummitTrackTagGroupsApiController
* @package App\Http\Controllers
*/
final class OAuth2SummitTrackTagGroupsApiController extends OAuth2ProtectedController
{
/**
* @var ISummitRepository
*/
private $summit_repository;
/**
* OAuth2SummitTrackTagGroupsApiController constructor.
* @param ISummitRepository $summit_repository
* @param ITrackTagGroupAllowedTagsRepository $repository
* @param IResourceServerContext $resource_server_context
*/
public function __construct
(
ISummitRepository $summit_repository,
ITrackTagGroupAllowedTagsRepository $repository,
IResourceServerContext $resource_server_context
)
{
parent::__construct($resource_server_context);
$this->summit_repository = $summit_repository;
$this->repository = $repository;
}
public function getAllowedTags($summit_id){
$values = Input::all();
$rules = array
(
'page' => 'integer|min:1',
'per_page' => 'required_with:page|integer|min:5|max:100',
);
try {
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();
$validation = Validator::make($values, $rules);
if ($validation->fails()) {
$ex = new ValidationException();
throw $ex->setMessages($validation->messages()->toArray());
}
// default values
$page = 1;
$per_page = 5;
if (Input::has('page')) {
$page = intval(Input::get('page'));
$per_page = intval(Input::get('per_page'));
}
$filter = null;
if (Input::has('filter')) {
$filter = FilterParser::parse(Input::get('filter'), array
(
'tag' => ['=@', '=='],
));
}
$order = null;
if (Input::has('order'))
{
$order = OrderParser::parse(Input::get('order'), array
(
'tag',
'id',
));
}
if(is_null($filter)) $filter = new Filter();
$data = $this->repository->getBySummit($summit, new PagingInfo($page, $per_page), $filter, $order);
$fields = Request::input('fields', '');
$fields = !empty($fields) ? explode(',', $fields) : [];
$relations = Request::input('relations', '');
$relations = !empty($relations) ? explode(',', $relations) : [];
return $this->ok
(
$data->toArray
(
Request::input('expand', ''),
$fields,
$relations
)
);
}
catch (EntityNotFoundException $ex1) {
Log::warning($ex1);
return $this->error404();
}
catch (ValidationException $ex2) {
Log::warning($ex2);
return $this->error412($ex2->getMessages());
}
catch(FilterParserException $ex3){
Log::warning($ex3);
return $this->error412($ex3->getMessages());
}
catch (\Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}

View File

@ -434,7 +434,7 @@ Route::group([
Route::post('{external_order_id}/external-attendees/{external_attendee_id}/confirm', 'OAuth2SummitApiController@confirmExternalOrderAttendee');
});
// member
// members
Route::group(array('prefix' => 'members'), function () {
Route::group(array('prefix' => '{member_id}'), function () {
Route::get('', 'OAuth2SummitMembersApiController@getMyMember')->where('member_id', 'me');
@ -527,6 +527,15 @@ Route::group([
});
});
Route::group(['prefix' => 'track-tag-groups'], function(){
Route::group(['prefix' => 'all'], function(){
Route::group(['prefix' => 'allowed-tags'], function(){
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
'uses' => 'OAuth2SummitTrackTagGroupsApiController@getAllowedTags']);
});
});
});
});
});

View File

@ -53,6 +53,7 @@ use App\ModelSerializers\Summit\RSVPTemplateSerializer;
use App\ModelSerializers\Summit\ScheduledSummitLocationBannerSerializer;
use App\ModelSerializers\Summit\SelectionPlanSerializer;
use App\ModelSerializers\Summit\SummitLocationBannerSerializer;
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupAllowedTagSerializer;
use Libs\ModelSerializers\IModelSerializer;
use ModelSerializers\ChatTeams\ChatTeamInvitationSerializer;
use ModelSerializers\ChatTeams\ChatTeamMemberSerializer;
@ -187,6 +188,11 @@ final class SerializerRegistry
$this->registry['SummitLocationImage'] = SummitLocationImageSerializer::class;
$this->registry['SummitLocationBanner'] = SummitLocationBannerSerializer::class;
$this->registry['ScheduledSummitLocationBanner'] = ScheduledSummitLocationBannerSerializer::class;
// track tag grousp
$this->registry['TrackTagGroup'] = TrackTagGroupSerializer::class;
$this->registry['TrackTagGroupAllowedTag'] = TrackTagGroupAllowedTagSerializer::class;
// member
$this->registry['Member'] = [
self::SerializerType_Public => PublicMemberSerializer::class,

View File

@ -0,0 +1,67 @@
<?php namespace App\ModelSerializers\Summit\TrackTagGroups;
/**
* Copyright 2018 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\Summit\TrackTagGroupAllowedTag;
use Libs\ModelSerializers\AbstractSerializer;
use ModelSerializers\SerializerRegistry;
/**
* Class TrackTagGroupAllowedTagSerializer
* @package App\ModelSerializers\Summit\TrackTagGroups
*/
final class TrackTagGroupAllowedTagSerializer extends AbstractSerializer
{
protected static $array_mappings = [
'Default' => 'is_default:json_boolean',
'TrackTagGroupId' => 'track_tag_group_id:json_int',
'TagId' => 'tag_id:json_int',
'SummitId' => 'summit_id:json_int',
];
/**
* @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 = [])
{
$allowed_tag = $this->object;
if (!$allowed_tag instanceof TrackTagGroupAllowedTag) return [];
$values = parent::serialize($expand, $fields, $relations, $params);
if (!empty($expand)) {
$relations = explode(',', $expand);
foreach ($relations as $relation) {
switch (trim($relation)) {
case 'track_tag_group':{
unset($values['track_tag_group_id']);
$values['track_tag_group'] = SerializerRegistry::getInstance()->getSerializer($allowed_tag->getTrackTagGroup())->serialize();
}
break;
case 'tag':{
unset($values['tag_id']);
$values['tag'] = SerializerRegistry::getInstance()->getSerializer($allowed_tag->getTag())->serialize();
}
break;
}
}
}
return $values;
}
}

View File

@ -0,0 +1,43 @@
<?php namespace App\ModelSerializers\Summit\TrackTagGroups;
/**
* Copyright 2018 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 TrackTagGroupSerializer
* @package App\ModelSerializers\Summit\TrackTagGroups
*/
final class TrackTagGroupSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Name' => 'name:json_string',
'Label' => 'label:json_string',
'Order' => 'order:json_int',
'isMandatory' => 'is_mandatory:json_boolean',
'SummitId' => 'summit_id:json_int',
];
/**
* @param null $expand
* @param array $fields
* @param array $relations
* @param array $params
* @return array
*/
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() )
{
$values = parent::serialize($expand, $fields, $relations, $params);
$track_tag_group = $this->object;
return $values;
}
}

View File

@ -0,0 +1,22 @@
<?php namespace App\Models\Foundation\Summit\Repositories;
/**
* Copyright 2018 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.
**/
/**
* Interface ITrackTagGroupAllowedTagsRepository
* @package App\Models\Foundation\Summit\Repositories
*/
interface ITrackTagGroupAllowedTagsRepository extends ISummitOwnedEntityRepository
{
}

View File

@ -142,5 +142,4 @@ class TrackTagGroup extends SilverstripeBaseModel
$this->allowed_tags = new ArrayCollection;
}
}

View File

@ -18,7 +18,7 @@ use models\summit\SummitOwned;
use models\utils\SilverstripeBaseModel;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineTrackTagGroupAllowedTagsRepository")
* @ORM\Table(name="TrackTagGroup_AllowedTags")
* Class TrackTagGroupAllowedTag
* @package models\summit\TrackTagGroupAllowedTag
@ -45,6 +45,43 @@ class TrackTagGroupAllowedTag extends BaseEntity
*/
private $track_tag_group;
/**
* @return int
*/
public function getTrackTagGroupId(){
try {
return is_null($this->track_tag_group) ? 0 : $this->track_tag_group->getId();
}
catch(\Exception $ex){
return 0;
}
}
/**
* @return int
*/
public function getSummitId(){
try {
return is_null($this->track_tag_group) ? 0 : $this->track_tag_group->getSummitId();
}
catch(\Exception $ex){
return 0;
}
}
/**
* @return int
*/
public function getTagId(){
try {
return is_null($this->tag) ? 0 : $this->tag->getId();
}
catch(\Exception $ex){
return 0;
}
}
/**
* @return bool
*/

View File

@ -23,7 +23,9 @@ use App\Models\Foundation\Summit\Repositories\ISummitEventTypeRepository;
use App\Models\Foundation\Summit\Repositories\ISummitLocationBannerRepository;
use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository;
use App\Models\Foundation\Summit\Repositories\ISummitTrackRepository;
use App\Models\Foundation\Summit\Repositories\ITrackTagGroupAllowedTagsRepository;
use App\Models\Foundation\Summit\SelectionPlan;
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;
use LaravelDoctrine\ORM\Facades\EntityManager;
@ -336,5 +338,13 @@ final class RepositoriesProvider extends ServiceProvider
return EntityManager::getRepository(SelectionPlan::class);
}
);
App::singleton(
ITrackTagGroupAllowedTagsRepository::class,
function(){
return EntityManager::getRepository(TrackTagGroupAllowedTag::class);
}
);
}
}

View File

@ -0,0 +1,119 @@
<?php namespace App\Repositories\Summit;
/**
* Copyright 2018 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\Summit\Repositories\ITrackTagGroupAllowedTagsRepository;
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
use App\Repositories\SilverStripeDoctrineRepository;
use Doctrine\ORM\Tools\Pagination\Paginator;
use models\summit\Summit;
use utils\DoctrineFilterMapping;
use utils\Filter;
use utils\Order;
use utils\PagingInfo;
use utils\PagingResponse;
/**
* Class DoctrineTrackTagGroupAllowedTagsRepository
* @package App\Repositories\Summit
*/
final class DoctrineTrackTagGroupAllowedTagsRepository
extends SilverStripeDoctrineRepository
implements ITrackTagGroupAllowedTagsRepository
{
protected function getFilterMappings()
{
return [
'tag' => new DoctrineFilterMapping
(
"(tg.tag :operator ':value')"
),
];
}
/**
* @return array
*/
protected function getOrderMappings()
{
return [
'tag' => 'tg.tag',
'id' => 't.id',
];
}
/**
* @return string
*/
protected function getBaseEntity()
{
return TrackTagGroupAllowedTag::class;
}
/**
* @param Summit $summit
* @param PagingInfo $paging_info
* @param Filter|null $filter
* @param Order|null $order
* @return PagingResponse
*/
public function getBySummit
(
Summit $summit,
PagingInfo $paging_info,
Filter $filter = null,
Order $order = null
)
{
$query = $this->getEntityManager()
->createQueryBuilder()
->select("t")
->from(TrackTagGroupAllowedTag::class, "t")
->innerJoin('t.tag', 'tg')
->innerJoin('t.track_tag_group', 'g')
->innerJoin('g.summit', 's')
->where("s.id = :summit_id");
$query->setParameter("summit_id", $summit->getId());
if(!is_null($filter)){
$filter->apply2Query($query, $this->getFilterMappings());
}
if (!is_null($order)) {
$order->apply2Query($query, $this->getOrderMappings());
} else {
//default order
$query = $query->addOrderBy("t.id",'ASC');
}
$query = $query
->setFirstResult($paging_info->getOffset())
->setMaxResults($paging_info->getPerPage());
$paginator = new Paginator($query, $fetchJoinCollection = true);
$total = $paginator->count();
$data = [];
foreach($paginator as $entity)
$data[] = $entity;
return new PagingResponse
(
$total,
$paging_info->getPerPage(),
$paging_info->getCurrentPage(),
$paging_info->getLastPage($total),
$data
);
}
}

View File

@ -1757,6 +1757,15 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::WriteSummitData, $current_realm)
],
],
// track tag groups
[
'name' => 'get-track-tag-groups-allowed-tags',
'route' => '/api/v1/summits/{id}/track-tag-groups/all/allowed-tags',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
],
]
]);
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Copyright 2018 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.
**/
/**
* Class OAuth2SummitTrackTagGroupsApiControllerTest
*/
final class OAuth2SummitTrackTagGroupsApiControllerTest extends ProtectedApiTest
{
public function testGetTags($summit_id = 25)
{
$params = [
'id' => $summit_id,
//AND FILTER
'filter' => ['tag=@101'],
'order' => '+id',
'expand' => 'tag,track_tag_group'
];
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
$response = $this->action(
"GET",
"OAuth2SummitTrackTagGroupsApiController@getAllowedTags",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$tags = json_decode($content);
$this->assertTrue(!is_null($tags));
$this->assertResponseStatus(200);
}
}