Skip to content

Commit

Permalink
Merge pull request #50 from someline/5.4.3@dev
Browse files Browse the repository at this point in the history
5.4.3@dev
  • Loading branch information
libern authored May 28, 2017
2 parents c7f99c8 + f972b62 commit 802f3bb
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 7 deletions.
230 changes: 230 additions & 0 deletions .idea/someline-starter.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use Illuminate\Http\Request;
use Someline\Http\Controllers\BaseController;
use Someline\Image\Controllers\SomelineImageController;
use Someline\Image\SomelineImageService;
use Someline\Models\Image\SomelineImage;
use Someline\Image\SomelineImageService;

class ImageController extends BaseController
{
Expand All @@ -20,20 +20,31 @@ public function postImage(Request $request)
/** @var SomelineImage $somelineImage */
$somelineImage = $somelineImageService->handleUploadedFile($file);
} catch (Exception $e) {
return 'Failed to save: ' . $e->getMessage();
return response('Failed to save: ' . $e->getMessage(), 422);
}

if (!$somelineImage) {
return 'Failed to save uploaded image.';
return response('Failed to save uploaded image.', 422);
}

$somelineImageId = $somelineImage->getSomelineImageId();
return 'Saved: ' . $somelineImage->getImageUrl();
return response([
'data' => [
'someline_image_id' => $somelineImage->getSomelineImageId(),
'someline_image_url' => $somelineImage->getImageUrl(),
'thumbnail_image_url' => $somelineImage->getTypeImageUrl('thumbnail'),
]
]);
}

public function showOriginalImage($image_name)
{
return SomelineImageController::showImage('original', $image_name);
}

public function showTypeImage($type, $image_name)
{
return SomelineImageController::showImage($type, $image_name);
}

}
5 changes: 5 additions & 0 deletions app/Providers/ApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Someline\Providers;

use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

class ApiServiceProvider extends ServiceProvider
{
Expand All @@ -16,6 +18,9 @@ class ApiServiceProvider extends ServiceProvider
public function boot()
{
$handler = app('Dingo\Api\Exception\Handler');
$handler->register(function (AuthenticationException $exception) {
throw new UnauthorizedHttpException(null, $exception->getMessage());
});
$handler->register(function (AuthorizationException $exception) {
throw new AccessDeniedHttpException($exception->getMessage());
});
Expand Down
10 changes: 8 additions & 2 deletions app/Transformers/BaseTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class BaseTransformer extends Transformer
public function includeUser(BaseModel $model)
{
$user = $model->user;
return $this->item($user, new UserTransformer(), 'user');
if ($user) {
return $this->item($user, new UserTransformer(), 'user');
}
return null;
}

/**
Expand All @@ -32,7 +35,10 @@ public function includeUser(BaseModel $model)
public function includeAuthUser(BaseModel $model)
{
$user = auth_user();
return $this->item($user, new UserTransformer());
if ($user) {
return $this->item($user, new UserTransformer());
}
return null;
}

}
5 changes: 4 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@
// @WARNING: The 'image' prefix is reserved for SomelineImageService
Route::group(['prefix' => 'image'], function () {

Route::post('/', 'ImageController@postImage');
Route::group(['middleware' => 'auth'], function () {
Route::post('/', 'ImageController@postImage');
});

Route::get('{type}/{name}', 'ImageController@showTypeImage');
Route::get('/{name}', 'ImageController@showOriginalImage');

});
Expand Down

0 comments on commit 802f3bb

Please sign in to comment.