Implement legal document acceptance tracking requiring users to accept terms of service and privacy policy before continuing to use the system. Add automatic generation of standard project files (LICENSE, README.md, RULES.md, cookies.html, termos-de-uso.html, privacidade.html) with download functionality. Enhance prompt building with detailed Portuguese instructions and system requirements. Update seeders with comprehensive legal content and standard files configuration for all prompt templates.
202 lines
5.9 KiB
PHP
Executable File
202 lines
5.9 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\PromptProject;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\PromptProject\StorePromptProjectRequest;
|
|
use App\Http\Requests\PromptProject\UpdatePromptProjectRequest;
|
|
use App\Models\AiModel;
|
|
use App\Models\AiProvider;
|
|
use App\Models\PromptGeneration;
|
|
use App\Models\PromptProject;
|
|
use App\Services\PromptProjectService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\View\View;
|
|
|
|
class PromptProjectController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*/
|
|
public function __construct(
|
|
private readonly PromptProjectService $promptProjectService
|
|
) {}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(): View
|
|
{
|
|
$result = $this->promptProjectService->index();
|
|
$projects = $result['data'] ?? [];
|
|
|
|
return view('prompt-projects.index', compact('projects'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(): View
|
|
{
|
|
$this->authorize('create', \App\Models\PromptProject::class);
|
|
|
|
$providers = AiProvider::where('is_active', true)->get();
|
|
|
|
return view('prompt-projects.create', compact('providers'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StorePromptProjectRequest $request): RedirectResponse
|
|
{
|
|
$this->authorize('create', \App\Models\PromptProject::class);
|
|
|
|
$this->promptProjectService->store($request->validated());
|
|
|
|
return redirect()->route('prompt-projects.index')
|
|
->with('success', 'Project created successfully.');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(PromptProject $promptProject): View
|
|
{
|
|
$this->authorize('view', $promptProject);
|
|
|
|
$providerModels = AiModel::where('provider_id', $promptProject->provider_id)
|
|
->where('is_active', true)
|
|
->get();
|
|
|
|
$models = $providerModels->isNotEmpty()
|
|
? $providerModels
|
|
: AiModel::where('is_active', true)->get();
|
|
|
|
$generations = PromptGeneration::where('project_id', $promptProject->id)
|
|
->latest()
|
|
->take(5)
|
|
->get();
|
|
|
|
$standardFiles = $this->promptProjectService->getStandardFiles($promptProject);
|
|
|
|
return view('prompt-projects.show', compact('promptProject', 'models', 'generations', 'standardFiles'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(\App\Models\PromptProject $promptProject): View
|
|
{
|
|
$this->authorize('update', $promptProject);
|
|
|
|
$providers = AiProvider::where('is_active', true)->get();
|
|
|
|
return view('prompt-projects.edit', compact('promptProject', 'providers'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdatePromptProjectRequest $request, \App\Models\PromptProject $promptProject): RedirectResponse
|
|
{
|
|
$this->authorize('update', $promptProject);
|
|
|
|
$this->promptProjectService->update($promptProject, $request->validated());
|
|
|
|
return redirect()->route('prompt-projects.show', $promptProject)
|
|
->with('success', 'Project updated successfully.');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(\App\Models\PromptProject $promptProject): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $promptProject);
|
|
|
|
$this->promptProjectService->destroy($promptProject);
|
|
|
|
return redirect()->route('prompt-projects.index')
|
|
->with('success', 'Project deleted successfully.');
|
|
}
|
|
|
|
/**
|
|
* Generate prompt for the specified project.
|
|
*/
|
|
public function generate(PromptProject $promptProject, Request $request): RedirectResponse
|
|
{
|
|
$this->authorize('update', $promptProject);
|
|
|
|
$model = null;
|
|
if ($request->filled('model')) {
|
|
$modelSlug = $request->input('model');
|
|
|
|
if ($modelSlug === 'outros') {
|
|
$customModel = $request->input('custom_model');
|
|
if ($customModel) {
|
|
$model = $customModel;
|
|
}
|
|
} else {
|
|
$model = AiModel::where('slug', $modelSlug)
|
|
->where('is_active', true)
|
|
->first();
|
|
}
|
|
}
|
|
|
|
$this->promptProjectService->generate($promptProject, $model, Auth::id());
|
|
|
|
return redirect()->route('prompt-projects.show', $promptProject)
|
|
->with('success', 'Prompt generated successfully.');
|
|
}
|
|
|
|
/**
|
|
* Get built prompt for the specified project.
|
|
*/
|
|
public function getPrompt(PromptProject $promptProject): JsonResponse
|
|
{
|
|
$this->authorize('view', $promptProject);
|
|
|
|
$prompt = $this->promptProjectService->buildPrompt($promptProject);
|
|
|
|
return response()->json(['prompt' => $prompt]);
|
|
}
|
|
|
|
/**
|
|
* Get standard files for the specified project.
|
|
*/
|
|
public function getStandardFiles(PromptProject $promptProject): JsonResponse
|
|
{
|
|
$this->authorize('view', $promptProject);
|
|
|
|
$files = $this->promptProjectService->getStandardFiles($promptProject);
|
|
|
|
return response()->json($files);
|
|
}
|
|
|
|
/**
|
|
* Download a standard file for the specified project.
|
|
*/
|
|
public function downloadFile(PromptProject $promptProject, string $filename)
|
|
{
|
|
$this->authorize('view', $promptProject);
|
|
|
|
$files = $this->promptProjectService->getStandardFiles($promptProject);
|
|
|
|
if (!isset($files[$filename])) {
|
|
abort(404);
|
|
}
|
|
|
|
$content = $files[$filename];
|
|
|
|
return response()->streamDownload(function () use ($content) {
|
|
echo $content;
|
|
}, $filename);
|
|
}
|
|
}
|