Added endpoints to add/remove speakers

from my presentations

DELETE /api/v1/speakers/me/presentations/{presentation_id}/speakers/{speaker_id}
PUT /api/v1/speakers/me/presentations/{presentation_id}/speakers/{speaker_id}

Required Scopes
* /summits/write
* /speakers/write
* /speakers/write/me

Change-Id: I1a262445b3b4342a983b169add63f3c9731e960b
This commit is contained in:
Sebastian Marcet
2018-08-13 18:39:15 -03:00
parent abfb97dbd0
commit ff8a664d95
6 changed files with 214 additions and 1 deletions

View File

@@ -222,4 +222,24 @@ interface ISummitService
* @return void
*/
public function deleteSummit($summit_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
}

View File

@@ -1653,4 +1653,85 @@ final class SummitService extends AbstractService implements ISummitService
});
}
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
$current_speaker = $this->speaker_repository->getByMember($current_member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $current_member_id));
$presentation = $this->event_repository->getById($presentation_id);
if(is_null($presentation))
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation instanceof Presentation)
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(sprintf("member %s can not edit presentation %s",
$current_member_id,
$presentation_id
));
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
$presentation->addSpeaker($speaker);
});
}
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
$current_speaker = $this->speaker_repository->getByMember($current_member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $current_member_id));
$presentation = $this->event_repository->getById($presentation_id);
if(is_null($presentation))
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation instanceof Presentation)
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(sprintf("member %s can not edit presentation %s",
$current_member_id,
$presentation_id
));
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
$presentation->removeSpeaker($speaker);
});
}
}