Skip to content

A free open source IT asset/license management system

Changed NotesController::getList() to NotesController::index() & reordered methods for consistency

Nicky Westc94a8c42f4f6
diff --git a/app/Http/Controllers/Api/NotesController.php b/app/Http/Controllers/Api/NotesController.php
index 965eec96dd..c1a16fd4d6 100644
--- a/app/Http/Controllers/Api/NotesController.php
+++ b/app/Http/Controllers/Api/NotesController.php
@@ -18,41 +18,6 @@ use Illuminate\Support\Facades\Log;
*/
class NotesController extends Controller
{
- /**
- * Store a manual note on a specified asset and log the action.
- *
- * Checks authorization for updating assets, validates the presence of the 'note',
- * attempts to find the asset by ID, and creates a new ActionLog entry if successful.
- * Returns JSON responses indicating success or failure with appropriate HTTP status codes.
- *
- * @param \Illuminate\Http\Request $request The incoming HTTP request containing the 'note'.
- * @param Asset $asset The ID of the asset to attach the note to.
- * @return \Illuminate\Http\JsonResponse
- */
- public function store(Request $request, Asset $asset): JsonResponse
- {
- $this->authorize('update', $asset);
-
- if ($request->input('note', '') == '') {
- return response()->json(Helper::formatStandardApiResponse('error', null, trans('validation.required', ['attribute' => 'note'])), 422);
- }
-
- // Create the note
- $logaction = new ActionLog();
- $logaction->item_type = get_class($asset);
- $logaction->created_by = Auth::id();
- $logaction->item_id = $asset->id;
- $logaction->note = $request->input('note', '');
-
- if ($logaction->logaction('note added')) {
- // Return a success response
- return response()->json(Helper::formatStandardApiResponse('success', ['note' => $logaction->note, 'item_id' => $asset->id], trans('general.note_added')));
- }
-
- // Return an error response if something went wrong
- return response()->json(Helper::formatStandardApiResponse('error', null, 'Something went wrong'), 500);
- }
-
/**
* Retrieve a list of manual notes (action logs) for a given asset.
*
@@ -64,7 +29,7 @@ class NotesController extends Controller
* @param Asset $asset The ID of the asset whose notes to retrieve.
* @return \Illuminate\Http\JsonResponse
*/
- public function getList(Asset $asset): JsonResponse
+ public function index(Asset $asset): JsonResponse
{
$this->authorize('view', $asset);
@@ -92,4 +57,39 @@ class NotesController extends Controller
// Return a success response
return response()->json(Helper::formatStandardApiResponse('success', ['notes' => $notesArray, 'asset_id' => $asset->id]));
}
+
+ /**
+ * Store a manual note on a specified asset and log the action.
+ *
+ * Checks authorization for updating assets, validates the presence of the 'note',
+ * attempts to find the asset by ID, and creates a new ActionLog entry if successful.
+ * Returns JSON responses indicating success or failure with appropriate HTTP status codes.
+ *
+ * @param \Illuminate\Http\Request $request The incoming HTTP request containing the 'note'.
+ * @param Asset $asset The ID of the asset to attach the note to.
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function store(Request $request, Asset $asset): JsonResponse
+ {
+ $this->authorize('update', $asset);
+
+ if ($request->input('note', '') == '') {
+ return response()->json(Helper::formatStandardApiResponse('error', null, trans('validation.required', ['attribute' => 'note'])), 422);
+ }
+
+ // Create the note
+ $logaction = new ActionLog();
+ $logaction->item_type = get_class($asset);
+ $logaction->created_by = Auth::id();
+ $logaction->item_id = $asset->id;
+ $logaction->note = $request->input('note', '');
+
+ if ($logaction->logaction('note added')) {
+ // Return a success response
+ return response()->json(Helper::formatStandardApiResponse('success', ['note' => $logaction->note, 'item_id' => $asset->id], trans('general.note_added')));
+ }
+
+ // Return an error response if something went wrong
+ return response()->json(Helper::formatStandardApiResponse('error', null, 'Something went wrong'), 500);
+ }
}
diff --git a/routes/api.php b/routes/api.php
index 001061fc9f..b139f3e81d 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -855,12 +855,12 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'api-throttle:api']], fu
)->name('api.notes.store');
Route::get(
- '{asset}/getList',
+ '{asset}/index',
[
Api\NotesController::class,
- 'getList'
+ 'index'
]
- )->name('api.notes.getList');
+ )->name('api.notes.index');
}
); // end asset notes API routes
diff --git a/tests/Feature/Assets/Api/AssetNotesTest.php b/tests/Feature/Assets/Api/AssetNotesTest.php
index 5096546af7..b3076c2852 100644
--- a/tests/Feature/Assets/Api/AssetNotesTest.php
+++ b/tests/Feature/Assets/Api/AssetNotesTest.php
@@ -67,7 +67,7 @@ class AssetNotesTest extends TestCase
]);
$this->actingAsForApi($user)
- ->getJson(route('api.notes.getList', $asset))
+ ->getJson(route('api.notes.index', $asset))
->assertOk()
->assertJson([
'messages' => null,