Skip to content

Commit

Permalink
Adds controller logic and route defintion for generating targets base…
Browse files Browse the repository at this point in the history
…d on an existing workflown namespace
  • Loading branch information
craigpaul committed Nov 26, 2023
1 parent 797ef1c commit 08feb19
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
use Illuminate\Support\Facades\Route;

Route::get('_blitz/workflows')->name('blitz.workflows')->uses([Controllers\WorkflowController::class, 'index']);
Route::post('_blitz/targets')->name('blitz.targets')->uses([Controllers\TargetController::class, 'store']);
41 changes: 41 additions & 0 deletions src/Http/Controllers/TargetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace CraigPaul\Blitz\Http\Controllers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class TargetController
{
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Routing\ResponseFactory $response
*
* @return void
*/
public function __construct(
protected Application $app,
protected ResponseFactory $response,
) {
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request): JsonResponse
{
$instance = $this->app->make($request->post('namespace'));

$instance->setUp();

return $this->response->json($instance->getTargets());
}
}

0 comments on commit 08feb19

Please sign in to comment.