|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\API;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Http\Requests\API\Library\CreateOrUpdateRequest;
|
|
|
use App\Http\Resources\API\LibraryResource;
|
|
|
+use App\Models\Enums\LibraryType;
|
|
|
use App\Models\Library;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
@@ -28,7 +29,7 @@ class LibraryController extends Controller
|
|
|
...$request->all(),
|
|
|
'created_by' => Auth::id(),
|
|
|
'company_id' => Auth::user()->company_id,
|
|
|
- 'whitelist' => $request->whitelist ? sprintf(",%s", implode(',', $request->whitelist)) : null,
|
|
|
+ 'whitelist' => $request->whitelist ? sprintf(",%s,", implode(',', $request->whitelist)) : null,
|
|
|
]);
|
|
|
|
|
|
return $this->created();
|
|
@@ -39,7 +40,7 @@ class LibraryController extends Controller
|
|
|
*/
|
|
|
public function show(string $id)
|
|
|
{
|
|
|
- $library = Library::query()->findOrFail($id);
|
|
|
+ $library = Library::allowed()->findOrFail($id);
|
|
|
|
|
|
return new LibraryResource($library);
|
|
|
}
|
|
@@ -49,7 +50,7 @@ class LibraryController extends Controller
|
|
|
*/
|
|
|
public function update(Request $request, string $id)
|
|
|
{
|
|
|
- $library = Library::query()->findOrFail($id);
|
|
|
+ $library = Library::query()->allowed()->findOrFail($id);
|
|
|
|
|
|
$library->fill($request->only([
|
|
|
'name', 'acl', 'asset_id', 'project_id',
|
|
@@ -68,4 +69,27 @@ class LibraryController extends Controller
|
|
|
{
|
|
|
//
|
|
|
}
|
|
|
+
|
|
|
+ public function linkage(Request $request, string $type)
|
|
|
+ {
|
|
|
+ $libraryType = LibraryType::from($type);
|
|
|
+ if (in_array($libraryType->value, [LibraryType::PROJECT->value, LibraryType::ASSET->value]) && !$request->get("id")) {
|
|
|
+ return $this->badRequest("Parameter ID cannot be empty");
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = match ($libraryType) {
|
|
|
+ LibraryType::ASSET => ['asset_id' => $request->get("id")],
|
|
|
+ LibraryType::PROJECT => ['project_id' => $request->get("id")],
|
|
|
+ LibraryType::CUSTOM => []
|
|
|
+ };
|
|
|
+
|
|
|
+ $libraries = Library::query()
|
|
|
+ ->allowed()
|
|
|
+ ->where("type", $type)->when($where, fn($query) => $query->where($where))
|
|
|
+ ->get(['id', 'name']);
|
|
|
+
|
|
|
+ return $this->success([
|
|
|
+ 'data' => $libraries
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|