Added endpoint to create selection plans by summit
POST /api/v1/summits/{id}/selection-plans Payload 'name' => 'required|string|max:255', 'is_enabled' => 'required|boolean', 'submission_begin_date' => 'nullable|date_format:U', 'submission_end_date' => 'nullable|required_with:submission_begin_date|date_format:U|after_or_equal:submission_begin_date', 'voting_begin_date' => 'nullable|date_format:U', 'voting_end_date' => 'nullable|required_with:voting_begin_date|date_format:U|after_or_equal:voting_begin_date', 'selection_begin_date' => 'nullable|date_format:U', 'selection_end_date' => 'nullable|required_with:selection_begin_date|date_format:U|after_or_equal:selection_begin_date', Change-Id: I73eb45cd5f15b79b294ef9b098f7fa749c2122ef
This commit is contained in:
parent
e06576303e
commit
cb6b3a22c7
@ -0,0 +1,49 @@
|
||||
<?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.
|
||||
**/
|
||||
/**
|
||||
* Class SummitSelectionPlanValidationRulesFactory
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
final class SummitSelectionPlanValidationRulesFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @param bool $update
|
||||
* @return array
|
||||
*/
|
||||
public static function build(array $data, $update = false){
|
||||
if($update){
|
||||
return [
|
||||
'name' => 'sometimes|string|max:255',
|
||||
'is_enabled' => 'sometimes|boolean',
|
||||
'submission_begin_date' => 'nullable|date_format:U',
|
||||
'submission_end_date' => 'nullable|required_with:submission_begin_date|date_format:U|after_or_equal:submission_begin_date',
|
||||
'voting_begin_date' => 'nullable|date_format:U',
|
||||
'voting_end_date' => 'nullable|required_with:voting_begin_date|date_format:U|after_or_equal:voting_begin_date',
|
||||
'selection_begin_date' => 'nullable|date_format:U',
|
||||
'selection_end_date' => 'nullable|required_with:selection_begin_date|date_format:U|after_or_equal:selection_begin_date',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'name' => 'required|string|max:255',
|
||||
'is_enabled' => 'required|boolean',
|
||||
'submission_begin_date' => 'nullable|date_format:U',
|
||||
'submission_end_date' => 'nullable|required_with:submission_begin_date|date_format:U|after_or_equal:submission_begin_date',
|
||||
'voting_begin_date' => 'nullable|date_format:U',
|
||||
'voting_end_date' => 'nullable|required_with:voting_begin_date|date_format:U|after_or_equal:voting_begin_date',
|
||||
'selection_begin_date' => 'nullable|date_format:U',
|
||||
'selection_end_date' => 'nullable|required_with:selection_begin_date|date_format:U|after_or_equal:selection_begin_date',
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
<?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\Services\Model\ISummitSelectionPlanService;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\oauth2\IResourceServerContext;
|
||||
use models\summit\ISummitRepository;
|
||||
use Exception;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
/**
|
||||
* Class OAuth2SummitSelectionPlansApiController
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedController
|
||||
{
|
||||
/**
|
||||
* @var ISummitRepository
|
||||
*/
|
||||
private $summit_repository;
|
||||
|
||||
/**
|
||||
* @var ISummitSelectionPlanService
|
||||
*/
|
||||
private $selection_plan_service;
|
||||
|
||||
/**
|
||||
* OAuth2SummitSelectionPlansApiController constructor.
|
||||
* @param ISummitRepository $summit_repository
|
||||
* @param ISummitSelectionPlanService $selection_plan_service
|
||||
* @param IResourceServerContext $resource_server_context
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ISummitRepository $summit_repository,
|
||||
ISummitSelectionPlanService $selection_plan_service,
|
||||
IResourceServerContext $resource_server_context
|
||||
)
|
||||
{
|
||||
parent::__construct($resource_server_context);
|
||||
|
||||
$this->summit_repository = $summit_repository;
|
||||
$this->selection_plan_service = $selection_plan_service;
|
||||
}
|
||||
|
||||
public function addSelectionPlan($summit_id){
|
||||
try {
|
||||
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$payload = Input::json()->all();
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$rules = SummitSelectionPlanValidationRulesFactory::build($payload);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$template = $this->selection_plan_service->addSelectionPlan($summit, $payload);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($template)->serialize());
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
}
|
32
app/Http/Utils/DateUtils.php
Normal file
32
app/Http/Utils/DateUtils.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php namespace App\Http\Utils;
|
||||
/**
|
||||
* 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 DateTime;
|
||||
/**
|
||||
* Class DateUtils
|
||||
* @package App\Http\Utils
|
||||
*/
|
||||
final class DateUtils
|
||||
{
|
||||
/**
|
||||
* @param DateTime $start1
|
||||
* @param DateTime $end1
|
||||
* @param DateTime $start2
|
||||
* @param DateTime $end2
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkTimeFramesOverlap(DateTime $start1, DateTime $end1, DateTime $start2, DateTime $end2){
|
||||
return $start1 <= $end2 && $end1 >= $start2;
|
||||
}
|
||||
}
|
@ -108,7 +108,13 @@ Route::group([
|
||||
Route::group(['prefix' => '{id}'], function () {
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitApiController@updateSummit']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitApiController@deleteSummit']);
|
||||
// rsvp templates
|
||||
|
||||
// selection plans
|
||||
Route::group(['prefix' => 'selection-plans'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSelectionPlansApiController@addSelectionPlan']);
|
||||
});
|
||||
|
||||
// RSVP templates
|
||||
Route::group(['prefix' => 'rsvp-templates'], function () {
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@getAllBySummit']);
|
||||
|
||||
|
@ -49,18 +49,18 @@ final class SelectionPlanSerializer extends SilverStripeSerializer
|
||||
foreach ($selection_plan->getCategoryGroups() as $group) {
|
||||
$category_groups[] = $group->getId();
|
||||
}
|
||||
$values['category_groups'] = $category_groups;
|
||||
$values['track_groups'] = $category_groups;
|
||||
|
||||
if (!empty($expand)) {
|
||||
$expand = explode(',', $expand);
|
||||
foreach ($expand as $relation) {
|
||||
switch (trim($relation)) {
|
||||
case 'category_groups':{
|
||||
case 'track_groups':{
|
||||
$category_groups = [];
|
||||
foreach ($selection_plan->getCategoryGroups() as $group) {
|
||||
$category_groups[] = SerializerRegistry::getInstance()->getSerializer($group)->serialize($expand);
|
||||
}
|
||||
$values['category_groups'] = $category_groups;
|
||||
$values['track_groups'] = $category_groups;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -0,0 +1,101 @@
|
||||
<?php namespace App\Models\Foundation\Summit\Factories;
|
||||
/**
|
||||
* 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\SelectionPlan;
|
||||
use models\summit\Summit;
|
||||
/**
|
||||
* Class SummitSelectionPlanFactory
|
||||
* @package App\Models\Foundation\Summit\Factories
|
||||
*/
|
||||
final class SummitSelectionPlanFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Summit $summit
|
||||
* @return SelectionPlan
|
||||
*/
|
||||
public static function build(array $data, Summit $summit){
|
||||
return self::populate(new SelectionPlan, $data, $summit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectionPlan $selection_plan
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @return SelectionPlan
|
||||
*/
|
||||
public static function populate(SelectionPlan $selection_plan, array $data, Summit $summit){
|
||||
|
||||
if(isset($data['name']))
|
||||
$selection_plan->setName(trim($data['name']));
|
||||
|
||||
if(isset($data['is_enabled']))
|
||||
$selection_plan->setIsEnabled(boolval($data['is_enabled']));
|
||||
|
||||
if(array_key_exists('submission_begin_date', $data) && array_key_exists('submission_end_date', $data)) {
|
||||
if (isset($data['submission_begin_date']) && isset($data['submission_end_date'])) {
|
||||
$start_datetime = intval($data['submission_begin_date']);
|
||||
$start_datetime = new \DateTime("@$start_datetime");
|
||||
$start_datetime->setTimezone($summit->getTimeZone());
|
||||
$end_datetime = intval($data['submission_end_date']);
|
||||
$end_datetime = new \DateTime("@$end_datetime");
|
||||
$end_datetime->setTimezone($summit->getTimeZone());
|
||||
|
||||
// set local time from UTC
|
||||
$selection_plan->setSubmissionBeginDate($start_datetime);
|
||||
$selection_plan->setSubmissionEndDate($end_datetime);
|
||||
}
|
||||
else{
|
||||
$selection_plan->clearSubmissionDates();
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists('voting_begin_date', $data) && array_key_exists('voting_end_date', $data)) {
|
||||
if (isset($data['voting_begin_date']) && isset($data['voting_end_date'])) {
|
||||
$start_datetime = intval($data['voting_begin_date']);
|
||||
$start_datetime = new \DateTime("@$start_datetime");
|
||||
$start_datetime->setTimezone($summit->getTimeZone());
|
||||
$end_datetime = intval($data['voting_end_date']);
|
||||
$end_datetime = new \DateTime("@$end_datetime");
|
||||
$end_datetime->setTimezone($summit->getTimeZone());
|
||||
|
||||
// set local time from UTC
|
||||
$selection_plan->setVotingBeginDate($start_datetime);
|
||||
$selection_plan->setVotingEndDate($end_datetime);
|
||||
}
|
||||
else{
|
||||
$selection_plan->clearVotingDates();
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists('selection_begin_date', $data) && array_key_exists('selection_end_date', $data)) {
|
||||
if (isset($data['selection_begin_date']) && isset($data['selection_end_date'])) {
|
||||
$start_datetime = intval($data['selection_begin_date']);
|
||||
$start_datetime = new \DateTime("@$start_datetime");
|
||||
$start_datetime->setTimezone($summit->getTimeZone());
|
||||
$end_datetime = intval($data['selection_end_date']);
|
||||
$end_datetime = new \DateTime("@$end_datetime");
|
||||
$end_datetime->setTimezone($summit->getTimeZone());
|
||||
|
||||
// set local time from UTC
|
||||
$selection_plan->setSelectionBeginDate($start_datetime);
|
||||
$selection_plan->setSelectionEndDate($end_datetime);
|
||||
}
|
||||
else{
|
||||
$selection_plan->clearSelectionDates();
|
||||
}
|
||||
}
|
||||
|
||||
return $selection_plan;
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
**/
|
||||
use App\Models\Utils\TimeZoneEntity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use models\summit\PresentationCategoryGroup;
|
||||
use models\summit\SummitOwned;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
@ -85,11 +86,11 @@ class SelectionPlan extends SilverstripeBaseModel
|
||||
*/
|
||||
private $selection_end_date;
|
||||
|
||||
/*
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="models\summit\PresentationCategoryGroup")
|
||||
* @ORM\JoinTable(name="SelectionPlan_CategoryGroups",
|
||||
* joinColumns={@JoinColumn(name="SelectionPlanID", referencedColumnName="ID")},
|
||||
* inverseJoinColumns={@JoinColumn(name="PresentationCategoryGroupID", referencedColumnName="ID")}
|
||||
* joinColumns={@ORM\JoinColumn(name="SelectionPlanID", referencedColumnName="ID")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="PresentationCategoryGroupID", referencedColumnName="ID")}
|
||||
* )
|
||||
* @var PresentationCategoryGroup[]
|
||||
*/
|
||||
@ -249,7 +250,7 @@ class SelectionPlan extends SilverstripeBaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection
|
||||
* @return PresentationCategoryGroup[]
|
||||
*/
|
||||
public function getCategoryGroups()
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Http\Utils\DateUtils;
|
||||
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
||||
use App\Models\Foundation\Summit\SelectionPlan;
|
||||
use App\Models\Foundation\Summit\TrackTagGroup;
|
||||
@ -1964,4 +1965,99 @@ SQL;
|
||||
return $this->selection_plans;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectionPlan $selection_plan
|
||||
* @throws ValidationException
|
||||
* @return bool
|
||||
*/
|
||||
public function checkSelectionPlanConflicts(SelectionPlan $selection_plan){
|
||||
foreach ($this->selection_plans as $sp){
|
||||
$start = $selection_plan->getSelectionBeginDate();
|
||||
$end = $selection_plan->getSelectionEndDate();
|
||||
|
||||
if(!is_null($start) && !is_null($end) && DateUtils::checkTimeFramesOverlap
|
||||
(
|
||||
$start,
|
||||
$end,
|
||||
$sp->getSelectionBeginDate(),
|
||||
$sp->getSelectionEndDate()
|
||||
))
|
||||
throw new ValidationException(trans(
|
||||
'validation_errors.Summit.checkSelectionPlanConflicts.conflictOnSelectionWorkflow',
|
||||
[
|
||||
'selection_plan_id' => $sp->getId(),
|
||||
'summit_id' => $this->getId()
|
||||
]
|
||||
));
|
||||
|
||||
$start = $selection_plan->getSubmissionBeginDate();
|
||||
$end = $selection_plan->getSubmissionEndDate();
|
||||
if(!is_null($start) && !is_null($end) && DateUtils::checkTimeFramesOverlap
|
||||
(
|
||||
$start,
|
||||
$end,
|
||||
$sp->getSubmissionBeginDate(),
|
||||
$sp->getSubmissionEndDate()
|
||||
))
|
||||
throw new ValidationException(trans(
|
||||
'validation_errors.Summit.checkSelectionPlanConflicts.conflictOnSubmissionWorkflow',
|
||||
[
|
||||
'selection_plan_id' => $sp->getId(),
|
||||
'summit_id' => $this->getId()
|
||||
]
|
||||
));
|
||||
|
||||
$start = $selection_plan->getVotingBeginDate();
|
||||
$end = $selection_plan->getVotingEndDate();
|
||||
|
||||
if(!is_null($start) && !is_null($end) && DateUtils::checkTimeFramesOverlap
|
||||
(
|
||||
$start,
|
||||
$end,
|
||||
$sp->getVotingBeginDate(),
|
||||
$sp->getVotingEndDate()
|
||||
))
|
||||
throw new ValidationException(trans(
|
||||
'validation_errors.Summit.checkSelectionPlanConflicts.conflictOnVotingWorkflow',
|
||||
[
|
||||
'selection_plan_id' => $sp->getId(),
|
||||
'summit_id' => $this->getId()
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return null|SelectionPlan
|
||||
*/
|
||||
public function getSelectionPlanByName($name){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('name', intval($name)));
|
||||
$selection_plan = $this->selection_plans->matching($criteria)->first();
|
||||
return $selection_plan === false ? null : $selection_plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectionPlan $selection_plan
|
||||
* @return $this
|
||||
*/
|
||||
public function addSelectionPlan(SelectionPlan $selection_plan){
|
||||
$this->selection_plans->add($selection_plan);
|
||||
$selection_plan->setSummit($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectionPlan $selection_plan
|
||||
* @return $this
|
||||
*/
|
||||
public function removeSelectionSelectionPlan(SelectionPlan $selection_plan){
|
||||
$this->selection_plans->removeElement($selection_plan);
|
||||
$selection_plan->clearSummit();
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
30
app/Services/Model/ISummitSelectionPlanService.php
Normal file
30
app/Services/Model/ISummitSelectionPlanService.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php namespace App\Services\Model;
|
||||
/**
|
||||
* 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\SelectionPlan;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\summit\Summit;
|
||||
/**
|
||||
* Interface ISummitSelectionPlanService
|
||||
* @package App\Services\Model
|
||||
*/
|
||||
interface ISummitSelectionPlanService
|
||||
{
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $payload
|
||||
* @return SelectionPlan
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addSelectionPlan(Summit $summit, array $payload);
|
||||
}
|
@ -67,6 +67,7 @@ final class SummitEventTypeService
|
||||
* @return SummitEventType
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addEventType(Summit $summit, array $data)
|
||||
{
|
||||
@ -107,6 +108,7 @@ final class SummitEventTypeService
|
||||
* @return SummitEventType
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateEventType(Summit $summit, $event_type_id, array $data)
|
||||
{
|
||||
@ -149,6 +151,7 @@ final class SummitEventTypeService
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteEventType(Summit $summit, $event_type_id)
|
||||
{
|
||||
@ -197,6 +200,7 @@ final class SummitEventTypeService
|
||||
* @return SummitEventType[]
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function seedDefaultEventTypes(Summit $summit)
|
||||
{
|
||||
|
58
app/Services/Model/SummitSelectionPlanService.php
Normal file
58
app/Services/Model/SummitSelectionPlanService.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php namespace App\Services\Model;
|
||||
/**
|
||||
* 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\Factories\SummitSelectionPlanFactory;
|
||||
use App\Models\Foundation\Summit\SelectionPlan;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\summit\Summit;
|
||||
/**
|
||||
* Class SummitSelectionPlanService
|
||||
* @package App\Services\Model
|
||||
*/
|
||||
final class SummitSelectionPlanService
|
||||
extends AbstractService
|
||||
implements ISummitSelectionPlanService
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $payload
|
||||
* @return SelectionPlan
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addSelectionPlan(Summit $summit, array $payload)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $payload){
|
||||
|
||||
$selection_plan = SummitSelectionPlanFactory::build($payload, $summit);
|
||||
|
||||
$former_selection_plan = $summit->getSelectionPlanByName($selection_plan->getName());
|
||||
|
||||
if(!is_null($former_selection_plan)){
|
||||
throw new ValidationException(trans(
|
||||
'validation_errors.SummitSelectionPlanService.addSelectionPlan.alreadyExistName',
|
||||
[
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
// validate selection plan
|
||||
$summit->checkSelectionPlanConflicts($selection_plan);
|
||||
|
||||
$summit->addSelectionPlan($selection_plan);
|
||||
|
||||
return $selection_plan;
|
||||
});
|
||||
}
|
||||
}
|
@ -797,6 +797,13 @@ final class SummitService extends AbstractService implements ISummitService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitEvent $event
|
||||
* @param SummitEventType $event_type
|
||||
* @param array $data
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function saveOrUpdatePresentationData(SummitEvent $event, SummitEventType $event_type, array $data ){
|
||||
if(!$event instanceof Presentation) return;
|
||||
|
||||
@ -859,6 +866,7 @@ final class SummitService extends AbstractService implements ISummitService
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $event_id
|
||||
|
@ -24,6 +24,7 @@ use App\Services\Model\IPresentationCategoryGroupService;
|
||||
use App\Services\Model\IRSVPTemplateService;
|
||||
use App\Services\Model\ISummitEventTypeService;
|
||||
use App\Services\Model\ISummitPushNotificationService;
|
||||
use App\Services\Model\ISummitSelectionPlanService;
|
||||
use App\Services\Model\ISummitTicketTypeService;
|
||||
use App\Services\Model\ISummitTrackService;
|
||||
use App\Services\Model\PresentationCategoryGroupService;
|
||||
@ -32,6 +33,7 @@ use App\Services\Model\MemberService;
|
||||
use App\Services\Model\RSVPTemplateService;
|
||||
use App\Services\Model\SummitPromoCodeService;
|
||||
use App\Services\Model\SummitPushNotificationService;
|
||||
use App\Services\Model\SummitSelectionPlanService;
|
||||
use App\Services\Model\SummitTicketTypeService;
|
||||
use App\Services\Model\SummitTrackService;
|
||||
use App\Services\SummitEventTypeService;
|
||||
@ -224,5 +226,11 @@ final class ServicesProvider extends ServiceProvider
|
||||
Config::get("server.google_geocoding_api_key", null)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
App::singleton(
|
||||
ISummitSelectionPlanService::class,
|
||||
SummitSelectionPlanService::class
|
||||
);
|
||||
}
|
||||
}
|
@ -1603,6 +1603,40 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
// selection plans
|
||||
[
|
||||
'name' => 'get-selection-plan-by-id',
|
||||
'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-selection-plan',
|
||||
'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-selection-plan',
|
||||
'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-selection-plan',
|
||||
'route' => '/api/v1/summits/{id}/selection-plans',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -73,4 +73,8 @@ return [
|
||||
// SummitPushNotificationService
|
||||
'SummitPushNotificationService.addPushNotification.MemberNotActive' => 'member :member_id is not active',
|
||||
'SummitPushNotificationService.deleteNotification.NotificationAlreadySent' => 'notification :notification_id is already sent.',
|
||||
'Summit.checkSelectionPlanConflicts.conflictOnSelectionWorkflow' => 'there is a conflict on selection dates with selection plan :selection_plan_id on summit :summit_id',
|
||||
'Summit.checkSelectionPlanConflicts.conflictOnSubmissionWorkflow' => 'there is a conflict on submission dates with selection plan :selection_plan_id on summit :summit_id',
|
||||
'Summit.checkSelectionPlanConflicts.conflictOnVotingWorkflow' => 'there is a conflict on voting dates with selection plan :selection_plan_id on summit :summit_id',
|
||||
'SummitSelectionPlanService.addSelectionPlan.alreadyExistName' => 'there is already another selection plan with same name on summit :summit_id',
|
||||
];
|
55
tests/OAuth2SelectionPlansApiTest.php
Normal file
55
tests/OAuth2SelectionPlansApiTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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.
|
||||
**/
|
||||
|
||||
final class OAuth2SelectionPlansApiTest extends ProtectedApiTest
|
||||
{
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testAddSelectionPlan($summit_id = 24){
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
];
|
||||
|
||||
$name = str_random(16).'_selection_plan';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'is_enabled' => true
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitSelectionPlansApiController@addSelectionPlan",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$selection_plan = json_decode($content);
|
||||
$this->assertTrue(!is_null($selection_plan));
|
||||
$this->assertEquals($name, $selection_plan->name);
|
||||
return $selection_plan;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user