From 5ee4d1b8a664b698b109735e8da451bd6e261810 Mon Sep 17 00:00:00 2001 From: Will Kiiskila Date: Thu, 9 Jan 2025 21:25:26 -0800 Subject: [PATCH] setup api endpoints for system messages --- .../Controllers/SystemMessageController.php | 36 +++++++++++++++++++ app/Http/Resources/SystemMessageResource.php | 29 +++++++++++++++ .../SystemMessageSummaryResource.php | 19 ++++++++++ routes/api.php | 3 ++ routes/system_message_routes.php | 13 +++++++ 5 files changed, 100 insertions(+) create mode 100644 app/Http/Controllers/SystemMessageController.php create mode 100644 app/Http/Resources/SystemMessageResource.php create mode 100644 app/Http/Resources/SystemMessageSummaryResource.php create mode 100644 routes/system_message_routes.php diff --git a/app/Http/Controllers/SystemMessageController.php b/app/Http/Controllers/SystemMessageController.php new file mode 100644 index 0000000..1a74614 --- /dev/null +++ b/app/Http/Controllers/SystemMessageController.php @@ -0,0 +1,36 @@ +has('error_code')) { + $query->where('error_code', $request->input('error_code')); + } + + $systemMessages = $query->select('id', 'error_code', 'error_message', 'error_data_group_id')->get(); + + return SystemMessageSummaryResource::collection($systemMessages); + } + + public function show($id) + { + $systemMessage = SystemMessage::findOrFail($id); + return new SystemMessageResource($systemMessage); + } + + public function getLastUpdated() + { + $lastUpdated = SystemMessage::max('updated_at'); + return response()->json(['last_updated' => $lastUpdated]); + } +} diff --git a/app/Http/Resources/SystemMessageResource.php b/app/Http/Resources/SystemMessageResource.php new file mode 100644 index 0000000..cc02ea8 --- /dev/null +++ b/app/Http/Resources/SystemMessageResource.php @@ -0,0 +1,29 @@ + $this->id, + 'error_code' => $this->error_code, + 'error_message' => $this->error_message, + 'icm_error_solution' => $this->icm_error_solution, + 'explanation' => $this->explanation, + 'fix' => $this->fix, + 'service_desk' => $this->service_desk, + 'limited_data' => $this->limited_data, + 'last_updated' => $this->updated_at, + 'error_entity' => $this->errorEntity->name ?? null, + 'error_data_group' => $this->errorDataGroup->name ?? null, + 'error_integration_state' => $this->errorIntegrationState->name ?? null, + 'error_actor' => $this->errorActor->name ?? null, + 'error_source' => $this->errorSource->name ?? null, + ]; + } +} diff --git a/app/Http/Resources/SystemMessageSummaryResource.php b/app/Http/Resources/SystemMessageSummaryResource.php new file mode 100644 index 0000000..524bbee --- /dev/null +++ b/app/Http/Resources/SystemMessageSummaryResource.php @@ -0,0 +1,19 @@ + $this->id, + 'error_code' => $this->error_code, + 'error_message' => $this->error_message, + 'data_group' => $this->errorDataGroup->name ?? null, + ]; + } +} diff --git a/routes/api.php b/routes/api.php index cbade83..7c7c63b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -9,3 +9,6 @@ // BRE routes require __DIR__ . '/bre_routes.php'; + +// System Message routes +require __DIR__ . '/system_message_routes.php'; diff --git a/routes/system_message_routes.php b/routes/system_message_routes.php new file mode 100644 index 0000000..2b8f33d --- /dev/null +++ b/routes/system_message_routes.php @@ -0,0 +1,13 @@ +middleware(['auth:sanctum', 'ability:admin,fodig']); + +Route::get('/system-messages', [SystemMessageController::class, 'index']) + ->middleware(['auth:sanctum', 'ability:admin,fodig']); + +Route::get('/system-messages/{id}', [SystemMessageController::class, 'show']) + ->middleware(['auth:sanctum', 'ability:admin,fodig']);