added new endpoint add location banner

POST /api/v1/summits/{id}/locations/{location_id}/banners
Payload

* title (required|string)
* content (required|string)
* type (required|in:Primary,Secondary)
* enabled (required|boolean)
* class_name (required|in:SummitLocationBanner, ScheduledSummitLocationBanner)

Payload part for ScheduledSummitLocationBanner

* start_date (required|date_format:U)
* end_date (required_with:start_date|date_format:U|after:start_date)

Required Scopes

* '%s/summits/write'
* '%s/locations/write'
* '%s/locations/banners/write'

Change-Id: Ic8de4a81c4d57253bbe25559a5ba7f50d1c7730d
This commit is contained in:
Sebastian Marcet
2018-03-07 19:01:04 -03:00
parent ec4a3474ad
commit dda0d68378
25 changed files with 1359 additions and 25 deletions

View File

@@ -12,6 +12,7 @@
* limitations under the License.
**/
use App\Http\Utils\PagingConstants;
use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBannerConstants;
use App\Models\Foundation\Summit\Locations\SummitLocationConstants;
use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository;
use App\Services\Model\ILocationService;
@@ -20,6 +21,7 @@ use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Validator;
use libs\utils\HTMLCleaner;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\oauth2\IResourceServerContext;
@@ -1553,4 +1555,64 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
return $this->error500($ex);
}
}
/**
* Location Banners Endpoints
*/
/**
* @param $summit_id
* @param $location_id
* @return mixed
*/
public function addLocationBanner($summit_id, $location_id){
try {
if(!Request::isJson()) return $this->error403();
$payload = Input::json()->all();
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();
$rules = SummitLocationBannerValidationRulesFactory::build($payload);
// Creates a Validator instance and validates the data.
$validation = Validator::make($payload, $rules);
if ($validation->fails()) {
$messages = $validation->messages()->toArray();
return $this->error412
(
$messages
);
}
if(!in_array($payload["class_name"], SummitLocationBannerConstants::$valid_class_names) ){
throw new ValidationException(
sprintf
(
"class_name has an invalid value ( valid values are %s",
implode(", ", SummitLocationBannerConstants::$valid_class_names)
)
);
}
$banner = $this->location_service->addLocationBanner($summit, $location_id, HTMLCleaner::cleanData($payload, ['title', 'content']));
return $this->created(SerializerRegistry::getInstance()->getSerializer($banner)->serialize());
}
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);
}
}
}