LCOV - code coverage report
Current view: top level - matchscore/domain/event - query.clj Coverage Total Hit
Test: lcov.info Lines: 97.7 % 43 42
Test Date: 2026-11-23 18:11:10 Functions: - 0 0

            Line data    Source code
       1            4 : (ns matchscore.domain.event.query
       2              :   (:require
       3              :    [cats.monad.either :as either]
       4              :    [matchscore.domain.event.repository.postgres :as event-postgres-repo]))
       5              : 
       6              : 
       7            4 : (defn get-event
       8              :  "Retrieves an event by ID. Returns Event map or nil."
       9              :  [repo id ctx]
      10           20 :  (event-postgres-repo/find-by-id repo id ctx))
      11              : 
      12              : 
      13            4 : (defn get-event-by-public-id
      14              :  "Retrieves an event by public_id. Returns Event map or nil."
      15              :  [repo public-id ctx]
      16           20 :  (event-postgres-repo/find-by-public-id repo public-id ctx))
      17              : 
      18              : 
      19            4 : (defn get-events-by-template-id
      20              :  "Retrieves events by event template ID. Returns a vector of Event maps."
      21              :  [repo template-id ctx]
      22            5 :  (event-postgres-repo/find-by-template-id repo template-id ctx))
      23              : 
      24              : 
      25            4 : (defn get-events-by-creator-id
      26              :  "Retrieves events by creator ID. Returns a vector of Event maps."
      27              :  [repo creator-id ctx]
      28            0 :  (event-postgres-repo/find-by-creator-id repo creator-id ctx))
      29              : 
      30              : 
      31            4 : (defn get-events-by-ids
      32              :  "Retrieves events for multiple UUIDs in one batch. Returns a vector of Event maps."
      33              :  [repo ids]
      34            4 :  (event-postgres-repo/find-by-ids repo ids))
      35              : 
      36              : 
      37            4 : (defn get-events-by-stage-ids
      38              :  "Retrieves the owning event for each stage UUID (via stages -> event_classes -> events).
      39              :    Returns a seq of {:stage-id \"uuid\" :event {..}}."
      40              :  [repo stage-ids]
      41            4 :  (event-postgres-repo/find-by-stage-ids repo stage-ids))
      42              : 
      43              : 
      44            4 : (defn search-events
      45              :  "Search events by filters and pagination. Returns Either<Error, Result>."
      46              :  [repo filters pagination]
      47           14 :  (either/right (event-postgres-repo/search repo filters pagination)))
      48              : 
      49              : 
      50            4 : (defn search-public-events
      51              :  "Search discoverable events for the bot home feed. Visibility is always forced to public."
      52            5 :  ([repo pagination] (search-public-events repo {} pagination))
      53              :  ([repo filters pagination]
      54            4 :   (either/right
      55            4 :    (event-postgres-repo/search
      56            2 :     repo
      57           22 :     (assoc (or filters {}) :visibility {:eq "public"})
      58            2 :     pagination))))
      59              : 
      60              : 
      61            4 : (defn search-user-events
      62              :  "Search the authenticated user's events by filters and pagination.
      63              :    Forces a `createdBy = user-id` filter on top of the supplied filters. With
      64              :    `include-admin-role?`, events where the user holds the admin participant role match too.
      65              :    Returns Either<Error, Result>."
      66            7 :  ([repo user-id filters pagination] (search-user-events repo user-id filters pagination false))
      67              :  ([repo user-id filters pagination include-admin-role?]
      68           18 :   (let [filters     (or filters {})
      69            9 :         user-filter {:eq user-id}]
      70            6 :     (either/right
      71            6 :      (event-postgres-repo/search
      72            3 :       repo
      73           18 :       (cond (:hosted-user-id filters) filters
      74           30 :             (and include-admin-role? (seq user-id)) (assoc filters :managing-user-id user-id)
      75              :             :else
      76           10 :             (assoc filters
      77            2 :              :createdBy  user-filter
      78            2 :              :created-by user-filter))
      79            3 :       pagination)))))
      80              : 
      81              : 
      82            4 : (defn search-user-participating-events
      83              :  "Search events where the authenticated user participates as a player.
      84              :    Forces participation through event_participants -> participants.user_id and requires
      85              :    the player role.
      86              :    Returns Either<Error, Result>."
      87              :  [repo user-id filters pagination]
      88            8 :  (if (seq user-id)
      89            4 :    (either/right
      90            4 :     (event-postgres-repo/search
      91            2 :      repo
      92           18 :      (assoc (or filters {}) :participating-user-id user-id)
      93            2 :      pagination))
      94            5 :    (either/left {:message "Authentication required."})))
        

Generated by: LCOV version 2.0-1