<?php

use App\Http\Controllers\ReviewController;
use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| 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 github new
 * */
Route::post('/github-oLpwmFNisOxKseNqAQDdoxkap', function () {
    try {
        $data = request()->all();
        $branchName = $data['push']['changes'][0]['old']['name'];
        $oldPath = getcwd();
        chdir(base_path());
        if ($branchName == 'master') {
            exec("bash ./build.sh");
        }
        chdir($oldPath);
    } catch(\Exception $e) {
        abort(400);
    }
});

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::group([
//    'middleware' => 'api',
    //'prefix' => 'api'

], function ($router) {
    Route::post('/review/register', [ReviewController::class, 'registerReview']);
    Route::post('/review/edit', [ReviewController::class, 'updateReview']);
    Route::post('/review/delete/{id}', [ReviewController::class, 'delReview']);
});
