Skip to content

Commit

Permalink
setup api endpoints for system messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kiiskila-bcgov committed Jan 10, 2025
1 parent 06f0584 commit 5ee4d1b
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/Http/Controllers/SystemMessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\SystemMessage;
use App\Http\Resources\SystemMessageResource;
use App\Http\Resources\SystemMessageSummaryResource;

class SystemMessageController extends Controller
{
public function index(Request $request)
{
$query = SystemMessage::query();

if ($request->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]);
}
}
29 changes: 29 additions & 0 deletions app/Http/Resources/SystemMessageResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class SystemMessageResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $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,
];
}
}
19 changes: 19 additions & 0 deletions app/Http/Resources/SystemMessageSummaryResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class SystemMessageSummaryResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'error_code' => $this->error_code,
'error_message' => $this->error_message,
'data_group' => $this->errorDataGroup->name ?? null,
];
}
}
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

// BRE routes
require __DIR__ . '/bre_routes.php';

// System Message routes
require __DIR__ . '/system_message_routes.php';
13 changes: 13 additions & 0 deletions routes/system_message_routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\SystemMessageController;

Route::get('/system-messages/last-updated', [SystemMessageController::class, 'getLastUpdated'])
->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']);

0 comments on commit 5ee4d1b

Please sign in to comment.