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

            Line data    Source code
       1            4 : (ns matchscore.domain.tournament-subscription.query
       2              :   "Per-request loaders for the calendar's tier and subscription fields: one
       3              :   query per source, never one per tournament."
       4              :   (:require
       5              :    [matchscore.domain.tournament-subscription.repository :as repository]
       6              :    [next.jdbc :as jdbc]
       7              :    [next.jdbc.result-set :as rs]))
       8              : 
       9              : 
      10           16 : (def ^:private options {:builder-fn rs/as-unqualified-kebab-maps})
      11              : 
      12              : 
      13            4 : (defn tiers-by-tournament
      14              :  "{tournament-key -> {:source :code :label :tournament-count}} for the source.
      15              :   The label follows `language` (\"uk\" or anything else for English)."
      16              :  [repo ds source language]
      17            9 :  (let [tiers (into
      18            3 :               {}
      19            6 :               (map
      20            3 :                (fn [tier]
      21           12 :                 [(:code tier)
      22           18 :                  {:source source
      23            9 :                   :code   (:code tier)
      24           12 :                   :label  (if (= "uk" language)
      25            7 :                             (or (:label-uk tier) (:label-en tier))
      26            9 :                             (:label-en tier))
      27           21 :                   :tournament-count (or (:tournament-count tier) 0)}]))
      28           12 :               (repository/list-tiers repo source))
      29            6 :        rows  (jdbc/execute!
      30            3 :               ds
      31            9 :               ["SELECT tournament_key, tier FROM imported_tournaments WHERE source = ?" source]
      32            3 :               options)]
      33            6 :    (into
      34            3 :     {}
      35            6 :     (keep
      36            3 :      (fn [{:keys [tournament-key tier]}]
      37           30 :       (when-let [t (get tiers tier)] [tournament-key t])))
      38            3 :     rows)))
      39              : 
      40              : 
      41            4 : (defn tournament-subscriptions
      42              :  "{tournament-key -> subscription row} for the user's target = tournament rows."
      43              :  [repo user-id source]
      44            2 :  (into
      45            1 :   {}
      46            2 :   (comp
      47           17 :    (filter #(and (= source (:source %)) (= "tournament" (:target %))))
      48            6 :    (map (juxt :target-key identity)))
      49            4 :   (repository/list-subscriptions repo user-id)))
        

Generated by: LCOV version 2.0-1