ルーターにコールバックで直接登録されてるルートをコントローラーに移動 (#111)
This commit is contained in:
parent
d0dd2db159
commit
307e578d4a
54
app/Http/Controllers/Api/CardController.php
Normal file
54
app/Http/Controllers/Api/CardController.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
|
||||
use App\Metadata;
|
||||
use App\MetadataResolver\MetadataResolver;
|
||||
use App\Utilities\Formatter;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CardController
|
||||
{
|
||||
/**
|
||||
* @var MetadataResolver
|
||||
*/
|
||||
private $resolver;
|
||||
/**
|
||||
* @var Formatter
|
||||
*/
|
||||
private $formatter;
|
||||
|
||||
public function __construct(MetadataResolver $resolver, Formatter $formatter)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'url:required|url'
|
||||
]);
|
||||
|
||||
$url = $this->formatter->normalizeUrl($request->input('url'));
|
||||
|
||||
$metadata = Metadata::find($url);
|
||||
if ($metadata === null || ($metadata->expires_at !== null && $metadata->expires_at < now())) {
|
||||
$resolved = $this->resolver->resolve($url);
|
||||
$metadata = Metadata::updateOrCreate(['url' => $url], [
|
||||
'title' => $resolved->title,
|
||||
'description' => $resolved->description,
|
||||
'image' => $resolved->image,
|
||||
'expires_at' => $resolved->expires_at
|
||||
]);
|
||||
}
|
||||
|
||||
$response = response($metadata);
|
||||
if (!config('app.debug')) {
|
||||
$response = $response->setCache(['public' => true, 'max_age' => 86400]);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -11,7 +11,10 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
//
|
||||
public function redirectMypage()
|
||||
{
|
||||
return redirect()->route('user.profile', ['name' => auth()->user()->name]);
|
||||
}
|
||||
|
||||
public function profile($name)
|
||||
{
|
||||
|
@ -1,9 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\MetadataResolver\MetadataResolver;
|
||||
use App\Utilities\Formatter;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
@ -15,31 +11,8 @@ use Illuminate\Http\Request;
|
||||
|
|
||||
*/
|
||||
|
||||
Route::middleware('auth:api')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
//Route::middleware('auth:api')->get('/user', function (Request $request) {
|
||||
// return $request->user();
|
||||
//});
|
||||
|
||||
Route::get('/checkin/card', function (Request $request, MetadataResolver $resolver, Formatter $formatter) {
|
||||
$request->validate([
|
||||
'url:required|url'
|
||||
]);
|
||||
$url = $formatter->normalizeUrl($request->input('url'));
|
||||
|
||||
$metadata = App\Metadata::find($url);
|
||||
if ($metadata == null || ($metadata->expires_at !== null && $metadata->expires_at < now())) {
|
||||
$resolved = $resolver->resolve($url);
|
||||
$metadata = App\Metadata::updateOrCreate(['url' => $url], [
|
||||
'title' => $resolved->title,
|
||||
'description' => $resolved->description,
|
||||
'image' => $resolved->image,
|
||||
'expires_at' => $resolved->expires_at
|
||||
]);
|
||||
}
|
||||
|
||||
$response = response()->json($metadata);
|
||||
if (!config('app.debug')) {
|
||||
$response = $response->setCache(['public' => true, 'max_age' => 86400]);
|
||||
}
|
||||
|
||||
return $response;
|
||||
});
|
||||
Route::get('/checkin/card', 'Api\\CardController@show');
|
||||
|
@ -15,9 +15,7 @@ Auth::routes();
|
||||
|
||||
Route::get('/', 'HomeController@index')->name('home');
|
||||
|
||||
Route::get('/user', function () {
|
||||
return redirect()->route('user.profile', ['name' => Auth::user()->name]);
|
||||
})->middleware('auth')->name('user.profile');
|
||||
Route::get('/user', 'UserController@redirectMypage')->middleware('auth');
|
||||
Route::get('/user/{name?}', 'UserController@profile')->name('user.profile');
|
||||
Route::get('/user/{name}/stats', 'UserController@stats')->name('user.stats');
|
||||
Route::get('/user/{name}/okazu', 'UserController@okazu')->name('user.okazu');
|
||||
|
Loading…
Reference in New Issue
Block a user