Added endpoint delete track per summit
DELETE /api/v1/summits/{id}/tracks/{track_id} Change-Id: I465bc489996c6ca94eea1d844e32f8e4b88fe370
This commit is contained in:
parent
d856c7ecc2
commit
74d64b113b
|
@ -393,4 +393,33 @@ final class OAuth2SummitTracksApiController extends OAuth2ProtectedController
|
|||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $track_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteTrackBySummit($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();
|
||||
|
||||
$this->track_service->deleteTrack($summit, $track_id);
|
||||
|
||||
return $this->deleted();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -350,6 +350,7 @@ Route::group([
|
|||
Route::group(['prefix' => '{track_id}'], function () {
|
||||
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']);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -36,9 +36,7 @@ use App\ModelSerializers\Marketplace\SpokenLanguageSerializer;
|
|||
use App\ModelSerializers\Marketplace\SupportChannelTypeSerializer;
|
||||
use App\ModelSerializers\Software\OpenStackComponentSerializer;
|
||||
use App\ModelSerializers\Software\OpenStackReleaseSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\PresentationCategoryAllowedTagSerializer;
|
||||
use Libs\ModelSerializers\IModelSerializer;
|
||||
use models\summit\SummitRegistrationPromoCode;
|
||||
use ModelSerializers\ChatTeams\ChatTeamInvitationSerializer;
|
||||
use ModelSerializers\ChatTeams\ChatTeamMemberSerializer;
|
||||
use ModelSerializers\ChatTeams\ChatTeamPushNotificationMessageSerializer;
|
||||
|
@ -51,7 +49,6 @@ use ModelSerializers\Locations\SummitVenueFloorSerializer;
|
|||
use ModelSerializers\Locations\SummitVenueRoomSerializer;
|
||||
use ModelSerializers\Locations\SummitVenueSerializer;
|
||||
use App\ModelSerializers\Marketplace\ApplianceSerializer;
|
||||
use ModelSerializers\SummitScheduleEmptySpotSerializer;
|
||||
/**
|
||||
* Class SerializerRegistry
|
||||
* @package ModelSerializers
|
||||
|
@ -90,7 +87,6 @@ final class SerializerRegistry
|
|||
$this->registry['PresentationType'] = PresentationTypeSerializer::class;
|
||||
$this->registry['SummitTicketType'] = SummitTicketTypeSerializer::class;
|
||||
$this->registry['PresentationCategory'] = PresentationCategorySerializer::class;
|
||||
$this->registry['PresentationCategoryAllowedTag'] = PresentationCategoryAllowedTagSerializer::class;
|
||||
$this->registry['PresentationCategoryGroup'] = PresentationCategoryGroupSerializer::class;
|
||||
$this->registry['PrivatePresentationCategoryGroup'] = PrivatePresentationCategoryGroupSerializer::class;
|
||||
$this->registry['Tag'] = TagSerializer::class;
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?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 App\Models\Foundation\Summit\Events\Presentations\PresentationCategoryAllowedTag;
|
||||
use ModelSerializers\SilverStripeSerializer;
|
||||
/**
|
||||
* Class PresentationCategoryAllowedTagSerializer
|
||||
* @package App\ModelSerializers\Summit\Presentation
|
||||
*/
|
||||
final class PresentationCategoryAllowedTagSerializer extends SilverStripeSerializer
|
||||
{
|
||||
protected static $array_mappings = [
|
||||
'Default' => 'is_default:json_boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* @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 = [] )
|
||||
{
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$allowed_tag = $this->object;
|
||||
if(!$allowed_tag instanceof PresentationCategoryAllowedTag) return [];
|
||||
$values['tag'] = $allowed_tag->getTag()->getTag();
|
||||
$values['id'] = $allowed_tag->getTag()->getId();
|
||||
return $values;
|
||||
}
|
||||
}
|
|
@ -53,8 +53,8 @@ final class PresentationCategorySerializer extends SilverStripeSerializer
|
|||
}
|
||||
$values['track_groups'] = $groups;
|
||||
|
||||
foreach($category->getAllowedTags() as $allowed_tag){
|
||||
$allowed_tag[] = intval($allowed_tag->getTag()->getId());
|
||||
foreach($category->getAllowedTags() as $tag){
|
||||
$allowed_tag[] = $tag->getId();
|
||||
}
|
||||
|
||||
$values['track_groups'] = $groups;
|
||||
|
@ -78,8 +78,8 @@ final class PresentationCategorySerializer extends SilverStripeSerializer
|
|||
case 'allowed_tags': {
|
||||
$allowed_tag = [];
|
||||
unset($values['allowed_tags']);
|
||||
foreach ($category->getAllowedTags() as $allowed_tag) {
|
||||
$allowed_tag[] = SerializerRegistry::getInstance()->getSerializer($allowed_tag)->serialize(null, [], ['none']);
|
||||
foreach ($category->getAllowedTags() as $tag) {
|
||||
$allowed_tag[] = SerializerRegistry::getInstance()->getSerializer($tag)->serialize(null, [], ['none']);
|
||||
}
|
||||
$values['allowed_tags'] = $allowed_tag;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\Events\Presentations\PresentationCategoryAllowedTag;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
|
@ -143,12 +142,14 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||
private $groups;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Models\Foundation\Summit\Events\Presentations\PresentationCategoryAllowedTag", mappedBy="track", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var PresentationCategoryAllowedTag[]
|
||||
* @ORM\ManyToMany(targetEntity="models\main\Tag", cascade={"persist"})
|
||||
* @ORM\JoinTable(name="PresentationCategory_AllowedTags",
|
||||
* joinColumns={@ORM\JoinColumn(name="PresentationCategoryID", referencedColumnName="ID")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="TagID", referencedColumnName="ID")}
|
||||
* )
|
||||
*/
|
||||
protected $allowed_tags;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@ -179,7 +180,7 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||
}
|
||||
|
||||
/**
|
||||
* @return PresentationCategoryAllowedTag[]
|
||||
* @return Tag[]
|
||||
*/
|
||||
public function getAllowedTags(){
|
||||
return $this->allowed_tags;
|
||||
|
@ -296,24 +297,21 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||
*/
|
||||
public function getRelatedPublishedSummitEvents(){
|
||||
$query = <<<SQL
|
||||
SELECT SummitEvent.*
|
||||
FROM SummitEvent
|
||||
SELECT e
|
||||
FROM models\summit\SummitEvent e
|
||||
WHERE
|
||||
SummitEvent.Published = 1
|
||||
AND SummitEvent.SummitID = :summit_id
|
||||
AND SummitEvent.CategoryID = :track_id
|
||||
e.published = 1
|
||||
AND e.summit = :summit
|
||||
AND e.category = :track
|
||||
SQL;
|
||||
|
||||
$rsm = new ResultSetMappingBuilder($this->getEM());
|
||||
$rsm->addRootEntityFromClassMetadata(\models\summit\SummitEvent::class, 'e');
|
||||
$native_query = $this->getEM()->createQuery($query);
|
||||
|
||||
// build rsm here
|
||||
$native_query = $this->getEM()->createNativeQuery($query, $rsm);
|
||||
$native_query->setParameter("summit", $this->summit);
|
||||
$native_query->setParameter("track", $this);
|
||||
|
||||
$native_query->setParameter("summit_id", $this->summit->getId());
|
||||
$native_query->setParameter("track_id", $this->id);
|
||||
|
||||
return $native_query->getResult();
|
||||
$res = $native_query->getResult();
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
<?php namespace App\Models\Foundation\Summit\Events\Presentations;
|
||||
/**
|
||||
* 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 models\main\Tag;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use models\summit\PresentationCategory;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="PresentationCategory_AllowedTags")
|
||||
* Class PresentationCategoryAllowedTag
|
||||
* @package App\Models\Foundation\Summit\Events\Presentations
|
||||
*/
|
||||
class PresentationCategoryAllowedTag extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Tag")
|
||||
* @ORM\JoinColumn(name="TagID", referencedColumnName="ID")
|
||||
* @var Tag
|
||||
*/
|
||||
private $tag;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\PresentationCategory", inversedBy="allowed_tags")
|
||||
* @ORM\JoinColumn(name="PresentationCategoryID", referencedColumnName="ID")
|
||||
* @var PresentationCategory
|
||||
*/
|
||||
private $track;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="IsDefault", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
private $is_default;
|
||||
|
||||
/**
|
||||
* @return Tag
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*/
|
||||
public function setTag($tag)
|
||||
{
|
||||
$this->tag = $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PresentationCategory
|
||||
*/
|
||||
public function getTrack()
|
||||
{
|
||||
return $this->track;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationCategory $track
|
||||
*/
|
||||
public function setTrack($track)
|
||||
{
|
||||
$this->track = $track;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefault()
|
||||
{
|
||||
return $this->is_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_default
|
||||
*/
|
||||
public function setIsDefault($is_default)
|
||||
{
|
||||
$this->is_default = $is_default;
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ final class PresentationCategoryFactory
|
|||
if(isset($data['title']))
|
||||
$track->setTitle(trim($data['title']));
|
||||
|
||||
if(isset($data['code']))
|
||||
if(isset($data['code']) && !empty($data['code']))
|
||||
$track->setCode(trim($data['code']));
|
||||
|
||||
if(isset($data['description']))
|
||||
|
|
|
@ -47,6 +47,6 @@ interface ISummitTrackService
|
|||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteEventType(Summit $summit, $track_id);
|
||||
public function deleteTrack(Summit $summit, $track_id);
|
||||
|
||||
}
|
|
@ -60,9 +60,11 @@ final class SummitTrackService implements ISummitTrackService
|
|||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $data) {
|
||||
|
||||
$former_track = $summit->getPresentationCategoryByCode($data['code']);
|
||||
if (!is_null($former_track))
|
||||
throw new ValidationException(sprintf("track id %s already has code %s assigned on summit id %s", $former_track->getId(), $data['code'], $summit->getId()));
|
||||
if (!empty($data['code'])) {
|
||||
$former_track = $summit->getPresentationCategoryByCode(trim($data['code']));
|
||||
if (!is_null($former_track))
|
||||
throw new ValidationException(sprintf("track id %s already has code %s assigned on summit id %s", $former_track->getId(), $data['code'], $summit->getId()));
|
||||
}
|
||||
|
||||
$former_track = $summit->getPresentationCategoryByTitle($data['title']);
|
||||
if (!is_null($former_track))
|
||||
|
@ -95,7 +97,7 @@ final class SummitTrackService implements ISummitTrackService
|
|||
sprintf("track id %s does not belong to summit id %s", $track_id, $summit->getId())
|
||||
);
|
||||
|
||||
if (isset($data['code'])) {
|
||||
if (isset($data['code']) && !empty($data['code'])) {
|
||||
$former_track = $summit->getPresentationCategoryByCode($data['code']);
|
||||
if (!is_null($former_track) && $former_track->getId() != $track_id)
|
||||
throw new ValidationException(sprintf("track id %s already has code %s assigned on summit id %s", $former_track->getId(), $data['code'], $summit->getId()));
|
||||
|
@ -121,8 +123,28 @@ final class SummitTrackService implements ISummitTrackService
|
|||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteEventType(Summit $summit, $track_id)
|
||||
public function deleteTrack(Summit $summit, $track_id)
|
||||
{
|
||||
// TODO: Implement deleteEventType() method.
|
||||
return $this->tx_service->transaction(function () use ($summit, $track_id) {
|
||||
|
||||
$track = $summit->getPresentationCategory($track_id);
|
||||
|
||||
if (is_null($track))
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
sprintf("track id %s does not belong to summit id %s", $track_id, $summit->getId())
|
||||
);
|
||||
|
||||
$summit_events = $track->getRelatedPublishedSummitEvents();
|
||||
|
||||
if(count($summit_events) > 0){
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf("track id %s could not be deleted bc its assigned to published events on summit id %s", $track_id, $summit->getId())
|
||||
);
|
||||
}
|
||||
|
||||
$this->repository->delete($track);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -629,7 +629,7 @@ class ApiEndpointsSeeder extends Seeder
|
|||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-tracks',
|
||||
'name' => 'add-track',
|
||||
'route' => '/api/v1/summits/{id}/tracks',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
|
@ -638,7 +638,7 @@ class ApiEndpointsSeeder extends Seeder
|
|||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-tracks',
|
||||
'name' => 'update-track',
|
||||
'route' => '/api/v1/summits/{id}/tracks/{track_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
|
@ -646,6 +646,15 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-track',
|
||||
'route' => '/api/v1/summits/{id}/tracks/{track_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteTracksData, $current_realm),
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
// track groups
|
||||
array(
|
||||
'name' => 'get-track-groups',
|
||||
|
|
|
@ -29,7 +29,7 @@ final class OAuth2TracksApiTest extends ProtectedApiTest
|
|||
'per_page' => 10,
|
||||
'filter' => 'title=@con',
|
||||
'order' => '+code',
|
||||
'expand' => 'track_groups'
|
||||
'expand' => 'track_groups,allowed_tags'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
|
@ -134,7 +134,7 @@ final class OAuth2TracksApiTest extends ProtectedApiTest
|
|||
$data = [
|
||||
'title' => $name,
|
||||
'description' => 'test desc',
|
||||
'code' => 'SM',
|
||||
'code' => '',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
|
@ -203,4 +203,62 @@ final class OAuth2TracksApiTest extends ProtectedApiTest
|
|||
$this->assertTrue(!empty($track->code) && $track->code == 'SMX');
|
||||
return $track;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testDeleteNewTrack($summit_id = 23){
|
||||
|
||||
$new_track = $this->testAddTrack($summit_id);
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'track_id' => $new_track->id
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"DELETE",
|
||||
"OAuth2SummitTracksApiController@deleteTrackBySummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
|
||||
public function testDeleteOldTrack($summit_id = 23){
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'track_id' => 155
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"DELETE",
|
||||
"OAuth2SummitTracksApiController@deleteTrackBySummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(412);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue