added endpoint to update location maps and get by id
PUT /api/v1/summits/{id}/locations/{location_id}/maps/{map_id} Content Type multipart/form-data' * file (sometimes) * name (sometimes|string|max:255) * description (sometimes|string) GET /api/v1/summits/{id}/locations/{location_id}/maps/{map_id} Change-Id: I00d28aae722ba7416317c561b2e42140908d73b5
This commit is contained in:
parent
c87f7ee320
commit
92f87924df
|
@ -768,6 +768,42 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $location_id
|
||||
* @param $map_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLocationMap($summit_id, $location_id, $map_id){
|
||||
try {
|
||||
|
||||
$expand = Request::input('expand', '');
|
||||
$relations = Request::input('relations', '');
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$location = $summit->getLocation($location_id);
|
||||
if (is_null($location)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
if (!Summit::isPrimaryLocation($location)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
$map = $location->getMap($map_id);
|
||||
if (is_null($map)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($map)->serialize($expand,[], $relations));
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param LaravelRequest $request
|
||||
* @param $summit_id
|
||||
|
@ -799,7 +835,7 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
);
|
||||
}
|
||||
|
||||
$this->location_service->addLocationMap
|
||||
$map = $this->location_service->addLocationMap
|
||||
(
|
||||
$summit,
|
||||
$location_id,
|
||||
|
@ -809,6 +845,8 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
),
|
||||
$file
|
||||
);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($map)->serialize());
|
||||
}
|
||||
catch (EntityNotFoundException $ex1) {
|
||||
Log::warning($ex1);
|
||||
|
@ -856,6 +894,10 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
$input = $multiPartRequestParser->getInput();
|
||||
$metadata = $input['parameters'];
|
||||
$files = $input['files'];
|
||||
$file = null;
|
||||
|
||||
if(count($files) > 0)
|
||||
$file = $files[0];
|
||||
|
||||
$rules = SummitLocationImageValidationRulesFactory::build(true);
|
||||
// Creates a Validator instance and validates the data.
|
||||
|
@ -869,6 +911,20 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$map = $this->location_service->updateLocationMap
|
||||
(
|
||||
$summit,
|
||||
$location_id,
|
||||
$map_id,
|
||||
HTMLCleaner::cleanData
|
||||
(
|
||||
$metadata, ['description']
|
||||
),
|
||||
$file
|
||||
);
|
||||
|
||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($map)->serialize());
|
||||
}
|
||||
catch (EntityNotFoundException $ex1) {
|
||||
Log::warning($ex1);
|
||||
|
|
|
@ -84,11 +84,8 @@ class OAuth2BearerAccessTokenRequestValidator
|
|||
$method = $request->getMethod();
|
||||
$realm = $request->getHost();
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
return $response;
|
||||
|
||||
try {
|
||||
|
||||
$route = RequestUtils::getCurrentRoutePath($request);
|
||||
if (!$route) {
|
||||
throw new OAuth2ResourceServerException(
|
||||
|
|
|
@ -347,10 +347,11 @@ Route::group([
|
|||
|
||||
// locations maps
|
||||
Route::group(['prefix' => 'maps'], function () {
|
||||
Route::post('', 'OAuth2SummitLocationsApiController@addLocationMap');
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addLocationMap']);
|
||||
Route::group(['prefix' => '{map_id}'], function () {
|
||||
Route::put('', 'OAuth2SummitLocationsApiController@updateLocationMap');
|
||||
Route::delete('', 'OAuth2SummitLocationsApiController@deleteLocationMap');
|
||||
Route::get('', 'OAuth2SummitLocationsApiController@getLocationMap');
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateLocationMap']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@deleteLocationMap']);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ class SummitGeoLocatedLocation extends SummitAbstractLocation
|
|||
(
|
||||
Criteria::create()
|
||||
->where(Criteria::expr()->eq("class_name", SummitLocationImage::TypeMap))
|
||||
->orderBy(array("order" => Criteria::ASC))
|
||||
->orderBy(["order" => Criteria::ASC])
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -392,6 +392,21 @@ class SummitGeoLocatedLocation extends SummitAbstractLocation
|
|||
return $res === false ? null : $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $map_id
|
||||
* @return SummitLocationImage
|
||||
*/
|
||||
public function getMap($map_id){
|
||||
$res = $this->images
|
||||
->matching
|
||||
(
|
||||
Criteria::create()->where(Criteria::expr()->eq("id", $map_id))->andWhere(Criteria::expr()->eq("class_name", SummitLocationImage::TypeMap))
|
||||
|
||||
)->first();
|
||||
return $res === false ? null : $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SummitLocationImage $map
|
||||
*/
|
||||
|
|
|
@ -158,4 +158,16 @@ interface ILocationService
|
|||
*/
|
||||
public function addLocationMap(Summit $summit, $location_id, array $metadata, UploadedFile $file);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $location_id
|
||||
* @param int $map_id
|
||||
* @param array $metadata
|
||||
* @param $file
|
||||
* @return SummitLocationImage
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateLocationMap(Summit $summit, $location_id, $map_id, array $metadata, UploadedFile $file);
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ use App\Events\FloorInserted;
|
|||
use App\Events\FloorUpdated;
|
||||
use App\Events\LocationDeleted;
|
||||
use App\Events\LocationImageInserted;
|
||||
use App\Events\LocationImageUpdated;
|
||||
use App\Events\LocationInserted;
|
||||
use App\Events\LocationUpdated;
|
||||
use App\Events\SummitVenueRoomDeleted;
|
||||
|
@ -1195,4 +1196,112 @@ final class LocationService implements ILocationService
|
|||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $location_id
|
||||
* @param int $map_id
|
||||
* @param array $metadata
|
||||
* @param $file
|
||||
* @return SummitLocationImage
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateLocationMap(Summit $summit, $location_id, $map_id, array $metadata, UploadedFile $file)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $location_id, $map_id, $metadata, $file) {
|
||||
$max_file_size = config('file_upload.max_file_upload_size') ;
|
||||
$allowed_extensions = ['png','jpg','jpeg','gif','pdf'];
|
||||
$location = $summit->getLocation($location_id);
|
||||
|
||||
if (is_null($location)) {
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans(
|
||||
'not_found_errors.LocationService.addLocationMap.LocationNotFound',
|
||||
[
|
||||
'location_id' => $location_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(!$location instanceof SummitGeoLocatedLocation){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans(
|
||||
'not_found_errors.LocationService.addLocationMap.LocationNotFound',
|
||||
[
|
||||
'location_id' => $location_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$map = $location->getMap($map_id);
|
||||
|
||||
if (is_null($map)) {
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans(
|
||||
'not_found_errors.LocationService.addLocationMap.MapNotFound',
|
||||
[
|
||||
'map_id' => $map_id,
|
||||
'location_id' => $location_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(!is_null($file)) {
|
||||
if (!in_array($file->extension(), $allowed_extensions)) {
|
||||
throw new ValidationException
|
||||
(
|
||||
trans(
|
||||
'validation_errors.LocationService.addLocationMap.FileNotAllowedExtension',
|
||||
[
|
||||
'allowed_extensions' => implode(", ", $allowed_extensions),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($file->getSize() > $max_file_size) {
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.addLocationMap.FileMaxSize',
|
||||
[
|
||||
'max_file_size' => (($max_file_size / 1024) / 1024)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$uploader = new FileUploader($this->folder_repository);
|
||||
$pic = $uploader->build($file, sprintf('summits/%s/locations/%s/maps/', $location->getSummitId(), $location->getId()), true);
|
||||
$map->setPicture($pic);
|
||||
}
|
||||
|
||||
$map = SummitLocationImageFactory::populate($map, $metadata);
|
||||
|
||||
if (isset($metadata['order']) && intval($metadata['order']) != $map->getOrder()) {
|
||||
// request to update order
|
||||
$location->recalculateMapOrder($map, intval($metadata['order']));
|
||||
}
|
||||
|
||||
Event::fire
|
||||
(
|
||||
new LocationImageUpdated
|
||||
(
|
||||
$map->getId(),
|
||||
$map->getLocationId(),
|
||||
$map->getLocation()->getSumitId(),
|
||||
$map->getClassName()
|
||||
)
|
||||
);
|
||||
return $map;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -528,6 +528,15 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-location-map',
|
||||
'route' => '/api/v1/summits/{id}/locations/{location_id}/maps/{map_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-location-map',
|
||||
'route' => '/api/v1/summits/{id}/locations/{location_id}/maps/{map_id}',
|
||||
|
|
|
@ -32,4 +32,5 @@ return [
|
|||
'LocationService.updateLocationBanner.LocationNotFound' => 'location :location_id not found on summit :summit_id',
|
||||
'LocationService.updateLocationBanner.BannerNotFound'=> 'banner :banner_id not found on location :location_id',
|
||||
'LocationService.addLocationMap.LocationNotFound' => 'location :location_id not found on summit :summit_id',
|
||||
'LocationService.addLocationMap.MapNotFound' => 'map :map_id does not belongs to location :location_id',
|
||||
];
|
Loading…
Reference in New Issue