This commit is contained in:
foobar
2022-08-21 21:39:06 +02:00
commit 27c1969aaa
7354 changed files with 897064 additions and 0 deletions

56
routes/api.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
use App\Models\City;
use App\Http\Resources\CityResource;
use App\Http\Resources\CityCollection;
use App\Filters\CityFilter;
use App\Http\Controllers\DatabaseController;
use App\Http\Requests\StoreCityRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Requests\UpdateCityRequest;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('/city/{id}', function ($id) {
return new CityResource(City::findOrFail($id));
});
Route::get('/city', function (Request $request) {
$filter = new CityFilter();
$filterItems = $filter->transform($request); // [['column', 'operator', 'value']]
return new CityCollection(City::where($filterItems)->get());
});
Route::group(['middleware' => 'auth:sanctum'], function() {
Route::post('/city', function (StoreCityRequest $request) {
$id = DatabaseController::storeApiRequest($request);
return new CityResource(City::findOrFail($id));
});
Route::put('/city/{id}', function ($id, UpdateCityRequest $request) {
$DatabaseController = new DatabaseController();
$DatabaseController->updateApiRequest($id, $request);
});
Route::delete('/city/{id}', function ($id) {
City::findOrFail($id)->delete();
});
});

18
routes/channels.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
use Illuminate\Support\Facades\Broadcast;
/*
|--------------------------------------------------------------------------
| Broadcast Channels
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});

19
routes/console.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
/*
|--------------------------------------------------------------------------
| Console Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of your Closure based console
| commands. Each Closure is bound to a command instance allowing a
| simple approach to interacting with each command's IO methods.
|
*/
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');

48
routes/web.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CityController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This application only has a single view which contains a form for adding new cities as well as a listing of all current cities.|
| |
*/
/**
* Show City Dashboard
*/
Route::get('/', [CityController::class, 'show']);
/**
* Add New City
*
* The form in our view will create a new city via POST request.
* We will use the validate method provided by the Illuminate\Http\Request object. If the validation rules pass, your code will keep executing normally; however, if validation fails, an Illuminate\Validation\ValidationException exception will be thrown and the proper error response will automatically be sent back to the user.
* If validation fails during a traditional HTTP request, a redirect response to the previous URL will be generated. If the incoming request is an XHR request, a JSON response containing the validation error messages will be returned.
* If the validation fails, we will redirect the user back to the / URL, as well as flash the old input and errors into the session.
*
* Fun Fact: There is a city called Taumatawhakatangihangakoauauotamateapokaiwhenuakitanatahu (85 characters) in New Zealand, so we allow max. 85 characters for city names.
* TODO: Change validate language to german.
*/
Route::post('/city', [CityController::class, 'create']);
/**
* Delete City
*
* Once the record is deleted, we will redirect the user back to the / endpoint.
*/
Route::delete('/city/{id}', [CityController::class, 'delete']);
/**
* Refresh weather data
*/
Route::post('/refresh', [CityController::class, 'refresh']);
/**
* Generate Bearer-Token for Laravel Sanctum API authentication
*/
Route::get('/setup', [CityController::class, 'setup']);