-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup api endpoints for system messages
- Loading branch information
1 parent
06f0584
commit 5ee4d1b
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); |