getApp()->access_read_apps) { throw new NoPermissionException(403, "App has no access to perform this request."); } $apps = \App\Models\App::query()->where("user_id", "=", Auth::user()->id)->get(); return $response->withData(AppForOwner::collection(collect($apps))); } public function appDetails(Response $response, $id) { if(!Auth::check()) { throw new NotLoggedInException(); } $app = \App\Models\App::query()->where("id", "=", (int)$id)->firstOrFail(); if($app->user_id == Auth::user()->id) { return $response->withData(new AppForOwner($app)); } return $response->withData(new App($app)); } public function findApp(Response $response, \Illuminate\Http\Request $request) { if(!Auth::check()) { throw new NotLoggedInException(); } $this->validate($request, [ 'apiKey' => '', ]); $query = \App\Models\App::query(); if($request->input("apiKey", false)) { $query->where("apiKey", "=", $request->input("apiKey")); } $apps = $query->paginate(20); $response->setPagination($apps->currentPage(), $apps->lastPage(), $apps->perPage()); return $response->withData(App::collection($apps)); } public function updateApp(Response $response, \Illuminate\Http\Request $request, $id) { if(!Auth::check()) { throw new NotLoggedInException(); } $this->validate($request, [ 'name' => 'required|max:255|min:3|regex:@^[a-zA-Z0-9]*$@', 'description' => 'required|min:3', 'url' => 'required|url', 'direct_url' => 'url' ]); $app = \App\Models\App::query()->where("id", "=", $id)->firstOrFail(); if($app->user_id != Auth::user()->id) { throw new NoPermissionException(403, "Not your app (".$app->user_id."/".Auth::user()->id.")"); } $app->name = $request->input("name"); $app->description = $request->input("description"); $app->url = $request->input("url"); $app->direct_url = $request->input("direct_url"); $app->saveOrFail(); return $response->withData(new AppForOwner($app)); } public function getUsers(Response $response, $id) { if(!Auth::check()) { throw new NotLoggedInException(); } $app = \App\Models\App::query()->where("id", "=", $id)->firstOrFail(); if($app->user_id != Auth::user()->id) { throw new NoPermissionException(403, "Not your app"); } $access = \App\Models\AppAccess::query()->where("status", "=", "allowed")->where("app_id", "=", $id)->paginate(100); $response->setPagination( $access->currentPage(), $access->lastPage(), $access->perPage() ); return $response->withData(AppUser::collection($access)); } }