implemented step 12 by Gemini
- Task actions
This commit is contained in:
66
src/Actions/TaskActions.php
Normal file
66
src/Actions/TaskActions.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Services\FileStorage;
|
||||
use App\Services\ConsentService;
|
||||
use Exception;
|
||||
|
||||
class TaskActions
|
||||
{
|
||||
private FileStorage $storage;
|
||||
private ProjectActions $projectActions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->storage = new FileStorage();
|
||||
$this->projectActions = new ProjectActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AI generation task for a project.
|
||||
*/
|
||||
public function generateWebsite(string $userId, string $projectId): array
|
||||
{
|
||||
// 1. Verify project ownership and status
|
||||
$projectData = $this->projectActions->getProjectStatus($userId, $projectId);
|
||||
|
||||
// 2. Prevent duplicate queuing
|
||||
if ($projectData['status'] === 'queued' || $projectData['status'] === 'generating') {
|
||||
return ['message' => 'Generation already in progress.', 'status' => $projectData['status']];
|
||||
}
|
||||
|
||||
// 3. Verify GDPR consent
|
||||
$consentService = new ConsentService();
|
||||
if (!$consentService->hasConsent($projectId)) {
|
||||
throw new Exception("GDPR consent is required for AI generation.", 403);
|
||||
}
|
||||
|
||||
// 4. Create Task
|
||||
$taskId = 't_' . bin2hex(random_bytes(8));
|
||||
$taskData = [
|
||||
'task_id' => $taskId,
|
||||
'project_id' => $projectId,
|
||||
'status' => 'queued',
|
||||
'attempt_count' => 0,
|
||||
'max_attempts' => 3,
|
||||
'created_at' => date('c'),
|
||||
'wizard_data' => $projectData['wizard_data']
|
||||
];
|
||||
|
||||
$this->storage->put("llm/{$taskId}.json", $taskData);
|
||||
|
||||
// 5. Update Project Status
|
||||
$projectData['status'] = 'queued';
|
||||
$projectData['updated_at'] = date('c');
|
||||
$this->storage->put("projects/{$projectId}.json", $projectData);
|
||||
|
||||
return [
|
||||
'task_id' => $taskId,
|
||||
'status' => 'queued',
|
||||
'message' => 'Project successfully queued for generation.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user