Skip to content

Add Kir-Pay integration#1045

Open
Isti01 wants to merge 2 commits into
stagingfrom
integration
Open

Add Kir-Pay integration#1045
Isti01 wants to merge 2 commits into
stagingfrom
integration

Conversation

@Isti01

@Isti01 Isti01 commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added Kir-Pay leaderboard with a new frontend route and an API-backed leaderboard view.
    • Added Kir-Pay settings for enabling the leaderboard and showing Kir-Pay balance on the profile.
    • Frontend configuration now loads from runtime browser settings (window.config) for easier deployment updates.
  • Bug Fixes
    • Standardized riddle request endpoints to a single, consistent URL format.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a KirPay backend component with leaderboard and balance access, a matching frontend leaderboard page and profile balance display, and a runtime config migration from Vite env vars to window.config with container-time substitution. It also removes the NEW_RIDDLE_ENDPOINTS feature flag and related conditional endpoint logic.

Changes

KirPay Component (Backend + Frontend)

Layer / File(s) Summary
KirPay models and component config
backend/.../kirpay/KirPayLeaderboardView.kt, backend/.../kirpay/KirPayComponent.kt, backend/.../config/application*.properties, helm/cmsch/...
Defines the KirPay leaderboard DTOs, component wiring, three Kir-Pay settings groups, and the backend load toggles in application and Helm config.
KirPayService fetch and cache flow
backend/.../kirpay/KirPayService.kt
Builds the KirPay WebClient, refreshes and serves the cached leaderboard, fetches balances by email, and parses remote leaderboard responses.
KirPay leaderboard endpoint
backend/.../kirpay/KirPayApiController.kt
Exposes GET /api/kirpay-leaderboard with authentication checks, feature gating, and entry truncation.
Profile balance wiring
backend/.../profile/ProfileComponent.kt, backend/.../profile/ProfileService.kt, backend/.../profile/ProfileView.kt
Adds the Kir-Pay profile setting group, extends profile data with kirPayBalance, and conditionally fetches balance through KirPayService.
KirPay frontend route, query, and views
frontend/src/api/contexts/config/types.ts, frontend/src/util/views/kirPayLeaderboard.view.ts, frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts, frontend/src/api/hooks/queryKeys.ts, frontend/src/util/paths.ts, frontend/src/App.tsx, frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx, frontend/src/util/views/profile.view.ts, frontend/src/pages/profile/profile.page.tsx
Adds KirPay frontend config types, route constants, query hook, leaderboard page, and profile balance rendering.

Frontend Runtime Config Migration

Layer / File(s) Summary
WindowConfig and environment source migration
frontend/src/global.d.ts, frontend/src/vite-env.d.ts, frontend/tsconfig.app.json, frontend/src/util/configs/environment.config.ts, frontend/package.json
Defines the runtime window config type, removes Vite ambient env typings, rewires exported config constants to read from window.config, and updates the package manager metadata.
Container entrypoint and HTML placeholder substitution
frontend/entrypoint.sh, frontend/index.html, frontend/Dockerfile, frontend/.env.docker
Adds the shell entrypoint, updates the HTML runtime config script, and changes the frontend image build and startup to use runtime placeholder replacement.
Remove NEW_RIDDLE_ENDPOINTS usage
frontend/.env.example, frontend/src/api/hooks/riddle/...
Removes the riddle endpoint feature flag from the example env file and simplifies all riddle hooks to fixed endpoint paths.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • albi005
  • SzBeni2003

Poem

🐇 A KirPay hop through backend light,
and profile balances now show right.
Window configs dance at startup time,
while riddle flags fade out of rhyme.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding Kir-Pay integration across backend, frontend, and deployment config.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch integration

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
frontend/src/pages/profile/profile.page.tsx

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.21][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

frontend/src/util/views/profile.view.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.17][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

frontend/src/util/paths.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.30][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

  • 2 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 11

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt`:
- Around line 61-63: The warning in KirPayService.fetchBalance currently logs
the raw email address on failure, which leaks PII. Update the catch block in
KirPayService so the log message no longer includes email; if correlation is
needed, use a non-PII internal identifier or a sanitized token instead. Keep the
existing failure handling behavior unchanged and adjust the log call around
log.warn accordingly.
- Around line 21-45: The cache in KirPayService currently treats an empty list
as both “not loaded” and “loaded but empty,” so getConsumptionLeaderboard keeps
refetching forever and can stampede the backend. Change cachedLeaderboard
handling in KirPayService to distinguish cache state from cached content, such
as by using a nullable/initialized flag or a separate loaded marker, and update
both refreshCache and getConsumptionLeaderboard to serve a legitimately empty
result without retrying on every call. Keep the existing scheduler flow, but
ensure only one cold-load path populates the cache before subsequent reads reuse
it.
- Around line 23-30: The KirPay client built in KirPayService’s kirPayClient is
currently used with blocking calls in the service methods, so a stalled upstream
can hang the caller indefinitely. Add an explicit timeout either on the
WebClient connector/read side when building kirPayClient or by applying timeout
handling to the Monos in the KirPayService methods that call block(), and make
sure the existing request paths in the service use the timed client or timed
reactive pipeline consistently.

In
`@backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt`:
- Around line 148-152: The new profile-level showKirPayBalance setting in
ProfileComponent is duplicating an existing Kir-Pay feature toggle, so the
balance visibility is now controlled by two independent switches. Remove the
extra gate in ProfileService and rely on the existing
kirPayComponent.showKirPayBalance path used by KirPayService, or otherwise wire
both places to the same underlying setting so there is a single source of truth
for balance visibility. Refer to ProfileComponent, ProfileService, and
KirPayService when making the change.

In `@frontend/entrypoint.sh`:
- Around line 6-8: The placeholder substitution loop in entrypoint.sh uses a
bash-only indirect expansion and can break under /bin/sh, so update the VITE_
variable iteration and replacement logic to be POSIX-sh compatible. In the
section that builds placeholder and runs sed, fetch each variable’s value
without bashism and escape any special replacement characters such as &, \, and
| before substitution so HTML replacement works reliably for all env values.

In `@frontend/index.html`:
- Line 34: The inline error reporter is using the raw window.config.API_BASE_URL
instead of the same localhost fallback used by environment.config.ts, so missing
runtime tokens can break reporting only. Update the inline fetch setup in
index.html to resolve the API base through the same fallback logic as the app
(with the localhost:8080 default) and ensure any error-reporting request path
uses that resolved base consistently.

In `@frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts`:
- Around line 1-5: The import order in useKirPayLeaderboardQuery is causing the
lint failure; move joinPath so it is grouped with the other internal imports
before the third-party imports like useQuery and axios. Keep the existing
imports otherwise unchanged, and ensure the file follows the project’s import
sorting convention.

In `@frontend/src/App.tsx`:
- Line 28: The new KirPayLeaderboardPage import in App should be moved into the
existing sorted group of page imports so the linter order matches CI
expectations. Update the import block in App.tsx around KirPayLeaderboardPage
and the surrounding page imports to keep the list alphabetically/consistently
ordered with the project’s import sorting rules.

In `@frontend/src/global.d.ts`:
- Around line 18-23: The Window augmentation in global.d.ts is currently inside
a top-level declare global block in a non-module declaration file, which
TypeScript rejects. Make the file an external module by adding an empty export,
or move the Window interface augmentation to top level, so the declarations
merge correctly while keeping the WindowConfig and processAndReportError symbols
intact.

In `@frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx`:
- Around line 34-39: The row key in the kirpay leaderboard table is unstable
because TableRow uses entry.name, which is display text and may collide across
entries. Update the mapping in kirpay-leaderboard.page.tsx to use a stable
unique identifier from each entry if one is available from the backend; if not,
adjust the data shape or rendering logic so TableRow keys are derived from a
guaranteed-unique field instead of name.
- Around line 9-12: The KirPay leaderboard fetch is happening even when KirPay
is unavailable because `useKirPayLeaderboardQuery()` is called before the
`!component` guard in `KirPayLeaderboardPage`. Move the query invocation so it
only runs after confirming `component` exists, or otherwise conditionally
disable the query based on the config check, and keep `ComponentUnavailable` as
the early return for the unavailable case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: efa99f1a-3304-4bd9-8286-4400beb0c9f0

📥 Commits

Reviewing files that changed from the base of the PR and between f4b0b49 and 1ae6c87.

📒 Files selected for processing (37)
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileService.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileView.kt
  • backend/src/main/resources/config/application-env.properties
  • backend/src/main/resources/config/application.properties
  • frontend/.env.docker
  • frontend/.env.example
  • frontend/Dockerfile
  • frontend/entrypoint.sh
  • frontend/index.html
  • frontend/package.json
  • frontend/plan
  • frontend/src/App.tsx
  • frontend/src/api/contexts/config/types.ts
  • frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts
  • frontend/src/api/hooks/queryKeys.ts
  • frontend/src/api/hooks/riddle/useRiddleDeatilsQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHintQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHistoryQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleListQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleSkipMutation.ts
  • frontend/src/api/hooks/riddle/useRiddleSubmitMutation.ts
  • frontend/src/global.d.ts
  • frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx
  • frontend/src/pages/profile/profile.page.tsx
  • frontend/src/util/configs/environment.config.ts
  • frontend/src/util/paths.ts
  • frontend/src/util/views/kirPayLeaderboard.view.ts
  • frontend/src/util/views/profile.view.ts
  • frontend/src/vite-env.d.ts
  • frontend/tsconfig.app.json
  • helm/cmsch/templates/cmsch-config.yml
  • helm/cmsch/values.yaml
💤 Files with no reviewable changes (3)
  • frontend/tsconfig.app.json
  • frontend/src/vite-env.d.ts
  • frontend/.env.example

Comment thread backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt Outdated
Comment on lines +148 to +152
val kirPayGroup by SettingGroup(fieldName = "Kir-Pay",
description = "A Kir-Pay komponensnek is be kell kapcsolva lennie, hogy az itteni beállítások működjenek")

var showKirPayBalance by BooleanSettingRef(true,
fieldName = "Kir-Pay egyenleg látható", description = "Megjelenjen-e a Kir-Pay egyenleg a profilban")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

This creates a second independent showKirPayBalance switch.

ProfileService now gates the field on profileComponent.showKirPayBalance, but backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt, Lines 47-49 already gate the upstream call on kirPayComponent.showKirPayBalance. Turning on this new profile flag alone still returns no balance, so the feature now has two separate toggles for one behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt`
around lines 148 - 152, The new profile-level showKirPayBalance setting in
ProfileComponent is duplicating an existing Kir-Pay feature toggle, so the
balance visibility is now controlled by two independent switches. Remove the
extra gate in ProfileService and rely on the existing
kirPayComponent.showKirPayBalance path used by KirPayService, or otherwise wire
both places to the same underlying setting so there is a single source of truth
for balance visibility. Refer to ProfileComponent, ProfileService, and
KirPayService when making the change.

Comment thread frontend/entrypoint.sh Outdated
Comment on lines +6 to +8
for var in $(env | grep '^VITE_' | cut -d= -f1); do
placeholder="__${var}__"
sed -i "s|${placeholder}|${!var}|g" "$HTML"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/sh
cat -n frontend/entrypoint.sh | sed -n '1,120p'

Repository: kir-dev/cmsch

Length of output: 444


Fix the placeholder substitution in frontend/entrypoint.sh:6-8

${!var} is a bashism, so this entrypoint fails under /bin/sh before nginx starts. The sed replacement also needs escaping for values containing &, \, or |.

🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 8-8: In POSIX sh, indirect expansion is undefined.

(SC3053)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/entrypoint.sh` around lines 6 - 8, The placeholder substitution loop
in entrypoint.sh uses a bash-only indirect expansion and can break under
/bin/sh, so update the VITE_ variable iteration and replacement logic to be
POSIX-sh compatible. In the section that builds placeholder and runs sed, fetch
each variable’s value without bashism and escape any special replacement
characters such as &, \, and | before substitution so HTML replacement works
reliably for all env values.

Source: Linters/SAST tools

Comment thread frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts Outdated
Comment thread frontend/src/App.tsx
Comment thread frontend/src/global.d.ts
Comment thread frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx
Comment on lines +34 to +39
{data.entries.map((entry, index) => (
<TableRow key={entry.name}>
<TableCell className="font-medium">{index + 1}</TableCell>
<TableCell>{entry.name}</TableCell>
<TableCell className="text-right">{entry.itemCount} db</TableCell>
</TableRow>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the component
sed -n '1,220p' frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx

printf '\n--- SEARCH: kirpay leaderboard types/usages ---\n'
rg -n "kirpay|leaderboard|itemCount|entries" frontend/src -g '!**/node_modules/**'

printf '\n--- SEARCH: backend payload shape / API contract ---\n'
rg -n "itemCount|name" . -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/build/**'

Repository: kir-dev/cmsch

Length of output: 50371


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- frontend/src/util/views/kirPayLeaderboard.view.ts ---'
sed -n '1,120p' frontend/src/util/views/kirPayLeaderboard.view.ts

printf '\n%s\n' '--- frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts ---'
sed -n '1,120p' frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts

printf '\n%s\n' '--- backend / api kirpay-leaderboard references ---'
rg -n "kirpay-leaderboard|KirPayLeaderboard|kirPayLeaderboard|itemCount" . \
  -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/build/**' -g '!**/.git/**' \
  | head -n 80

Repository: kir-dev/cmsch

Length of output: 5064


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt ---'
sed -n '1,120p' backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt

printf '\n%s\n' '--- backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt ---'
sed -n '1,160p' backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt

printf '\n%s\n' '--- backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt ---'
sed -n '1,180p' backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt

Repository: kir-dev/cmsch

Length of output: 5607


Use a stable row key here. entry.name is display text, not a unique identifier; this payload has no stable ID, so duplicate names can collide and make React reuse the wrong row. If the backend can expose an ID, use that instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx` around
lines 34 - 39, The row key in the kirpay leaderboard table is unstable because
TableRow uses entry.name, which is display text and may collide across entries.
Update the mapping in kirpay-leaderboard.page.tsx to use a stable unique
identifier from each entry if one is available from the backend; if not, adjust
the data shape or rendering logic so TableRow keys are derived from a
guaranteed-unique field instead of name.

@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmsch-cst Ready Ready Preview, Comment Jun 28, 2026 9:40pm
cmsch-felezobal Ready Ready Preview, Comment Jun 28, 2026 9:40pm
cmsch-golyakorte Ready Ready Preview, Comment Jun 28, 2026 9:40pm
cmsch-seniortabor Ready Ready Preview, Comment Jun 28, 2026 9:40pm
cmsch-skktv Ready Ready Preview, Comment Jun 28, 2026 9:40pm
cmsch-snyt Ready Ready Preview, Comment Jun 28, 2026 9:40pm
cmsch-vitorlaskupa Ready Ready Preview, Comment Jun 28, 2026 9:40pm

Request Review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt`:
- Around line 33-36: The refreshCache() flow in KirPayService is overwriting
cachedLeaderboard even when fetchConsumptionLeaderboard() fails and returns an
empty fallback, which can evict the last known good snapshot. Change
fetchConsumptionLeaderboard() to return a distinct success/failure result
instead of collapsing errors into emptyList(), and update refreshCache() to
assign cachedLeaderboard only when the fetch succeeds. Keep the existing
cachedLeaderboard value unchanged on failures, and preserve the current logging
in refreshCache() for successful refreshes.

In `@frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts`:
- Around line 7-14: The KirPay leaderboard query hook always runs, which causes
a failing request when KirPay is disabled; update useKirPayLeaderboardQuery to
accept an enabled flag and pass it through to useQuery, then update
KirPayLeaderboardPage to call it with !!component so the request is skipped when
the component gate is off.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1140593b-a048-4fef-803a-d125ad63e7cb

📥 Commits

Reviewing files that changed from the base of the PR and between 1ae6c87 and a238b1e.

📒 Files selected for processing (36)
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileService.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileView.kt
  • backend/src/main/resources/config/application-env.properties
  • backend/src/main/resources/config/application.properties
  • frontend/.env.docker
  • frontend/.env.example
  • frontend/Dockerfile
  • frontend/entrypoint.sh
  • frontend/index.html
  • frontend/package.json
  • frontend/src/App.tsx
  • frontend/src/api/contexts/config/types.ts
  • frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts
  • frontend/src/api/hooks/queryKeys.ts
  • frontend/src/api/hooks/riddle/useRiddleDeatilsQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHintQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHistoryQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleListQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleSkipMutation.ts
  • frontend/src/api/hooks/riddle/useRiddleSubmitMutation.ts
  • frontend/src/global.d.ts
  • frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx
  • frontend/src/pages/profile/profile.page.tsx
  • frontend/src/util/configs/environment.config.ts
  • frontend/src/util/paths.ts
  • frontend/src/util/views/kirPayLeaderboard.view.ts
  • frontend/src/util/views/profile.view.ts
  • frontend/src/vite-env.d.ts
  • frontend/tsconfig.app.json
  • helm/cmsch/templates/cmsch-config.yml
  • helm/cmsch/values.yaml
💤 Files with no reviewable changes (3)
  • frontend/.env.example
  • frontend/tsconfig.app.json
  • frontend/src/vite-env.d.ts
✅ Files skipped from review due to trivial changes (5)
  • helm/cmsch/values.yaml
  • frontend/src/util/views/profile.view.ts
  • frontend/src/util/views/kirPayLeaderboard.view.ts
  • frontend/package.json
  • helm/cmsch/templates/cmsch-config.yml
🚧 Files skipped from review as they are similar to previous changes (23)
  • frontend/src/pages/profile/profile.page.tsx
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt
  • frontend/src/api/hooks/riddle/useRiddleHintQuery.ts
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileView.kt
  • frontend/src/global.d.ts
  • frontend/index.html
  • frontend/src/api/hooks/queryKeys.ts
  • frontend/src/api/hooks/riddle/useRiddleHistoryQuery.ts
  • frontend/src/util/paths.ts
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayComponent.kt
  • frontend/src/api/hooks/riddle/useRiddleListQuery.ts
  • backend/src/main/resources/config/application.properties
  • frontend/src/api/hooks/riddle/useRiddleDeatilsQuery.ts
  • backend/src/main/resources/config/application-env.properties
  • frontend/src/api/hooks/riddle/useRiddleSubmitMutation.ts
  • frontend/Dockerfile
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileService.kt
  • frontend/src/api/contexts/config/types.ts
  • frontend/src/api/hooks/riddle/useRiddleSkipMutation.ts
  • frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx
  • frontend/src/util/configs/environment.config.ts

Comment on lines +33 to +36
fun refreshCache() {
if (!kirPayComponent.leaderboardEnabled) return
cachedLeaderboard = fetchConsumptionLeaderboard()
log.info("Kir-Pay consumption leaderboard cache refreshed, {} entries", cachedLeaderboard.size)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Don't evict the last good leaderboard snapshot on refresh failures.

fetchConsumptionLeaderboard() turns every upstream error into emptyList(), so one failed scheduled refresh replaces a valid cache with “no data” until the next successful run. Return a distinct failure state here and only overwrite cachedLeaderboard when the fetch actually succeeds.

Proposed fix
     fun refreshCache() {
         if (!kirPayComponent.leaderboardEnabled) return
-        cachedLeaderboard = fetchConsumptionLeaderboard()
-        log.info("Kir-Pay consumption leaderboard cache refreshed, {} entries", cachedLeaderboard.size)
+        val refreshed = fetchConsumptionLeaderboard() ?: return
+        cachedLeaderboard = refreshed
+        log.info("Kir-Pay consumption leaderboard cache refreshed, {} entries", refreshed.size)
     }
@@
-    private fun fetchConsumptionLeaderboard(): List<KirPayLeaderboardEntry> {
+    private fun fetchConsumptionLeaderboard(): List<KirPayLeaderboardEntry>? {
         return try {
             val response = kirPayClient.get()
                 .uri("/consumption-leaderboard")
                 .retrieve()
                 .bodyToMono<List<Map<String, Any>>>()
@@
             response.map {
                 KirPayLeaderboardEntry(
                     name = it["name"] as? String ?: "n/a",
                     itemCount = (it["itemCount"] as? Number)?.toLong() ?: 0
                 )
             }
         } catch (e: Exception) {
             log.warn("Failed to fetch Kir-Pay consumption leaderboard: {}", e.message)
-            listOf()
+            null
         }
     }

Also applies to: 67-84

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt`
around lines 33 - 36, The refreshCache() flow in KirPayService is overwriting
cachedLeaderboard even when fetchConsumptionLeaderboard() fails and returns an
empty fallback, which can evict the last known good snapshot. Change
fetchConsumptionLeaderboard() to return a distinct success/failure result
instead of collapsing errors into emptyList(), and update refreshCache() to
assign cachedLeaderboard only when the fetch succeeds. Keep the existing
cachedLeaderboard value unchanged on failures, and preserve the current logging
in refreshCache() for successful refreshes.

Comment thread frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/Dockerfile`:
- Around line 27-34: The frontend startup path in entrypoint.sh only substitutes
VITE_* placeholders when matching env vars exist, so missing values remain
unresolved and break the fallback handling in environment.config.ts. Update the
entrypoint logic referenced by the Dockerfile ENTRYPOINT to also clear or
default any absent __VITE_*__ tokens before Nginx serves index.html, ensuring
placeholders like PASS_SERVER_URL become undefined and
APP_CONFIG_CACHE_TTL_SECONDS does not parse as NaN when unset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ad193f87-d516-40c2-a1bb-093589d02512

📥 Commits

Reviewing files that changed from the base of the PR and between a238b1e and 1bc76bf.

📒 Files selected for processing (36)
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayService.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileService.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileView.kt
  • backend/src/main/resources/config/application-env.properties
  • backend/src/main/resources/config/application.properties
  • frontend/.env.docker
  • frontend/.env.example
  • frontend/Dockerfile
  • frontend/entrypoint.sh
  • frontend/index.html
  • frontend/package.json
  • frontend/src/App.tsx
  • frontend/src/api/contexts/config/types.ts
  • frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts
  • frontend/src/api/hooks/queryKeys.ts
  • frontend/src/api/hooks/riddle/useRiddleDeatilsQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHintQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHistoryQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleListQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleSkipMutation.ts
  • frontend/src/api/hooks/riddle/useRiddleSubmitMutation.ts
  • frontend/src/global.d.ts
  • frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx
  • frontend/src/pages/profile/profile.page.tsx
  • frontend/src/util/configs/environment.config.ts
  • frontend/src/util/paths.ts
  • frontend/src/util/views/kirPayLeaderboard.view.ts
  • frontend/src/util/views/profile.view.ts
  • frontend/src/vite-env.d.ts
  • frontend/tsconfig.app.json
  • helm/cmsch/templates/cmsch-config.yml
  • helm/cmsch/values.yaml
💤 Files with no reviewable changes (3)
  • frontend/tsconfig.app.json
  • frontend/.env.example
  • frontend/src/vite-env.d.ts
✅ Files skipped from review due to trivial changes (3)
  • backend/src/main/resources/config/application-env.properties
  • frontend/src/util/views/kirPayLeaderboard.view.ts
  • frontend/package.json
🚧 Files skipped from review as they are similar to previous changes (23)
  • helm/cmsch/templates/cmsch-config.yml
  • frontend/src/App.tsx
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayLeaderboardView.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/kirpay/KirPayApiController.kt
  • frontend/src/api/hooks/queryKeys.ts
  • frontend/src/pages/profile/profile.page.tsx
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileComponent.kt
  • frontend/index.html
  • frontend/src/api/hooks/riddle/useRiddleDeatilsQuery.ts
  • frontend/entrypoint.sh
  • frontend/src/pages/kirpay-leaderboard/kirpay-leaderboard.page.tsx
  • frontend/src/api/hooks/riddle/useRiddleSkipMutation.ts
  • frontend/src/api/hooks/kirpay/useKirPayLeaderboardQuery.ts
  • frontend/src/util/paths.ts
  • helm/cmsch/values.yaml
  • backend/src/main/resources/config/application.properties
  • frontend/src/global.d.ts
  • frontend/src/api/hooks/riddle/useRiddleHintQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleHistoryQuery.ts
  • frontend/src/api/hooks/riddle/useRiddleSubmitMutation.ts
  • frontend/src/api/hooks/riddle/useRiddleListQuery.ts
  • frontend/src/util/configs/environment.config.ts
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/profile/ProfileService.kt

Comment thread frontend/Dockerfile
Comment on lines +27 to +34
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Expose the desired port (default is 80 for Nginx)
EXPOSE 80

# Set the command to start the Nginx server
CMD ["nginx", "-g", "daemon off;"]
# Set the entrypoint to inject runtime env vars then start Nginx
ENTRYPOINT ["/entrypoint.sh"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle unset VITE_* vars before serving index.html.

Wiring /entrypoint.sh as the startup path makes the image serve unresolved __VITE_*__ tokens whenever a runtime variable is omitted, because the script only replaces variables that are present in env. That breaks the new frontend fallback logic: for example, PASS_SERVER_URL stays a truthy placeholder instead of becoming undefined, and APP_CONFIG_CACHE_TTL_SECONDS parses to NaN in frontend/src/util/configs/environment.config.ts:1-13. The entrypoint should also clear or default missing placeholders, not just substitute the vars that exist.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/Dockerfile` around lines 27 - 34, The frontend startup path in
entrypoint.sh only substitutes VITE_* placeholders when matching env vars exist,
so missing values remain unresolved and break the fallback handling in
environment.config.ts. Update the entrypoint logic referenced by the Dockerfile
ENTRYPOINT to also clear or default any absent __VITE_*__ tokens before Nginx
serves index.html, ensuring placeholders like PASS_SERVER_URL become undefined
and APP_CONFIG_CACHE_TTL_SECONDS does not parse as NaN when unset.

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