added endpoint update summit

PUT /api/v1/summits/{id}

Payload

* name (sometimes|string|max:50)
* start_date (sometimes|date_format:U)
* end_date (required_with:start_date|date_format:U|after:start_date)
* submission_begin_date (sometimes|date_format:U)
* submission_end_date (required_with:submission_begin_date|date_format:U|after:submission_begin_date)
* voting_begin_date (sometimes|date_format:U)
* voting_end_date (required_with:voting_begin_date|date_format:U|after:voting_begin_date)
* selection_begin_date (sometimes|date_format:U)
* selection_end_date (required_with:selection_begin_date|date_format:U|after:selection_begin_date)
* registration_begin_date (sometimes|date_format:U)
* registration_end_date (required_with:registration_begin_date|date_format:U|after:registration_begin_date)
* start_showing_venues_date (sometimes|date_format:U|before:start_date)
* schedule_start_date (sometimes|date_format:U)
* active (sometimes|boolean)
* dates_label (sometimes|string)
* time_zone_id (sometimes|timezone) check http://php.net/manual/en/timezones.php
* external_summit_id (sometimes|string)
* available_on_api (sometimes|boolean)
* calendar_sync_name (sometimes|string|max:255)
* calendar_sync_desc  (sometimes|string)
* link (sometimes|url)
* registration_link (sometimes|url)
* max_submission_allowed_per_user (sometimes|integer|min:1)

Required scopes

'%s/summits/write'

Change-Id: Ib50c64994f9de5e8cfba0aaf2a990708a3c6afb9
This commit is contained in:
Sebastian Marcet 2018-04-04 18:08:33 -03:00
parent d000e398aa
commit 18bf5bfa04
11 changed files with 314 additions and 1 deletions

View File

@ -0,0 +1,45 @@
<?php namespace App\Events;
/**
* 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 Illuminate\Queue\SerializesModels;
/**
* Class SummitAction
* @package App\Events
*/
class SummitAction
{
use SerializesModels;
/**
* @var int
*/
protected $summit_id;
/**
* SummitAction constructor.
* @param int $summit_id
*/
public function __construct($summit_id)
{
$this->summit_id = $summit_id;
}
/**
* @return int
*/
public function getSummitId()
{
return $this->summit_id;
}
}

View File

@ -0,0 +1,22 @@
<?php namespace App\Events;
/**
* 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 SummitDeleted
* @package App\Events
*/
final class SummitDeleted extends SummitAction
{
}

View File

@ -0,0 +1,22 @@
<?php namespace App\Events;
/**
* 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 SummitUpdated
* @package App\Events
*/
final class SummitUpdated extends SummitAction
{
}

View File

@ -0,0 +1,58 @@
<?php namespace App\Factories\EntityEvents;
/**
* 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\Events\SummitAction;
use Illuminate\Support\Facades\App;
use models\main\IMemberRepository;
use models\oauth2\IResourceServerContext;
use models\summit\ISummitRepository;
use models\summit\SummitEntityEvent;
/**
* Class SummitActionEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class SummitActionEntityEventFactory
{
/**
* @param SummitAction $event
* @param string $type
* @return SummitEntityEvent
*/
public static function build(SummitAction $event, $type = 'UPDATE')
{
$resource_server_context = App::make(IResourceServerContext::class);
$member_repository = App::make(IMemberRepository::class);
$summit_repository = App::make(ISummitRepository::class);
$summit = $summit_repository->getById($event->getSummitId());
$owner_id = $resource_server_context->getCurrentUserExternalId();
if (is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('Summit');
$entity_event->setEntityId($event->getSummitId());
$entity_event->setType($type);
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
if(!is_null($summit))
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
return $entity_event;
}
}

View File

@ -23,6 +23,11 @@ interface ISummitRepository extends IBaseRepository
*/
public function getCurrent();
/**
* @return Summit
*/
public function getActive();
/**
* @return Summit[]
*/

View File

@ -32,6 +32,7 @@ use App\Factories\EntityEvents\PresentationMaterialUpdatedEntityEventFactory;
use App\Factories\EntityEvents\PresentationSpeakerCreatedEntityEventFactory;
use App\Factories\EntityEvents\PresentationSpeakerDeletedEntityEventFactory;
use App\Factories\EntityEvents\PresentationSpeakerUpdatedEntityEventFactory;
use App\Factories\EntityEvents\SummitActionEntityEventFactory;
use App\Factories\EntityEvents\SummitEventCreatedEntityEventFactory;
use App\Factories\EntityEvents\SummitEventDeletedEntityEventFactory;
use App\Factories\EntityEvents\SummitEventTypeActionEntityEventFactory;
@ -304,5 +305,17 @@ final class EventServiceProvider extends ServiceProvider
{
EntityEventPersister::persist(TrackGroupActionActionEntityEventFactory::build($event, 'DELETE'));
});
// summits
Event::listen(\App\Events\SummitUpdated::class, function($event)
{
EntityEventPersister::persist(SummitActionEntityEventFactory::build($event, 'UPDATE'));
});
Event::listen(\App\Events\SummitDeleted::class, function($event)
{
EntityEventPersister::persist(SummitActionEntityEventFactory::build($event, 'DELETE'));
});
}
}

View File

@ -89,4 +89,20 @@ final class DoctrineSummitRepository
->getQuery()
->getOneOrNullResult();
}
/**
* @return Summit
*/
public function getActive()
{
$res = $this->getEntityManager()->createQueryBuilder()
->select("s")
->from(\models\summit\Summit::class, "s")
->where('s.active = 1')
->orderBy('s.begin_date', 'DESC')
->getQuery()
->getResult();
if (count($res) == 0) return null;
return $res[0];
}
}

View File

@ -15,6 +15,8 @@ use App\Events\MyFavoritesAdd;
use App\Events\MyFavoritesRemove;
use App\Events\MyScheduleAdd;
use App\Events\MyScheduleRemove;
use App\Events\SummitDeleted;
use App\Events\SummitUpdated;
use App\Http\Utils\FileUploader;
use App\Models\Foundation\Summit\Factories\SummitFactory;
use App\Models\Utils\IntervalParser;
@ -1525,6 +1527,54 @@ final class SummitService extends AbstractService implements ISummitService
{
return $this->tx_service->transaction(function () use ($summit_id, $data) {
if(isset($data['name'])) {
$former_summit = $this->summit_repository->getByName(trim($data['name']));
if (!is_null($former_summit) && $former_summit->getId() != $summit_id) {
throw new ValidationException
(
trans
(
'validation_errors.SummitService.updateSummit.NameAlreadyExists',
['name' => $data['name']]
)
);
}
}
if(isset($data['active'])) {
$active = boolval($data['active']);
$active_summit = $this->summit_repository->getActive();
if ($active && !is_null($active_summit) && $active_summit->getId() != $summit_id) {
throw new ValidationException
(
trans
(
'validation_errors.SummitService.updateSummit.SummitAlreadyActive',
['active_summit_id' => $active_summit->getId()]
)
);
}
}
$summit = $this->summit_repository->getById($summit_id);
if(is_null($summit)){
throw new EntityNotFoundException
(
trans
(
'not_found_errors.SummitService.updateSummit.SummitNotFound',
['summit_id' => $summit_id]
)
);
}
$summit = SummitFactory::populate($summit, $data);
Event::fire(new SummitUpdated($summit_id));
return $summit;
});
}
@ -1538,6 +1588,23 @@ final class SummitService extends AbstractService implements ISummitService
{
return $this->tx_service->transaction(function () use ($summit_id) {
$summit = $this->summit_repository->getById($summit_id);
if(is_null($summit)){
throw new EntityNotFoundException
(
trans
(
'not_found_errors.SummitService.deleteSummit.SummitNotFound',
['summit_id' => $summit_id]
)
);
}
$this->summit_repository->delete($summit);
Event::fire(new SummitDeleted($summit_id));
});
}
}

View File

@ -68,4 +68,6 @@ return [
'PresentationCategoryGroupService.associateAllowedGroup2TrackGroup.GroupNotFound' => 'group :group_id does not exists.',
'PresentationCategoryGroupService.disassociateAllowedGroup2TrackGroup.TrackGroupNotFound' => 'track group :track_group_id does not exists on summit :summit_id',
'PresentationCategoryGroupService.disassociateAllowedGroup2TrackGroup.GroupNotFound' => 'group :group_id does not exists.',
'SummitService.updateSummit.SummitNotFound' => 'summit :summit_id not found',
'SummitService.deleteSummit.SummitNotFound' => 'summit :summit_id not found',
];

View File

@ -67,5 +67,6 @@ return [
'PresentationCategoryGroupService.addTrackGroup.NameAlreadyExists' => 'name :name already exists for summit :summit_id',
// SummitService
'SummitService.AddSummit.NameAlreadyExists' => 'name :name its already being assigned to another summit',
'SummitService.updateSummit.NameAlreadyExists'=> 'name :name its already being assigned to another summit',
'SummitService.updateSummit.SummitAlreadyActive' => 'summit :active_summit_id is already activated please deactivate it to set current summit as active'
];

View File

@ -184,6 +184,68 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
return $summit;
}
public function testUpdateSummitAlreadyActiveError(){
$summit = $this->testAddSummit();
$params = [
'id' => $summit->id
];
$data = [
'active' => 1
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"PUT",
"OAuth2SummitApiController@updateSummit",
$params,
[],
[],
[],
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(412);
}
public function testUpdateSummitTitle(){
$summit = $this->testAddSummit();
$params = [
'id' => $summit->id
];
$data = [
'name' => $summit->name.' update!'
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"PUT",
"OAuth2SummitApiController@updateSummit",
$params,
[],
[],
[],
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$summit = json_decode($content);
$this->assertTrue(!is_null($summit));
return $summit;
}
public function testGetSummitMin($summit_id = 23)
{