LCOV - code coverage report
Current view: top level - matchscore/application/event - leave.clj Coverage Total Hit
Test: lcov.info Lines: 100.0 % 16 16
Test Date: 2026-11-23 18:11:10 Functions: - 0 0

            Line data    Source code
       1            4 : (ns matchscore.application.event.leave
       2              :   "Self-service event withdrawal."
       3              :   (:require
       4              :    [cats.monad.either :as either]
       5              :    [matchscore.application.event.remove-participant :as app-event-remove-participant]
       6              :    [matchscore.domain.class-participant.repository.postgres :as class-participant-postgres-repo]
       7              :    [matchscore.domain.event-participant.repository.postgres :as event-participant-postgres-repo]
       8              :    [matchscore.telegram.notifications-trigger :as notifications-trigger]))
       9              : 
      10              : 
      11           12 : (defn- admin-participant? [participant] (boolean (some #{"admin"} (:roles participant))))
      12              : 
      13              : 
      14            4 : (defn execute!
      15              :  "Removes the user's registration from the event and from every class of the event.
      16              :    Admins keep their event participant row -- leaving only drops their player
      17              :    registration, keeping their admin standing intact. Idempotent.
      18              :    Returns Either<Error, nil>."
      19              :  [{:keys [repos]
      20              :    :as   ctx}
      21              :   event-uuid
      22              :   user-uuid]
      23            3 :  (let [existing (event-participant-postgres-repo/find-by-event-id-and-user-id
      24            3 :                  (:event-participant-postgres-repo repos)
      25            1 :                  event-uuid
      26            1 :                  user-uuid)]
      27           10 :    (cond (nil? existing) (either/right nil)
      28              : 
      29            3 :          (admin-participant? existing)
      30            3 :          (let [result (class-participant-postgres-repo/delete-by-participant-and-event!
      31            3 :                        (:class-participant-postgres-repo repos)
      32            3 :                        (:participant-id existing)
      33            1 :                        event-uuid)]
      34            9 :            (when (either/right? result) (notifications-trigger/trigger-debounced! ctx event-uuid))
      35            1 :            result)
      36              : 
      37            7 :          :else (app-event-remove-participant/execute! ctx event-uuid (:participant-id existing)))))
        

Generated by: LCOV version 2.0-1