Added endpoint to delete
RSVP Question Value DELETE /api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}/values/{value_id} Change-Id: Icb1a8d10735549fedce9f7f920594d293b5c1031
This commit is contained in:
parent
e35c0fb5d7
commit
d2a9492239
@ -536,4 +536,36 @@ final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedContro
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $template_id
|
||||
* @param $question_id
|
||||
* @param $value_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteRSVPTemplateQuestionValue($summit_id, $template_id, $question_id, $value_id){
|
||||
try {
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$this->rsvp_template_service->deleteQuestionValue($summit, $template_id, $question_id, $value_id);
|
||||
|
||||
return $this->deleted();
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -182,6 +182,7 @@ Route::group([
|
||||
Route::group(['prefix' => '{value_id}'], function () {
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@getRSVPTemplateQuestionValue']);
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@updateRSVPTemplateQuestionValue']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@deleteRSVPTemplateQuestionValue']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -11,6 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Main\OrderableChilds;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@ -70,42 +71,15 @@ class SummitVenue extends SummitGeoLocatedLocation
|
||||
$room->setVenue($this);
|
||||
}
|
||||
|
||||
use OrderableChilds;
|
||||
|
||||
/**
|
||||
* @param SummitVenueRoom $room
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateRoomsOrder(SummitVenueRoom $room, $new_order){
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$rooms = $this->rooms->matching($criteria)->toArray();
|
||||
$rooms = array_slice($rooms,0, count($rooms), false);
|
||||
$max_order = count($rooms);
|
||||
$former_order = 1;
|
||||
foreach ($rooms as $r){
|
||||
if($r->getId() == $room->getId()) break;
|
||||
$former_order++;
|
||||
}
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($rooms[$former_order - 1]);
|
||||
|
||||
$rooms = array_merge
|
||||
(
|
||||
array_slice($rooms, 0, $new_order -1 , true) ,
|
||||
[$room] ,
|
||||
array_slice($rooms, $new_order -1 , count($rooms), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($rooms as $r){
|
||||
$r->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
|
||||
self::recalculateOrderFor($this->rooms, $room, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Main\OrderableChilds;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\File;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
@ -205,42 +206,15 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
||||
$room->clearFloor();
|
||||
}
|
||||
|
||||
use OrderableChilds;
|
||||
|
||||
/**
|
||||
* @param SummitVenueRoom $room
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateRoomsOrder(SummitVenueRoom $room, $new_order){
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$rooms = $this->rooms->matching($criteria)->toArray();
|
||||
$rooms = array_slice($rooms,0, count($rooms), false);
|
||||
$max_order = count($rooms);
|
||||
$former_order = 1;
|
||||
foreach ($rooms as $r){
|
||||
if($r->getId() == $room->getId()) break;
|
||||
$former_order++;
|
||||
}
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($rooms[$former_order - 1]);
|
||||
|
||||
$rooms = array_merge
|
||||
(
|
||||
array_slice($rooms, 0, $new_order -1 , true) ,
|
||||
[$room] ,
|
||||
array_slice($rooms, $new_order -1 , count($rooms), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($rooms as $r){
|
||||
$r->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
|
||||
self::recalculateOrderFor($this->rooms, $room, $new_order);
|
||||
}
|
||||
|
||||
}
|
@ -12,18 +12,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use App\Models\Foundation\Main\IOrderable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SummitVenueRoom")
|
||||
* Class SummitVenueRoom
|
||||
* @package models\summit
|
||||
*/
|
||||
class SummitVenueRoom extends SummitAbstractLocation
|
||||
class SummitVenueRoom extends SummitAbstractLocation implements IOrderable
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\SummitVenue", inversedBy="rooms")
|
||||
|
@ -73,7 +73,6 @@ interface IRSVPTemplateService
|
||||
*/
|
||||
public function addQuestionValue($summit, $template_id, $question_id, $payload);
|
||||
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $template_id
|
||||
@ -86,4 +85,15 @@ interface IRSVPTemplateService
|
||||
*/
|
||||
public function updateQuestionValue($summit, $template_id, $question_id, $value_id, $payload);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $template_id
|
||||
* @param int $question_id
|
||||
* @param int $value_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteQuestionValue($summit, $template_id, $question_id, $value_id);
|
||||
|
||||
}
|
@ -431,4 +431,84 @@ final class RSVPTemplateService implements IRSVPTemplateService
|
||||
return $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $template_id
|
||||
* @param int $question_id
|
||||
* @param int $value_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteQuestionValue($summit, $template_id, $question_id, $value_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $template_id, $question_id, $value_id){
|
||||
|
||||
$template = $summit->getRSVPTemplateById($template_id);
|
||||
|
||||
if(is_null($template))
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.deleteQuestionValue.TemplateNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$question = $template->getQuestionById($question_id);
|
||||
if(is_null($question))
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.deleteQuestionValue.QuestionNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
'question_id' => $question_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
if(!$question instanceof RSVPMultiValueQuestionTemplate)
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.deleteQuestionValue.QuestionNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
'question_id' => $question_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$value = $question->getValueById($value_id);
|
||||
|
||||
if(is_null($value)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.deleteQuestionValue.ValueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
'question_id' => $question_id,
|
||||
'value_id' => $value_id
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$question->removeValue($value);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
@ -50,4 +50,7 @@ return [
|
||||
'RSVPTemplateService.deleteQuestion.QuestionNotFound' => 'question :question_id not found on template :template_id',
|
||||
'RSVPTemplateService.addQuestionValue.TemplateNotFound' => 'template :template_id not found on summit :summit_id',
|
||||
'RSVPTemplateService.addQuestionValue.QuestionNotFound' => 'question :question_id not found on template :template_id',
|
||||
'RSVPTemplateService.deleteQuestionValue.TemplateNotFound' => 'template :template_id not found on summit :summit_id',
|
||||
'RSVPTemplateService.deleteQuestionValue.QuestionNotFound' => 'question :question_id not found on template :template_id',
|
||||
'RSVPTemplateService.deleteQuestionValue.ValueNotFound' => 'value :value_id not found on question :question_id',
|
||||
];
|
@ -347,4 +347,35 @@ final class OAuth2SummitRSVPTemplateApiTest extends ProtectedApiTest
|
||||
$this->assertTrue($value->order == 3);
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function testDeleteRSVPQuestionValue($summit_id = 24, $template_id = 13, $question_id = 86){
|
||||
|
||||
$value = $this->testAddRSVPQuestionValue($summit_id, $template_id, $question_id);
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'template_id' => $template_id,
|
||||
'question_id' => $question_id,
|
||||
'value_id' => $value->id
|
||||
];
|
||||
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"DELETE",
|
||||
"OAuth2SummitRSVPTemplatesApiController@deleteRSVPTemplateQuestionValue",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user