Add Template Creation Functionality in Admin Panel (#729)
* Add create template functionality in Admin Panel - Implemented a new endpoint for creating templates in AdminController, utilizing the GenerateTemplate command. - Added a form in the admin settings Vue component to allow users to input a template description and submit it. - Enhanced the user experience with loading states and success/error alerts during template creation. These changes facilitate the generation of new form templates directly from the admin interface, improving usability and functionality. * Update template prompt validation length in AdminController - Increased the maximum length of the 'template_prompt' field from 1000 to 4000 characters in the createTemplate method. This change allows for more extensive template descriptions, enhancing the flexibility of template creation in the admin panel. * Refactor template generation to use job-based approach - Migrate template generation logic from the GenerateTemplate command to a new GenerateTemplateJob class for improved separation of concerns and better handling of asynchronous processing. - Update AdminController to utilize the new job for generating templates, enhancing maintainability and clarity in the codebase. - Remove unused dependencies and streamline the command's handle method for better performance and readability. * fix lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\Template\GenerateTemplateJob;
|
||||
use App\Models\Forms\Form;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -18,6 +19,20 @@ class AdminController extends Controller
|
||||
$this->middleware('moderator');
|
||||
}
|
||||
|
||||
public function createTemplate(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'template_prompt' => 'required|string|max:4000'
|
||||
]);
|
||||
|
||||
$job = new GenerateTemplateJob($request->template_prompt);
|
||||
$job->handle();
|
||||
|
||||
return $this->success([
|
||||
'template_slug' => $job->generatedTemplate?->slug ?? null
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetchUser($identifier)
|
||||
{
|
||||
$user = null;
|
||||
|
||||
Reference in New Issue
Block a user