Skip to content

fix: include source in exercise_snapshot for v2 by-date endpoint#1091

Open
johnpena wants to merge 1 commit intoCodeWithCJ:mainfrom
johnpena:fix/exercise-snapshot-source
Open

fix: include source in exercise_snapshot for v2 by-date endpoint#1091
johnpena wants to merge 1 commit intoCodeWithCJ:mainfrom
johnpena:fix/exercise-snapshot-source

Conversation

@johnpena
Copy link
Copy Markdown

@johnpena johnpena commented Apr 7, 2026

Summary

  • The v2 _buildExerciseEntryWithSnapshot function omits source from the exercise_snapshot object
  • The frontend checks exercise_snapshot.source to decide whether to prepend /uploads/exercises/ to image paths
  • Without source in the snapshot, it's undefined (falsy), so the frontend uses raw image filenames as URLs, resulting in 404s for all exercise images in the diary view

Test plan

  • Navigate to the diary page with exercise entries that have images from FreeExerciseDB
  • Verify exercise images load correctly (no broken image icons)
  • Verify the image URLs include the /uploads/exercises/ prefix

The v2 _buildExerciseEntryWithSnapshot function omitted `source` from
the exercise_snapshot object. The frontend checks
exercise_snapshot.source to determine whether to prepend
/uploads/exercises/ to image paths. Without it, source was undefined
(falsy), causing the frontend to use raw image filenames as URLs,
resulting in 404s for all exercise images in the diary view.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the exercise entry history service to include the source field in the exercise snapshot. The review feedback suggests also including source_id and calories_per_hour to maintain parity with the legacy API and ensure compliance with the defined response schema.

Comment on lines 116 to 120
id: entryData.exercise_id as string,
name: exercise_name as string,
category: (category as string) ?? null,
source: (source as string) ?? null,
images: _parseJsonArray(images),
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.

medium

While adding source fixes the reported image loading issue, the exercise_snapshot is still missing source_id and calories_per_hour. These fields were present in the legacy implementation and are defined in the exerciseSnapshotResponseSchema. Including them ensures full parity with the legacy API and prevents potential regressions in the frontend.

Suggested change
id: entryData.exercise_id as string,
name: exercise_name as string,
category: (category as string) ?? null,
source: (source as string) ?? null,
images: _parseJsonArray(images),
id: entryData.exercise_id as string,
name: exercise_name as string,
category: (category as string) ?? null,
source: (source as string) ?? null,
source_id: (entryData.source_id as string) ?? null,
calories_per_hour: (entryData.calories_per_hour as number) ?? null,
images: _parseJsonArray(images),

@apedley
Copy link
Copy Markdown
Contributor

apedley commented Apr 7, 2026

5 lines above, source_id is already sent so I don't know if sending the data twice is the right fix. I don't see where the frontend would expect it in the snapshot object. I only see it referenced like:

exerciseEntry.source
	? `/uploads/exercises/${snapshot.images[0]}`
	: snapshot.images[0]

Are you seeing image 404s? Where?

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.

2 participants