[]]], tags: ['Templates'], parameters: [ new OA\Parameter(name: 'slug', description: 'Template slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')), ], responses: [ new OA\Response( response: 202, description: 'Generation started', content: new OA\JsonContent( properties: [ new OA\Property(property: 'message', type: 'string', example: 'درخواست تولید پاورپوینت ثبت شد.'), new OA\Property( property: 'data', properties: [ new OA\Property(property: 'generation', ref: '#/components/schemas/TemplateGeneration'), ], type: 'object' ), ] ) ), new OA\Response(response: 401, description: 'Unauthenticated'), new OA\Response(response: 422, description: 'Validation error'), ] )] public function store(GenerateTemplateRequest $request, Template $template): JsonResponse { $uuid = (string) Str::uuid(); $values = $request->validated('values', []); $storedValues = []; foreach ($template->keys as $key) { if (! array_key_exists($key->key, $values)) { continue; } if ($key->type === TemplateKeyType::Image) { $storedValues[$key->key] = $request->file('values.'.$key->key) ->store('templates/generations/inputs/'.$uuid, 'local'); continue; } $storedValues[$key->key] = $values[$key->key]; } $generation = TemplateGeneration::query()->create([ 'template_id' => $template->id, 'uuid' => $uuid, 'status' => TemplateGenerationStatus::Pending, 'values' => $storedValues, 'requested_by' => $request->user()->id, ]); GenerateTemplateJob::dispatch($generation); return $this->success('درخواست تولید پاورپوینت ثبت شد.', [ 'generation' => new TemplateGenerationResource($generation), ], 202); } #[OA\Get( path: '/generations/{uuid}', description: 'Get the status of a presentation generation request', summary: 'Show generation status', security: [['sanctum' => []]], tags: ['Templates'], parameters: [ new OA\Parameter(name: 'uuid', description: 'Generation uuid', in: 'path', required: true, schema: new OA\Schema(type: 'string')), ], responses: [ new OA\Response( response: 200, description: 'Generation status fetched successfully', content: new OA\JsonContent( properties: [ new OA\Property(property: 'message', type: 'string', example: 'وضعیت تولید با موفقیت دریافت شد.'), new OA\Property( property: 'data', properties: [ new OA\Property(property: 'generation', ref: '#/components/schemas/TemplateGeneration'), ], type: 'object' ), ] ) ), new OA\Response(response: 401, description: 'Unauthenticated'), new OA\Response(response: 403, description: 'Forbidden'), new OA\Response(response: 404, description: 'Not found'), ] )] public function show(TemplateGeneration $generation): JsonResponse { abort_if($generation->requested_by !== request()->user()->id, 403); return $this->success('وضعیت تولید با موفقیت دریافت شد.', [ 'generation' => new TemplateGenerationResource($generation), ]); } #[OA\Get( path: '/generations/{uuid}/download', description: 'Download the generated presentation file', summary: 'Download generated presentation', security: [['sanctum' => []]], tags: ['Templates'], parameters: [ new OA\Parameter(name: 'uuid', description: 'Generation uuid', in: 'path', required: true, schema: new OA\Schema(type: 'string')), ], responses: [ new OA\Response(response: 200, description: 'File download'), new OA\Response(response: 401, description: 'Unauthenticated'), new OA\Response(response: 403, description: 'Forbidden'), new OA\Response(response: 404, description: 'Not found or not ready'), ] )] public function download(TemplateGeneration $generation): StreamedResponse { abort_if($generation->requested_by !== request()->user()->id, Response::HTTP_FORBIDDEN); abort_if($generation->status !== TemplateGenerationStatus::Completed || ! $generation->output_path, Response::HTTP_NOT_FOUND); return Storage::disk('local')->download($generation->output_path, $generation->template->slug.'.pptx'); } }