commit 5d1c5a978a2a638cb40796798d8053d9a3ea934e
parent 7b5699384059ded1d87419a226c3ab577988bc30
Author: Silas Brack <silasbrack@gmail.com>
Date: Wed, 10 Jun 2026 22:49:17 +0200
refactor: use enum for story fragment query parameter
Type-safe deserialization instead of matching on raw strings.
Invalid fragment values now return 400 instead of silently
falling through to the full page.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/handlers/story.rs b/src/handlers/story.rs
@@ -69,8 +69,14 @@ async fn fetch_enriched_comments(
}
#[derive(Debug, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum StoryFragment {
+ Comments,
+}
+
+#[derive(Debug, Deserialize)]
pub struct StoryQuery {
- pub fragment: Option<String>,
+ pub fragment: Option<StoryFragment>,
}
pub async fn show_story(
@@ -86,7 +92,7 @@ pub async fn show_story(
};
// Return just the comments fragment if requested
- if query.fragment.as_deref() == Some("comments") {
+ if matches!(query.fragment, Some(StoryFragment::Comments)) {
let enriched_comments = fetch_enriched_comments(&state, &tokens, &client, id).await?;
let is_logged_in = tokens.is_some();
let template = CommentsTemplate {