diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php index 2eeb7dd5..8c5769b6 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php @@ -452,12 +452,18 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController return $this->error500($ex); } } + /** + * @param $summit_id * @param $presentation_id * @return mixed */ - public function deletePresentation($presentation_id){ + public function deletePresentation($summit_id, $presentation_id){ try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); if (is_null($current_member_id)) return $this->error403(); @@ -467,7 +473,7 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController if(is_null($member)) return $this->error403(); - $this->presentation_service->deletePresentation($member, $presentation_id); + $this->presentation_service->deletePresentation($summit, $member, $presentation_id); return $this->deleted(); diff --git a/app/Models/Foundation/Summit/Summit.php b/app/Models/Foundation/Summit/Summit.php index a6479d8f..0016d0d2 100644 --- a/app/Models/Foundation/Summit/Summit.php +++ b/app/Models/Foundation/Summit/Summit.php @@ -674,10 +674,17 @@ class Summit extends SilverstripeBaseModel */ public function addEvent(SummitEvent $event) { + if($this->events->contains($event)) return; $this->events->add($event); $event->setSummit($this); } + public function removeEvent(SummitEvent $event){ + if(!$this->events->contains($event)) return; + $this->events->removeElement($event); + $event->clearSummit(); + } + /** * @return File */ diff --git a/app/Services/Model/IPresentationService.php b/app/Services/Model/IPresentationService.php index be2bc059..0e39e48f 100644 --- a/app/Services/Model/IPresentationService.php +++ b/app/Services/Model/IPresentationService.php @@ -80,11 +80,12 @@ interface IPresentationService public function completePresentationSubmission(Summit $summit, $presentation_id, Member $member); /** + * @param Summit $summit * @param Member $member * @param int $presentation_id * @throws ValidationException * @throws EntityNotFoundException * @return void */ - public function deletePresentation(Member $member, $presentation_id); + public function deletePresentation(Summit $summit, Member $member, $presentation_id); } \ No newline at end of file diff --git a/app/Services/Model/PresentationService.php b/app/Services/Model/PresentationService.php index bdc832a7..5d877c43 100644 --- a/app/Services/Model/PresentationService.php +++ b/app/Services/Model/PresentationService.php @@ -493,21 +493,22 @@ final class PresentationService } /** + * @param Summit $summit * @param Member $member * @param int $presentation_id * @throws ValidationException * @throws EntityNotFoundException * @return void */ - public function deletePresentation(Member $member, $presentation_id) + public function deletePresentation(Summit $summit, Member $member, $presentation_id) { - return $this->tx_service->transaction(function () use ($member, $presentation_id) { + return $this->tx_service->transaction(function () use ($summit, $member, $presentation_id) { $current_speaker = $this->speaker_repository->getByMember($member); if(is_null($current_speaker)) throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $member->getId())); - $presentation = $this->presentation_repository->getById($presentation_id); + $presentation = $summit->getEvent($presentation_id); if(is_null($presentation)) throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id)); @@ -520,7 +521,8 @@ final class PresentationService $presentation_id )); - $this->event_repository->delete($presentation); + $summit->removeEvent($presentation); + }); } diff --git a/tests/OAuth2PresentationSubmissionTest.php b/tests/OAuth2PresentationSubmissionTest.php index 29f42cb1..2dc0e472 100644 --- a/tests/OAuth2PresentationSubmissionTest.php +++ b/tests/OAuth2PresentationSubmissionTest.php @@ -30,16 +30,10 @@ class OAuth2PresentationSubmissionTest extends ProtectedApiTest 'social_description' => 'this is a social description', 'level' => 'N/A', 'attendees_expected_learnt' => 'super duper', - 'type_id' => 171, + 'type_id' => 182, 'track_id' => 262, 'attending_media' => true, 'links' => ['https://www.google.com'], - 'extra_questions' => [ - [ - 'id' => 24, - 'value' => 'test', - ] - ], 'tags' => ['Upstream Development'] ]; @@ -66,4 +60,34 @@ class OAuth2PresentationSubmissionTest extends ProtectedApiTest $this->assertEquals($title, $presentation->title); return $presentation; } + + /** + * @param int $summit_id + */ + public function testDeletePresentation($summit_id = 25){ + $new_presentation = $this->testSubmitPresentation($summit_id); + $params = [ + 'id' => $summit_id, + 'presentation_id' => $new_presentation->id, + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "DELETE", + "OAuth2PresentationApiController@deletePresentation", + $params, + [], + [], + [], + $headers, + '' + ); + + $content = $response->getContent(); + $this->assertResponseStatus(204); + } } \ No newline at end of file