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:
parent
d000e398aa
commit
18bf5bfa04
45
app/Events/SummitAction.php
Normal file
45
app/Events/SummitAction.php
Normal 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;
|
||||
}
|
||||
}
|
22
app/Events/SummitDeleted.php
Normal file
22
app/Events/SummitDeleted.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
22
app/Events/SummitUpdated.php
Normal file
22
app/Events/SummitUpdated.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -23,6 +23,11 @@ interface ISummitRepository extends IBaseRepository
|
||||
*/
|
||||
public function getCurrent();
|
||||
|
||||
/**
|
||||
* @return Summit
|
||||
*/
|
||||
public function getActive();
|
||||
|
||||
/**
|
||||
* @return Summit[]
|
||||
*/
|
||||
|
@ -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'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
@ -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));
|
||||
|
||||
});
|
||||
}
|
||||
}
|
@ -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',
|
||||
];
|
@ -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'
|
||||
];
|
@ -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)
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user