Fixed bug on event update

* location TBA
* validation errors

Change-Id: Iad3e9486edf83cc738906ddb0918f011a0d2420b
This commit is contained in:
Sebastian Marcet 2017-12-06 20:39:40 -03:00
parent dd7687aa89
commit f100a1df2d
4 changed files with 30 additions and 18 deletions

View File

@ -346,19 +346,18 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
if(!Request::isJson()) return $this->error403();
$data = Input::json();
$rules = array
(
$rules = [
'title' => 'sometimes|required|string|max:100',
'description' => 'sometimes|required|string',
'description' => 'sometimes|string',
'social_summary' => 'sometimes|string|max:100',
'location_id' => 'sometimes|required|integer',
'start_date' => 'sometimes|required|date_format:U',
'location_id' => 'sometimes|integer',
'start_date' => 'sometimes|date_format:U',
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
'allow_feedback' => 'sometimes|required|boolean',
'allow_feedback' => 'sometimes|boolean',
'type_id' => 'sometimes|required|integer',
'track_id' => 'sometimes|required|integer',
'tags' => 'sometimes|required|string_array',
);
'tags' => 'sometimes|string_array',
];
// Creates a Validator instance and validates the data.
$validation = Validator::make($data->all(), $rules);
@ -372,12 +371,11 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
);
}
$fields = array
(
$fields = [
'title',
'description',
'social_summary',
);
];
$event = $this->service->updateEvent($summit, $event_id, HTMLCleaner::cleanData($data->all(), $fields));

View File

@ -541,6 +541,11 @@ class SummitEvent extends SilverstripeBaseModel
return $this;
}
public function clearLocation(){
$this->location = null;
return $this;
}
/**
* @return SummitAbstractLocation
*/

View File

@ -593,7 +593,7 @@ final class SummitService implements ISummitService
$location = null;
if (isset($data['location_id'])) {
$location = $summit->getLocation(intval($data['location_id']));
if (is_null($location)) {
if (is_null($location) && intval($data['location_id']) > 0) {
throw new EntityNotFoundException(sprintf("location id %s does not exists!", $data['location_id']));
}
}
@ -619,7 +619,7 @@ final class SummitService implements ISummitService
$event->setRsvpLink(html_entity_decode(trim($data['rsvp_link'])));
if (isset($data['head_count']))
$event->setHeadCount(intval(data['head_count']));
$event->setHeadCount(intval($data['head_count']));
if (isset($data['social_summary']))
$event->setSocialSummary(strip_tags(trim($data['social_summary'])));
@ -641,13 +641,17 @@ final class SummitService implements ISummitService
}
$event->setSummit($summit);
if (!is_null($location))
if(!is_null($location))
$event->setLocation($location);
if(is_null($location) && isset($data['location_id'])){
// clear location
$event->clearLocation();
}
$this->updateEventDates($data, $summit, $event);
if (isset($data['tags']) && count($data['tags']) > 0) {
if (isset($data['tags'])) {
$event->clearTags();
foreach ($data['tags'] as $str_tag) {
$tag = $this->tag_repository->getByTag($str_tag);
@ -665,7 +669,7 @@ final class SummitService implements ISummitService
throw new ValidationException('sponsors are mandatory!');
}
if (count($sponsors) > 0) {
if (isset($data['sponsors'])) {
$event->clearSponsors();
foreach ($sponsors as $sponsor_id) {
$sponsor = $this->company_repository->getById(intval($sponsor_id));

View File

@ -2444,7 +2444,12 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$params = [
'id' => 23,
'filter' => ['selection_status==lightning-alternate', 'event_type_id==117'],
'filter' =>
[
'selection_status==lightning-alternate',
'event_type_id==117',
'title=@test,abstract=@test,social_summary=@test,tags=@test,speaker=@test'
],
'expand' => 'speakers',
];