Skip to content

feat(activity): S4 — Action ReactWith + DTO (#543) - #561

Merged
hefeus merged 2 commits into
feat/timeline-reactionfrom
feat/543-react-with-action
Sep 15, 2026
Merged

hefeus merged 2 commits into
feat/timeline-reactionfrom
feat/543-react-with-action

Conversation

@hefeus

@hefeus hefeus commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Contexto

Fatia S4 do subsistema de reações da timeline web (#539). A S3 (#542) entregou o model UserReaction + factory + relação em Timeline; esta fatia encapsula a regra de negócio de reagir num único ponto de domínio testável, espelhando o padrão de Timeline/Actions/CreatePost.

Sem essa Action, criar/trocar/remover uma reação ficaria espalhado em quem chama (Livewire, controller, etc.), com risco de duplicar linha para o mesmo (user_id, timeline_id) ou deixar a mutação fora de uma transação.

Alterações

  • DTO Reaction/DTOs/ReactWithDTO.phpreadonly, userId, timelineId, reaction: TimelineReaction
  • Action Reaction/Actions/ReactWith.phphandle() dentro de DB::transaction, com os 3 caminhos:
    • sem reação prévia → cria e retorna a reação
    • mesma reação → remove (toggle-off) e retorna null
    • reação diferente → atualiza a linha existente e retorna a nova
  • Testes unitários (ReactWithTest.php): os 4 cenários do BDD da issue + isolamento entre usuários no mesmo timeline + isolamento entre timelines do mesmo usuário + garantia de que a troca de reação faz UPDATE na mesma linha (não delete+insert)

Plano de Testes

  • Executar make check (ou composer check)
  • Executar php vendor/bin/pest --compact app-modules/activity/tests/Unit/Reaction/ReactWithTest.php
  • Confirmar que reagir sem reação prévia cria 1 linha e retorna a reação escolhida
  • Confirmar que reagir de novo com a mesma reação remove a linha e retorna null
  • Confirmar que reagir com uma reação diferente atualiza a linha existente (mesmo id) e retorna a nova
  • Confirmar que nunca existem 2 linhas para o mesmo par (user_id, timeline_id), mesmo entre usuários/timelines diferentes

Issues Relacionadas

Closes #543
Related to #539

Encapsula criar/toggle-off/trocar reação num único ponto de domínio,
espelhando o padrão de Timeline/Actions/CreatePost.
GabrielFVDev
GabrielFVDev previously approved these changes Sep 14, 2026

@GabrielFVDev GabrielFVDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

BrunaDomingues
BrunaDomingues previously approved these changes Sep 14, 2026

@BrunaDomingues BrunaDomingues left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread app-modules/activity/src/Reaction/Actions/ReactWith.php Outdated
…#561

Substitui o where()+first()/create() manual por firstOrCreate(), evitando
a race entre o SELECT e o INSERT ao criar a primeira reação — sugestão do
review do Clintonrocha98 na PR.

@GabrielFVDev GabrielFVDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gvieira18 gvieira18 linked an issue Sep 15, 2026 that may be closed by this pull request
7 tasks
@hefeus
hefeus merged commit 9a3145f into feat/timeline-reaction Sep 15, 2026
8 checks passed
@hefeus
hefeus deleted the feat/543-react-with-action branch September 15, 2026 16:16
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.

feat(activity): S4 — Action ReactWith + DTO

5 participants