HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux Bradford-Sitios 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api_matriculas/app/Http/Controllers/Signapis/SignapisTemplatesController.php
<?php

namespace App\Http\Controllers\Signapis;

use App\Http\Controllers\Controller;
use App\Services\Signapis\SignapisService;
use Illuminate\Http\Request;
use Exception;

class SignapisTemplatesController extends Controller
{
    protected SignapisService $signapis;

    public function __construct(SignapisService $signapis)
    {
        $this->signapis = $signapis;
    }

    // ======================================
    // 馃敼 TEMPLATES
    // ======================================

    /**
     * @OA\Post(
     *     path="/signapis/templates",
     *     summary="Crear plantilla de correo",
     *     tags={"SignApis/Templates"},
     *     @OA\RequestBody(
     *         required=true,
     *         @OA\JsonContent(
     *             @OA\Property(property="code", type="string"),
     *             @OA\Property(property="type", type="string"),
     *             @OA\Property(property="body", type="string"),
     *             @OA\Property(property="logoCode", type="string"),
     *             @OA\Property(property="footerCode", type="string")
     *         )
     *     ),
     *     @OA\Response(response=200, description="Plantilla creada")
     * )
     */
    public function createTemplate(Request $request)
    {
        try {
            $data = $this->signapis->createTemplate($request->all());
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

    /**
     * @OA\Get(
     *     path="/signapis/templates",
     *     summary="Listar todas las plantillas de correo",
     *     tags={"SignApis/Templates"},
     *     @OA\Response(response=200, description="Listado de plantillas obtenido exitosamente")
     * )
     */
    public function listTemplates()
    {
        try {
            $data = $this->signapis->listTemplates();
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

    /**
     * @OA\Get(
     *     path="/signapis/templates/{code}/{type}",
     *     summary="Obtener informaci贸n de una plantilla espec铆fica",
     *     tags={"SignApis/Templates"},
     *     @OA\Parameter(
     *         name="code", in="path", required=true,
     *         description="C贸digo de la plantilla",
     *         @OA\Schema(type="string", example="welcomeTemplate")
     *     ),
     *     @OA\Parameter(
     *         name="type", in="path", required=true,
     *         description="Tipo de plantilla (ejemplo: email)",
     *         @OA\Schema(type="string", example="email")
     *     ),
     *     @OA\Response(response=200, description="Plantilla obtenida exitosamente"),
     *     @OA\Response(response=404, description="Plantilla no encontrada")
     * )
     */
    public function getTemplate($code, $type)
    {
        try {
            $data = $this->signapis->getTemplate($code, $type);
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

    /**
     * @OA\Patch(
     *     path="/signapis/templates/{code}/{type}",
     *     summary="Modificar una plantilla existente",
     *     tags={"SignApis/Templates"},
     *     @OA\Parameter(
     *         name="code", in="path", required=true,
     *         description="C贸digo de la plantilla",
     *         @OA\Schema(type="string", example="welcomeTemplate")
     *     ),
     *     @OA\Parameter(
     *         name="type", in="path", required=true,
     *         description="Tipo de plantilla (ejemplo: email)",
     *         @OA\Schema(type="string", example="email")
     *     ),
     *     @OA\RequestBody(
     *         required=true,
     *         @OA\JsonContent(
     *             @OA\Property(property="name", type="string", example="Welcome Template"),
     *             @OA\Property(property="subject", type="string", example="Bienvenido a nuestra plataforma"),
     *             @OA\Property(property="body", type="string", example="<p>Hola {{name}}, bienvenido!</p>")
     *         )
     *     ),
     *     @OA\Response(response=200, description="Plantilla modificada exitosamente"),
     *     @OA\Response(response=404, description="Plantilla no encontrada")
     * )
     */
    public function updateTemplate(Request $request, $code, $type)
    {
        try {
            $data = $this->signapis->updateTemplate($code, $type, $request->all());
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

    /**
     * @OA\Delete(
     *     path="/signapis/templates/{code}/{type}",
     *     summary="Eliminar una plantilla espec铆fica",
     *     tags={"SignApis/Templates"},
     *     @OA\Parameter(
     *         name="code", in="path", required=true,
     *         description="C贸digo de la plantilla",
     *         @OA\Schema(type="string", example="welcomeTemplate")
     *     ),
     *     @OA\Parameter(
     *         name="type", in="path", required=true,
     *         description="Tipo de plantilla",
     *         @OA\Schema(type="string", example="email")
     *     ),
     *     @OA\Response(response=200, description="Plantilla eliminada exitosamente"),
     *     @OA\Response(response=404, description="Plantilla no encontrada")
     * )
     */
    public function deleteTemplate($code, $type)
    {
        try {
            $data = $this->signapis->deleteTemplate($code, $type);
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

    /**
     * @OA\Delete(
     *     path="/signapis/templates/{code}",
     *     summary="Eliminar todas las plantillas asociadas a un c贸digo",
     *     tags={"SignApis/Templates"},
     *     @OA\Parameter(
     *         name="code", in="path", required=true,
     *         description="C贸digo de las plantillas",
     *         @OA\Schema(type="string", example="welcomeTemplate")
     *     ),
     *     @OA\Response(response=200, description="Plantillas eliminadas exitosamente"),
     *     @OA\Response(response=404, description="No se encontraron plantillas con ese c贸digo")
     * )
     */
    public function deleteTemplatesByCode($code)
    {
        try {
            $data = $this->signapis->deleteTemplatesByCode($code);
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

    /**
     * @OA\Post(
     *     path="/signapis/templates/test",
     *     summary="Enviar un correo de prueba usando una plantilla",
     *     tags={"SignApis/Templates"},
     *     @OA\RequestBody(
     *         required=true,
     *         @OA\JsonContent(
     *             @OA\Property(property="templateCode", type="string", example="welcomeTemplate"),
     *             @OA\Property(property="recipient", type="string", example="user@mail.com"),
     *             @OA\Property(property="variables", type="object", example={"name":"John"})
     *         )
     *     ),
     *     @OA\Response(response=200, description="Correo de prueba enviado exitosamente"),
     *     @OA\Response(response=400, description="Error en la solicitud")
     * )
     */
    public function testTemplate(Request $request)
    {
        try {
            $data = $this->signapis->testTemplate($request->all());
            return response()->json(['data' => $data, 'message' => 'ok', 'code' => 200]);
        } catch (Exception $e) {
            return response()->json(['error' => $e->getMessage()], $e->getCode() ?: 500);
        }
    }

}