Skip to content

Commit 32976b7

Browse files
committed
finish release 0.1.0
2 parents 3c02bdd + 6e0e150 commit 32976b7

File tree

137 files changed

+22059
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+22059
-0
lines changed

api/.env.example

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_LOG_LEVEL=debug
6+
APP_URL=http://localhost
7+
8+
DB_CONNECTION=mysql
9+
DB_HOST=127.0.0.1
10+
DB_PORT=3306
11+
DB_DATABASE=homestead
12+
DB_USERNAME=homestead
13+
DB_PASSWORD=secret
14+
15+
BROADCAST_DRIVER=log
16+
CACHE_DRIVER=file
17+
SESSION_DRIVER=file
18+
QUEUE_DRIVER=sync
19+
20+
REDIS_HOST=127.0.0.1
21+
REDIS_PASSWORD=null
22+
REDIS_PORT=6379
23+
24+
MAIL_DRIVER=smtp
25+
MAIL_HOST=smtp.mailtrap.io
26+
MAIL_PORT=2525
27+
MAIL_USERNAME=null
28+
MAIL_PASSWORD=null
29+
MAIL_ENCRYPTION=null
30+
31+
PUSHER_APP_ID=
32+
PUSHER_APP_KEY=
33+
PUSHER_APP_SECRET=

api/.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

api/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/storage/*.key
5+
/vendor
6+
/.idea
7+
/.vagrant
8+
Homestead.json
9+
Homestead.yaml
10+
npm-debug.log
11+
.env

api/app/Console/Kernel.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
*
24+
* @return void
25+
*/
26+
protected function schedule(Schedule $schedule)
27+
{
28+
// $schedule->command('inspire')
29+
// ->hourly();
30+
}
31+
32+
/**
33+
* Register the Closure based commands for the application.
34+
*
35+
* @return void
36+
*/
37+
protected function commands()
38+
{
39+
require base_path('routes/console.php');
40+
}
41+
}

api/app/Exceptions/Handler.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Auth\AuthenticationException;
7+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
8+
use Illuminate\Http\Response;
9+
use Illuminate\Support\Facades\File;
10+
use Illuminate\Support\Facades\Log;
11+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12+
13+
class Handler extends ExceptionHandler
14+
{
15+
/**
16+
* A list of the exception types that should not be reported.
17+
*
18+
* @var array
19+
*/
20+
protected $dontReport = [
21+
\Illuminate\Auth\AuthenticationException::class,
22+
\Illuminate\Auth\Access\AuthorizationException::class,
23+
\Symfony\Component\HttpKernel\Exception\HttpException::class,
24+
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
25+
\Illuminate\Session\TokenMismatchException::class,
26+
\Illuminate\Validation\ValidationException::class,
27+
];
28+
29+
/**
30+
* Report or log an exception.
31+
*
32+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
33+
*
34+
* @param \Exception $exception
35+
*
36+
* @return void
37+
*/
38+
public function report(Exception $exception)
39+
{
40+
parent::report($exception);
41+
}
42+
43+
/**
44+
* Render an exception into an HTTP response.
45+
*
46+
* @param \Illuminate\Http\Request $request
47+
* @param \Exception $exception
48+
*
49+
* @return \Illuminate\Http\Response
50+
*/
51+
public function render($request, Exception $exception)
52+
{
53+
// If no route is found, we will serve the React app. React will show a 404 page.
54+
if ($exception instanceof NotFoundHttpException && !strpos($request->url(), '/api')) {
55+
Log::info('NotFoundHttpException, Route not found, serving index.html of build folder');
56+
57+
return new Response(File::get(public_path().'/build/index.html'), Response::HTTP_OK);
58+
}
59+
60+
return parent::render($request, $exception);
61+
}
62+
63+
/**
64+
* Convert an authentication exception into an unauthenticated response.
65+
*
66+
* @param \Illuminate\Http\Request $request
67+
* @param \Illuminate\Auth\AuthenticationException $exception
68+
*
69+
* @return \Illuminate\Http\Response
70+
*/
71+
protected function unauthenticated($request, AuthenticationException $exception)
72+
{
73+
if ($request->expectsJson()) {
74+
return response()->json(['error' => 'Unauthenticated.'], 401);
75+
}
76+
77+
return redirect()->guest(route('login'));
78+
}
79+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
use Tymon\JWTAuth\Facades\JWTAuth;
8+
9+
class AuthController extends Controller
10+
{
11+
public function auth(Request $request)
12+
{
13+
$credentials = $request->only('email', 'password');
14+
15+
if (!$token = JWTAuth::attempt($credentials)) {
16+
return response()->json(['error' => 'invalid_credentials'], 401);
17+
}
18+
19+
return response()->json(compact('token'));
20+
}
21+
22+
public function me(Request $request)
23+
{
24+
dd(auth()->user());
25+
26+
return response()->json(auth()->user());
27+
}
28+
29+
public function refresh()
30+
{
31+
$token = JWTAuth::getToken();
32+
$newToken = JWTAuth::refresh($token);
33+
34+
return response()->json(compact('newToken'));
35+
}
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Requests\Api\ObservationModel;
7+
use App\Observation;
8+
use Illuminate\Support\Facades\Storage;
9+
10+
class ObservationController extends Controller
11+
{
12+
public function index()
13+
{
14+
return Observation::all();
15+
}
16+
17+
public function show($id)
18+
{
19+
$observation = Observation::find($id);
20+
21+
return $observation->toJson();
22+
}
23+
24+
public function getPicture($id)
25+
{
26+
$observation = Observation::find($id);
27+
$image = Storage::get($observation->picture_storage);
28+
29+
return response($image)->header('Content-Type', 'image/jpeg');
30+
}
31+
32+
public function store(ObservationModel $request)
33+
{
34+
$file = $request->file('image');
35+
$request['picture_storage'] = Storage::putFile('observations', $file);
36+
37+
return Observation::create($request->all());
38+
}
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Requests\Api\VoteModel;
7+
use App\Vote;
8+
9+
class VotesController extends Controller
10+
{
11+
public function store(VoteModel $request)
12+
{
13+
$currentVote = Vote::where(['observation_id' => $request->observation_id, 'user_id' => auth()->user()->id])->first();
14+
15+
if (!is_null($currentVote)) {
16+
return response()->json('You has already voted');
17+
}
18+
19+
$vote = new Vote($request->all());
20+
$vote->user_id = auth()->user()->id;
21+
$vote->save();
22+
23+
return $vote;
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Bus\DispatchesJobs;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Routing\Controller as BaseController;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13+
}

api/app/Http/Kernel.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Http;
4+
5+
use Illuminate\Foundation\Http\Kernel as HttpKernel;
6+
7+
class Kernel extends HttpKernel
8+
{
9+
/**
10+
* The application's global HTTP middleware stack.
11+
*
12+
* These middleware are run during every request to your application.
13+
*
14+
* @var array
15+
*/
16+
protected $middleware = [
17+
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
18+
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
19+
\App\Http\Middleware\TrimStrings::class,
20+
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
21+
];
22+
23+
/**
24+
* The application's route middleware groups.
25+
*
26+
* @var array
27+
*/
28+
protected $middlewareGroups = [
29+
'web' => [
30+
\App\Http\Middleware\EncryptCookies::class,
31+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
32+
\Illuminate\Session\Middleware\StartSession::class,
33+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
34+
\App\Http\Middleware\VerifyCsrfToken::class,
35+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
36+
],
37+
38+
'api' => [
39+
'throttle:60,1',
40+
'bindings',
41+
\Barryvdh\Cors\HandleCors::class,
42+
],
43+
];
44+
45+
/**
46+
* The application's route middleware.
47+
*
48+
* These middleware may be assigned to groups or used individually.
49+
*
50+
* @var array
51+
*/
52+
protected $routeMiddleware = [
53+
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
54+
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
55+
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
56+
'can' => \Illuminate\Auth\Middleware\Authorize::class,
57+
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
58+
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
59+
'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
60+
'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
61+
];
62+
}

0 commit comments

Comments
 (0)