Adeed endpoint
GET api/v1/summits/{id}/tracks/{track_id}/allowed-tags SCOPES * summits/read * summits/read/all Change-Id: If94feb1be246a2f4197ed7b542f572f7ec647876
This commit is contained in:
parent
fcbea898eb
commit
ea5f602e21
|
@ -324,6 +324,44 @@ final class OAuth2SummitTracksApiController extends OAuth2ProtectedController
|
|||
}
|
||||
}
|
||||
|
||||
public function getTrackAllowedTagsBySummit($summit_id, $track_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$track = $summit->getPresentationCategory($track_id);
|
||||
if(is_null($track))
|
||||
return $this->error404();
|
||||
$allowed_tags = $track->getAllowedTags()->toArray();
|
||||
|
||||
$response = new PagingResponse(
|
||||
count($allowed_tags),
|
||||
count($allowed_tags),
|
||||
1,
|
||||
1,
|
||||
$allowed_tags
|
||||
);
|
||||
$res = $response->toArray();
|
||||
$i = 0;
|
||||
foreach($res["data"] as $allowed_tag){
|
||||
$track_tag_group = $summit->getTrackTagGroupForTagId($allowed_tag['id']);
|
||||
if(is_null($track_tag_group)) continue;
|
||||
$res["data"][$i]['track_tag_group']= SerializerRegistry::getInstance()->getSerializer($track_tag_group)->serialize(null, [], ['none']);
|
||||
$i++;
|
||||
}
|
||||
return $this->ok($res);
|
||||
|
||||
} catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
} catch (EntityNotFoundException $ex2) {
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message' => $ex2->getMessage()));
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
|
|
|
@ -467,6 +467,10 @@ Route::group([
|
|||
Route::get('', 'OAuth2SummitTracksApiController@getTrackBySummit');
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitTracksApiController@updateTrackBySummit']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitTracksApiController@deleteTrackBySummit']);
|
||||
Route::group(['prefix' => 'allowed-tags'], function () {
|
||||
Route::get('', 'OAuth2SummitTracksApiController@getTrackAllowedTagsBySummit');
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'extra-questions'], function () {
|
||||
Route::get('', 'OAuth2SummitTracksApiController@getTrackExtraQuestionsBySummit');
|
||||
});
|
||||
|
|
|
@ -43,6 +43,7 @@ use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackDropDownQuestio
|
|||
use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackMultiValueQuestionTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackQuestionValueTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackSingleValueTemplateQuestionSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\TrackTagGroupSerializer;
|
||||
use App\ModelSerializers\Summit\RSVP\Templates\RSVPDropDownQuestionTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\RSVP\Templates\RSVPLiteralContentQuestionTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\RSVP\Templates\RSVPMultiValueQuestionTemplateSerializer;
|
||||
|
@ -120,10 +121,11 @@ final class SerializerRegistry
|
|||
$this->registry['TrackDropDownQuestionTemplate'] = TrackDropDownQuestionTemplateSerializer::class;
|
||||
$this->registry['TrackCheckBoxListQuestionTemplate'] = TrackMultiValueQuestionTemplateSerializer::class;
|
||||
$this->registry['TrackRadioButtonListQuestionTemplate'] = TrackMultiValueQuestionTemplateSerializer::class;
|
||||
|
||||
// events
|
||||
$this->registry['SummitEvent'] = SummitEventSerializer::class;
|
||||
$this->registry['SummitGroupEvent'] = SummitGroupEventSerializer::class;
|
||||
$this->registry['SummitEventMetricsSnapshot'] = SummitEventMetricsSnapshotSerializer::class;
|
||||
$this->registry['TrackTagGroup'] = TrackTagGroupSerializer::class;
|
||||
$this->registry['Presentation'] = PresentationSerializer::class;
|
||||
$this->registry['PresentationVideo'] = PresentationVideoSerializer::class;
|
||||
$this->registry['PresentationSlide'] = PresentationSlideSerializer::class;
|
||||
|
|
|
@ -48,6 +48,7 @@ final class PresentationCategorySerializer extends SilverStripeSerializer
|
|||
$groups = [];
|
||||
$allowed_tag = [];
|
||||
$extra_questions = [];
|
||||
$summit = $category->getSummit();
|
||||
|
||||
foreach($category->getGroups() as $group){
|
||||
$groups[] = intval($group->getId());
|
||||
|
@ -81,12 +82,17 @@ final class PresentationCategorySerializer extends SilverStripeSerializer
|
|||
}
|
||||
switch (trim($relation)) {
|
||||
case 'allowed_tags': {
|
||||
$allowed_tag = [];
|
||||
$allowed_tags = [];
|
||||
unset($values['allowed_tags']);
|
||||
foreach ($category->getAllowedTags() as $tag) {
|
||||
$allowed_tag[] = SerializerRegistry::getInstance()->getSerializer($tag)->serialize(null, [], ['none']);
|
||||
$allowed_tag = SerializerRegistry::getInstance()->getSerializer($tag)->serialize(null, [], ['none']);
|
||||
$track_tag_group = $summit->getTrackTagGroupForTag($tag);
|
||||
if(!is_null($track_tag_group)){
|
||||
$allowed_tag['track_tag_group'] = SerializerRegistry::getInstance()->getSerializer($track_tag_group)->serialize(null, [], ['none']);
|
||||
}
|
||||
$allowed_tags[] = $allowed_tag;
|
||||
}
|
||||
$values['allowed_tags'] = $allowed_tag;
|
||||
$values['allowed_tags'] = $allowed_tags;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php namespace App\ModelSerializers\Summit\Presentation;
|
||||
/**
|
||||
* 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\Presentation
|
||||
*/
|
||||
final class TrackTagGroupSerializer extends SilverStripeSerializer
|
||||
{
|
||||
protected static $array_mappings = array
|
||||
(
|
||||
'Name' => 'name:json_text',
|
||||
'Label' => 'label:json_text',
|
||||
'Mandatory' => 'is_mandatory:json_boolean',
|
||||
'Order' => 'order:json_int',
|
||||
'SummitId' => 'summit_id:json_int',
|
||||
);
|
||||
}
|
|
@ -25,6 +25,7 @@ use models\exceptions\ValidationException;
|
|||
use models\main\Company;
|
||||
use models\main\File;
|
||||
use models\main\Member;
|
||||
use models\main\Tag;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
|
@ -2200,4 +2201,51 @@ SQL;
|
|||
const STAGE_OPEN = 0;
|
||||
const STAGE_FINISHED = 1;
|
||||
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @return TrackTagGroup|null
|
||||
*/
|
||||
public function getTrackTagGroupForTag(Tag $tag){
|
||||
$query = <<<SQL
|
||||
SELECT tg
|
||||
FROM App\Models\Foundation\Summit\TrackTagGroup tg
|
||||
JOIN tg.allowed_tags t
|
||||
WHERE
|
||||
tg.summit = :summit
|
||||
AND t.tag = :tag
|
||||
SQL;
|
||||
|
||||
$native_query = $this->getEM()->createQuery($query);
|
||||
|
||||
$native_query->setParameter("summit", $this);
|
||||
$native_query->setParameter("tag", $tag);
|
||||
|
||||
$res = $native_query->getResult();
|
||||
return count($res) > 0 ? $res[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tag_id
|
||||
* @return TrackTagGroup|null
|
||||
*/
|
||||
public function getTrackTagGroupForTagId($tag_id){
|
||||
$query = <<<SQL
|
||||
SELECT tg
|
||||
FROM App\Models\Foundation\Summit\TrackTagGroup tg
|
||||
JOIN tg.allowed_tags tgs
|
||||
JOIN tgs.tag t
|
||||
WHERE
|
||||
tg.summit = :summit
|
||||
AND t.id = :tag_id
|
||||
SQL;
|
||||
|
||||
$native_query = $this->getEM()->createQuery($query);
|
||||
|
||||
$native_query->setParameter("summit", $this);
|
||||
$native_query->setParameter("tag_id", $tag_id);
|
||||
|
||||
$res = $native_query->getResult();
|
||||
return count($res) > 0 ? $res[0] : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1144,6 +1144,15 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-track-allowed-tags',
|
||||
'route' => '/api/v1/summits/{id}/tracks/{track_id}/allowed-tags',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'copy-tracks-to-summit',
|
||||
'route' => '/api/v1/summits/{id}/tracks/copy/{to_summit_id}',
|
||||
|
|
|
@ -28,7 +28,7 @@ final class OAuth2TracksApiTest extends ProtectedApiTest
|
|||
'id' => $summit_id,
|
||||
'page' => 1,
|
||||
'per_page' => 10,
|
||||
'filter' => 'title=@con',
|
||||
'filter' => 'name=@con',
|
||||
'order' => '+code',
|
||||
'expand' => 'track_groups,allowed_tags'
|
||||
];
|
||||
|
@ -124,6 +124,40 @@ final class OAuth2TracksApiTest extends ProtectedApiTest
|
|||
return $extra_questions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param int $track_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testGetTracksAllowedTagsById($summit_id = 25, $track_id = 248){
|
||||
$params = [
|
||||
|
||||
'id' => $summit_id,
|
||||
'track_id' => $track_id,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitTracksApiController@getTrackAllowedTagsBySummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
$allowes_tags = json_decode($content);
|
||||
$this->assertTrue(!is_null($allowes_tags));
|
||||
return $allowes_tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue