diff --git a/app/Http/Controllers/API/AppController.php b/app/Http/Controllers/API/AppController.php index 38096bc..964bd1c 100644 --- a/app/Http/Controllers/API/AppController.php +++ b/app/Http/Controllers/API/AppController.php @@ -12,19 +12,48 @@ use App\Http\Resources\API\AppForOwner; use App\Http\Resources\API\AppUser; use App\Models\Setting; use App\Models\User; -use http\Env\Request; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Laravel\Lumen\Routing\Controller as BaseController; use TaGeSo\APIResponse\Response; class AppController extends BaseController { - public function listApps(Response $response) { + public function createApp(Request $request, Response $response) { if(!Auth::check()) { throw new NotLoggedInException(); } - if(!app('currentAccess')->getApp()->access_read_apps) { + if (!Auth::user()->developer) { + throw new NoPermissionException(403, "You need a developer Account to create new Apps."); + } + + if (!app('currentAccess')->getApp()->access_update_apps) { + throw new NoPermissionException(403, "App has no access to perform this request."); + } + + $this->validate($request, [ + 'name' => 'required|max:255|min:3|regex:@^[a-zA-Z0-9]*$@|unique:apps', + 'description' => 'required|min:3', + 'url' => 'required|url' + ]); + + $app = \App\Models\App::createApp($request->input("name"), htmlspecialchars($request->input("description")), $request->input("url"), Auth::user()); + + return $response->withData(new AppForOwner($app)); + + + } + public function listApps(Response $response) { + if (!Auth::check()) { + throw new NotLoggedInException(); + } + + if (!Auth::user()->developer) { + throw new NoPermissionException(403, "You need a developer Account to create new Apps."); + } + + if (!app('currentAccess')->getApp()->access_read_apps) { throw new NoPermissionException(403, "App has no access to perform this request."); } diff --git a/routes/web.php b/routes/web.php index 726c17e..6e47f05 100644 --- a/routes/web.php +++ b/routes/web.php @@ -48,6 +48,7 @@ $router->group(['prefix' => 'api'], function () use ($router) { }); $router->group(['prefix' => 'app'], function () use ($router) { $router->get("/", ['uses' => 'API\AppController@listApps']); + $router->post("/", ['uses' => 'API\AppController@createApp']); $router->get("/find", ['uses' => 'API\AppController@findApp']); $router->group(['prefix' => '{id}'], function () use ($router) { $router->get("/", ['uses' => 'API\AppController@appDetails']);