68 lines
2 KiB
PHP
68 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Exceptions\HTTPException;
|
|
use App\Exceptions\NoPermissionException;
|
|
use App\Exceptions\NotLoggedInException;
|
|
use App\Exceptions\ResourceNotFound;
|
|
use App\Http\Resources\API\App;
|
|
use App\Http\Resources\API\AppForOwner;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
use http\Env\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) {
|
|
if(!Auth::check()) {
|
|
throw new NotLoggedInException();
|
|
}
|
|
|
|
if(!app('currentAccess')->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));
|
|
|
|
}
|
|
}
|