Skip to content

Notificar en Discord cuando se publica un vídeo - #407

Open
lapencadev wants to merge 3 commits into
CodelyTV:mainfrom
lapencadev:feat/notify-video-published
Open

lapencadev wants to merge 3 commits into
CodelyTV:mainfrom
lapencadev:feat/notify-video-published

Conversation

@lapencadev

Copy link
Copy Markdown

Mi implementación del ejercicio: cuando se crea un vídeo, se manda un mensaje a un canal de Discord por webhook.

Cómo está montado:

  • Dominio: VideoPublishedNotifier, la interfaz (el puerto).
  • Aplicación: NotifyOnVideoCreated escucha VideoCreatedDomainEvent y llama al caso de uso VideoPublishedNotificator.
  • Infraestructura: DiscordVideoPublishedNotifier, que hace el POST al webhook con el HttpClient de Symfony.

Para poder probarlo de verdad he tenido que añadir algunas cosas que faltaban:

  • Un endpoint PUT /videos/{id}, porque no había forma de crear vídeos desde fuera.
  • La tabla videos y un par de mapeos de Doctrine, porque los vídeos no se podían guardar.
  • Unos arreglos del entorno (xdebug, --allow-all-ip en symfony serve y el README), porque con lo que hay ahora el proyecto no levanta. Van en un commit aparte y también en Arreglar el entorno local para que el proyecto vuelva a levantar #406 por si os sirven por separado.

Para probarlo:

  1. Poner DISCORD_WEBHOOK_URL en .env.test.local (con APP_ENV=test no se lee .env.local).
  2. make start y docker exec codely-php_ddd_skeleton-mooc_backend-php ./apps/mooc/backend/bin/console codely:domain-events:rabbitmq:configure
  3. Crear un vídeo:
    curl -X PUT localhost:8030/videos/<uuid> -H 'Content-Type: application/json' -d '{"type":"screencast","title":"Prueba","url":"https://codely.com","course_id":"1aab45ba-3c7a-4344-8936-78466eca77fa"}'
  4. Consumir el evento:
    docker exec codely-php_ddd_skeleton-mooc_backend-php ./apps/mooc/backend/bin/console codely:domain-events:rabbitmq:consume codelytv.mooc.videos.notify_on_video_created 10

Tests: uno unitario del subscriber con el notifier mockeado, uno del adaptador con MockHttpClient (sin llamar a Discord) y un Behat para el endpoint.

- Bump xdebug to 3.4.2: 3.3.0 no longer compiles on the current php:8.3-fpm-alpine image
- Add --allow-all-ip to symfony serve: Symfony CLI >= 5.10.3 only listens on 127.0.0.1, so the apps were unreachable from the host
- Keep tracked var/.gitkeep files when running make clean-cache
- Update README with the existing Makefile targets (make build / make deps no longer exist)
Videos could not be persisted: the videos table was missing, VideoType
(an enum) was mapped as an embeddable and VideoUrl had no mapping.
NotifyOnVideoCreated listens to VideoCreatedDomainEvent and uses the
VideoPublishedNotifier port, implemented with a Discord webhook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant