Skip to content

A self-hosted media server and file management system

chore: code smells

aminnausin0f42818290d3
diff --git a/app/Http/Controllers/Api/V1/CategoryController.php b/app/Http/Controllers/Api/V1/CategoryController.php
index 46dc8d09..2db0dbae 100755
--- a/app/Http/Controllers/Api/V1/CategoryController.php
+++ b/app/Http/Controllers/Api/V1/CategoryController.php
@@ -8,37 +8,32 @@ use App\Http\Requests\CategoryUpdateRequest;
use App\Http\Resources\CategoryResource;
use App\Models\Category;
use App\Models\Folder;
+use App\Traits\HasModelHelpers;
use App\Traits\HttpResponses;
use Illuminate\Support\Facades\Auth;
class CategoryController extends Controller {
use HttpResponses;
+ use HasModelHelpers;
/**
* Display a listing of the resource.
*/
public function index() {
- try {
- $categories = Category::orderBy('name');
- $userId = Auth::id();
- if (Auth::id() !== 1) {
- $categories->where('is_private', false);
- }
-
- if (! $userId) {
- return $this->success(
- [new CategoryResource($categories->with(['folders.series'])->first())]
- );
- }
-
- return $this->success(
- CategoryResource::collection(
- $categories->with(['folders.series'])->get()
- )
- );
- } catch (\Throwable $th) {
- return $this->error(null, 'Unable to get list of categories. Error: ' . $th->getMessage(), 500);
+ $categories = Category::orderBy('name');
+ $userId = Auth::id();
+
+ if ($userId !== 1) {
+ $categories->where('is_private', false);
}
+
+ $categories = $categories->with(['folders.series']);
+
+ return $this->success(
+ $userId
+ ? CategoryResource::collection($categories->get())
+ : [new CategoryResource($categories->first())]
+ );
}
/**
@@ -64,21 +59,18 @@ class CategoryController extends Controller {
return $this->forbidden();
}
- try {
- $validated = $request->validated();
+ $validated = $request->validated();
- $folder = Folder::where('id', $validated['default_folder_id'])->first();
- if (! $folder || $folder->category_id != $category->id) {
- return $this->error($category, 'Folder cannot be assigned to category!', 500);
- }
+ $folder = Folder::findOrFail($validated['default_folder_id']);
- $validated['editor_id'] = Auth::id();
- $category->update($validated);
-
- return $this->success($validated);
- } catch (\Throwable $th) {
- return $this->error($request, 'Unable to edit category. Error: ' . $th->getMessage(), 500);
+ if ($this->conflictsWithAnother("category_id", $folder, $category->id)) {
+ return $this->error($category, 'Folder cannot be assigned to category!', 500);
}
+
+ $validated['editor_id'] = Auth::id();
+ $category->update($validated);
+
+ return $this->success($validated);
}
/**
@@ -91,18 +83,11 @@ class CategoryController extends Controller {
return $this->forbidden();
}
- try {
- $validated = $request->validated();
- $validated['editor_id'] = Auth::id();
-
- $category->is_private = $validated['is_private'] ?? $category->is_private;
- $category->editor_id = $validated['editor_id'];
+ $validated = $request->validated();
+ $category->is_private = $validated['is_private'] ?? $category->is_private;
+ $category->editor_id = Auth::id();
+ $category->save();
- $category->save();
-
- return $this->success($validated);
- } catch (\Throwable $th) {
- return $this->error($request, 'Unable to edit category permissions. Error: ' . $th->getMessage(), 500);
- }
+ return $this->success($validated);
}
}
diff --git a/resources/js/components/pulseCards/PulseExceptions.vue b/resources/js/components/pulseCards/PulseExceptions.vue
index 83f796c5..beec3a2c 100644
--- a/resources/js/components/pulseCards/PulseExceptions.vue
+++ b/resources/js/components/pulseCards/PulseExceptions.vue
@@ -6,6 +6,7 @@ import { computed, ref } from 'vue';
import { sortObject } from '@/service/sort/baseSort';
import { toTimeSpan } from '@/service/util';
+import PulseSelectLabel from '@/components/pulse/PulseSelectLabel.vue';
import PulseNoResults from '@/components/pulse/PulseNoResults.vue';
import DashboardCard from '@/components/cards/DashboardCard.vue';
import PulseScroll from '@/components/pulse/PulseScroll.vue';
@@ -72,10 +73,8 @@ const exceptions = computed(() => {
</template>
<template #actions>
- <label
- class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-gray-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"
- >Sort By</label
- >
+ <PulseSelectLabel controlId="Select-Exceptions-Order"> Sort By </PulseSelectLabel>
+
<InputSelect
:placeholder="'None'"
:options="exceptionOptions"
@@ -83,6 +82,7 @@ const exceptions = computed(() => {
title="Select usage type"
@selectItem="handleSetSort"
:defaultItem="0"
+ id="Select-Exceptions-Order"
/>
</template>