Updated endpoints POST/PUT track by summit
POST /api/v1/summits/{id}/tracks PUT /api/v1/summits/{id}/tracks/{track_id} added allowed_tags param collection of tags ( restricted by tag track groups) Change-Id: I5733c60a887f08d34c0ce775087ec9bfb677b072
This commit is contained in:
parent
1539d2cd51
commit
92bd96de5b
@ -384,6 +384,7 @@ final class OAuth2SummitTracksApiController extends OAuth2ProtectedController
|
|||||||
'lightning_alternate_count' => 'sometimes|integer',
|
'lightning_alternate_count' => 'sometimes|integer',
|
||||||
'voting_visible' => 'sometimes|boolean',
|
'voting_visible' => 'sometimes|boolean',
|
||||||
'chair_visible' => 'sometimes|boolean',
|
'chair_visible' => 'sometimes|boolean',
|
||||||
|
'allowed_tags' => 'sometimes|string_array',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Creates a Validator instance and validates the data.
|
// Creates a Validator instance and validates the data.
|
||||||
@ -482,6 +483,7 @@ final class OAuth2SummitTracksApiController extends OAuth2ProtectedController
|
|||||||
'lightning_alternate_count' => 'sometimes|integer',
|
'lightning_alternate_count' => 'sometimes|integer',
|
||||||
'voting_visible' => 'sometimes|boolean',
|
'voting_visible' => 'sometimes|boolean',
|
||||||
'chair_visible' => 'sometimes|boolean',
|
'chair_visible' => 'sometimes|boolean',
|
||||||
|
'allowed_tags' => 'sometimes|string_array',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Creates a Validator instance and validates the data.
|
// Creates a Validator instance and validates the data.
|
||||||
|
@ -248,6 +248,18 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||||||
return $this->allowed_tags;
|
return $this->allowed_tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function clearAllowedTags(){
|
||||||
|
$this->allowed_tags->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Tag $tag
|
||||||
|
*/
|
||||||
|
public function addAllowedTag(Tag $tag){
|
||||||
|
if($this->allowed_tags->contains($tag)) return;
|
||||||
|
$this->allowed_tags->add($tag);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $group_id
|
* @param int $group_id
|
||||||
* @return PresentationCategoryGroup|null
|
* @return PresentationCategoryGroup|null
|
||||||
|
@ -665,6 +665,7 @@ class SummitEvent extends SilverstripeBaseModel
|
|||||||
*/
|
*/
|
||||||
public function addTag(Tag $tag)
|
public function addTag(Tag $tag)
|
||||||
{
|
{
|
||||||
|
if($this->tags->contains($tag)) return;
|
||||||
$this->tags->add($tag);
|
$this->tags->add($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use App\Http\Utils\DateUtils;
|
|||||||
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
||||||
use App\Models\Foundation\Summit\SelectionPlan;
|
use App\Models\Foundation\Summit\SelectionPlan;
|
||||||
use App\Models\Foundation\Summit\TrackTagGroup;
|
use App\Models\Foundation\Summit\TrackTagGroup;
|
||||||
|
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
|
||||||
use App\Models\Utils\TimeZoneEntity;
|
use App\Models\Utils\TimeZoneEntity;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -2225,6 +2226,56 @@ SQL;
|
|||||||
return count($res) > 0 ? $res[0] : null;
|
return count($res) > 0 ? $res[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $tag_value
|
||||||
|
* @return bool
|
||||||
|
* @throws \Doctrine\ORM\NoResultException
|
||||||
|
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||||
|
*/
|
||||||
|
public function isTagValueAllowedOnTrackTagGroups($tag_value){
|
||||||
|
$query = <<<SQL
|
||||||
|
SELECT COUNT(tg.id)
|
||||||
|
FROM App\Models\Foundation\Summit\TrackTagGroup tg
|
||||||
|
JOIN tg.allowed_tags t
|
||||||
|
JOIN t.tag tag
|
||||||
|
WHERE
|
||||||
|
tg.summit = :summit
|
||||||
|
AND tag.tag = :tag_value
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$native_query = $this->getEM()->createQuery($query);
|
||||||
|
|
||||||
|
$native_query->setParameter("summit", $this);
|
||||||
|
$native_query->setParameter("tag_value", $tag_value);
|
||||||
|
|
||||||
|
$res = $native_query->getSingleScalarResult();
|
||||||
|
return $res > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $tag_value
|
||||||
|
* @return null|TrackTagGroupAllowedTag
|
||||||
|
*/
|
||||||
|
public function getAllowedTagOnTagTrackGroup($tag_value){
|
||||||
|
$query = <<<SQL
|
||||||
|
SELECT allowed_tag
|
||||||
|
FROM App\Models\Foundation\Summit\TrackTagGroupAllowedTag allowed_tag
|
||||||
|
JOIN allowed_tag.track_tag_group tg
|
||||||
|
JOIN allowed_tag.tag tag
|
||||||
|
WHERE
|
||||||
|
tg.summit = :summit
|
||||||
|
AND tag.tag = :tag_value
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$native_query = $this->getEM()->createQuery($query);
|
||||||
|
|
||||||
|
$native_query->setParameter("summit", $this);
|
||||||
|
$native_query->setParameter("tag_value", $tag_value);
|
||||||
|
|
||||||
|
$res = $native_query->getResult();
|
||||||
|
return count($res) > 0 ? $res[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $tag_id
|
* @param int $tag_id
|
||||||
* @return TrackTagGroup|null
|
* @return TrackTagGroup|null
|
||||||
|
@ -21,6 +21,7 @@ use Illuminate\Support\Facades\Event;
|
|||||||
use libs\utils\ITransactionService;
|
use libs\utils\ITransactionService;
|
||||||
use models\exceptions\EntityNotFoundException;
|
use models\exceptions\EntityNotFoundException;
|
||||||
use models\exceptions\ValidationException;
|
use models\exceptions\ValidationException;
|
||||||
|
use models\main\ITagRepository;
|
||||||
use models\summit\PresentationCategory;
|
use models\summit\PresentationCategory;
|
||||||
use models\summit\Summit;
|
use models\summit\Summit;
|
||||||
/**
|
/**
|
||||||
@ -36,14 +37,26 @@ final class SummitTrackService
|
|||||||
*/
|
*/
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ITagRepository
|
||||||
|
*/
|
||||||
|
private $tag_repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SummitTrackService constructor.
|
* SummitTrackService constructor.
|
||||||
* @param ISummitTrackRepository $repository
|
* @param ISummitTrackRepository $repository
|
||||||
|
* @param ITagRepository $tag_repository
|
||||||
* @param ITransactionService $tx_service
|
* @param ITransactionService $tx_service
|
||||||
*/
|
*/
|
||||||
public function __construct(ISummitTrackRepository $repository, ITransactionService $tx_service)
|
public function __construct
|
||||||
|
(
|
||||||
|
ISummitTrackRepository $repository,
|
||||||
|
ITagRepository $tag_repository,
|
||||||
|
ITransactionService $tx_service
|
||||||
|
)
|
||||||
{
|
{
|
||||||
parent::__construct($tx_service);
|
parent::__construct($tx_service);
|
||||||
|
$this->tag_repository = $tag_repository;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +83,18 @@ final class SummitTrackService
|
|||||||
|
|
||||||
$track = PresentationCategoryFactory::build($summit, $data);
|
$track = PresentationCategoryFactory::build($summit, $data);
|
||||||
|
|
||||||
|
if(isset($data['allowed_tags'])){
|
||||||
|
foreach($data['allowed_tags'] as $tag_value) {
|
||||||
|
$tackTagGroupAllowedTag = $summit->getAllowedTagOnTagTrackGroup($tag_value);
|
||||||
|
if(is_null($tackTagGroupAllowedTag)){
|
||||||
|
throw new ValidationException(
|
||||||
|
sprintf("allowed_tags : tag value %s is not allowed on current track tag groups for summit %s", $tag_value, $summit->getId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$track->addAllowedTag($tackTagGroupAllowedTag->getTag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$summit->addPresentationCategory($track);
|
$summit->addPresentationCategory($track);
|
||||||
|
|
||||||
return $track;
|
return $track;
|
||||||
@ -114,6 +139,19 @@ final class SummitTrackService
|
|||||||
|
|
||||||
$track = PresentationCategoryFactory::populate($track, $data);
|
$track = PresentationCategoryFactory::populate($track, $data);
|
||||||
|
|
||||||
|
if(isset($data['allowed_tags'])){
|
||||||
|
$track->clearAllowedTags();
|
||||||
|
foreach($data['allowed_tags'] as $tag_value) {
|
||||||
|
$tackTagGroupAllowedTag = $summit->getAllowedTagOnTagTrackGroup($tag_value);
|
||||||
|
if(is_null($tackTagGroupAllowedTag)){
|
||||||
|
throw new ValidationException(
|
||||||
|
sprintf("allowed_tags : tag value %s is not allowed on current track tag groups for summit %s", $tag_value, $summit->getId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$track->addAllowedTag($tackTagGroupAllowedTag->getTag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Event::fire(new TrackUpdated($track->getSummitId(), $track->getId()));
|
Event::fire(new TrackUpdated($track->getSummitId(), $track->getId()));
|
||||||
|
|
||||||
return $track;
|
return $track;
|
||||||
|
@ -195,16 +195,17 @@ final class OAuth2TracksApiTest extends ProtectedApiTest
|
|||||||
* @param int $summit_id
|
* @param int $summit_id
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function testAddTrack($summit_id = 23){
|
public function testAddTrack($summit_id = 25){
|
||||||
$params = [
|
$params = [
|
||||||
'id' => $summit_id,
|
'id' => $summit_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
$name = str_random(16).'_track';
|
$name = str_random(16).'_track';
|
||||||
$data = [
|
$data = [
|
||||||
'title' => $name,
|
'name' => $name,
|
||||||
'description' => 'test desc',
|
'description' => 'test desc',
|
||||||
'code' => '',
|
'code' => '',
|
||||||
|
'allowed_tags' => ['101','Case Study', 'Demo'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user