diff --git a/src/frontend/src/app/core/tokens/notify-config.token.ts b/src/frontend/src/app/core/tokens/notify-config.token.ts new file mode 100644 index 0000000..4686dad --- /dev/null +++ b/src/frontend/src/app/core/tokens/notify-config.token.ts @@ -0,0 +1,6 @@ +import { InjectionToken } from '@angular/core'; + +export const NOTIFY_WEBHOOK_URL = new InjectionToken('NOTIFY_WEBHOOK_URL', { + providedIn: 'root', + factory: () => 'https://n8n.bryan-bano.com/webhook/portfolio-notify' +}); diff --git a/src/frontend/src/app/infrastructure/adapters/http-guestbook.adapter.ts b/src/frontend/src/app/infrastructure/adapters/http-guestbook.adapter.ts index 91fb2ef..84d4323 100644 --- a/src/frontend/src/app/infrastructure/adapters/http-guestbook.adapter.ts +++ b/src/frontend/src/app/infrastructure/adapters/http-guestbook.adapter.ts @@ -4,6 +4,7 @@ import { Observable, catchError, of, tap } from 'rxjs'; import { GuestbookPort } from '../../domain/ports/guestbook.port'; import { CreateGuestbookRequest, GuestbookEntry } from '../../domain/models/guestbook.model'; import { API_BASE_URL } from '../../core/tokens/api-config.token'; +import { NOTIFY_WEBHOOK_URL } from '../../core/tokens/notify-config.token'; const STORAGE_KEY = 'zen_guestbook_entries_cache'; @@ -37,6 +38,7 @@ const INITIAL_MOCK_ENTRIES: GuestbookEntry[] = [ export class HttpGuestbookAdapter implements GuestbookPort { private readonly http = inject(HttpClient); private readonly baseUrl = inject(API_BASE_URL); + private readonly notifyWebhookUrl = inject(NOTIFY_WEBHOOK_URL); getEntries(limit: number = 50): Observable { return this.http.get(`${this.baseUrl}/guestbook?limit=${limit}`).pipe( @@ -46,6 +48,8 @@ export class HttpGuestbookAdapter implements GuestbookPort { } createEntry(request: CreateGuestbookRequest): Observable { + this.dispatchN8nNotification(request); + return this.http.post(`${this.baseUrl}/guestbook`, request).pipe( tap(created => { const cached = this.loadFromCache(); @@ -67,6 +71,23 @@ export class HttpGuestbookAdapter implements GuestbookPort { ); } + private dispatchN8nNotification(request: CreateGuestbookRequest): void { + try { + this.http.post(this.notifyWebhookUrl, { + eventType: 'GUESTBOOK_SIGNATURE', + senderName: request.senderName, + senderContact: request.senderContact || 'Firma de Visitante Web', + message: request.message, + serviceType: request.origin ?? 'WebForm' + }).subscribe({ + next: () => {}, + error: () => {} + }); + } catch { + // Ignorar fallos de red en notificación + } + } + private loadFromCache(): GuestbookEntry[] { if (typeof localStorage === 'undefined') return INITIAL_MOCK_ENTRIES; const raw = localStorage.getItem(STORAGE_KEY); diff --git a/src/frontend/src/app/presentation/features/api-explorer/api-explorer.component.html b/src/frontend/src/app/presentation/features/api-explorer/api-explorer.component.html index 1adc304..8fb7b67 100644 --- a/src/frontend/src/app/presentation/features/api-explorer/api-explorer.component.html +++ b/src/frontend/src/app/presentation/features/api-explorer/api-explorer.component.html @@ -26,8 +26,12 @@ {{ currentEndpoint().method }}
- api.bryan-bano.com - {{ currentEndpoint().path }} + @if (currentEndpoint().path.startsWith('http')) { + {{ currentEndpoint().path }} + } @else { + api.bryan-bano.com + {{ currentEndpoint().path }} + }