From 882b443d2ee90271e7f8e755f790b44978aba236 Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Thu, 19 Mar 2026 14:33:38 -0500 Subject: [PATCH] day 2, lexicon changes --- shared/challenges_markdown/two/part_two.md | 15 ++++-- shared/lexicons/codes/advent/day.json | 3 -- shared/src/advent/challenges/day_two.rs | 8 +-- .../lexicons/codes/advent/challenge/day.rs | 3 +- shared/src/lexicons/lib.rs | 3 ++ web/src/main.rs | 49 ++++++++++++++++++- 6 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 shared/src/lexicons/lib.rs diff --git a/shared/challenges_markdown/two/part_two.md b/shared/challenges_markdown/two/part_two.md index f54b35d..619cec7 100644 --- a/shared/challenges_markdown/two/part_two.md +++ b/shared/challenges_markdown/two/part_two.md @@ -8,10 +8,17 @@ can use 3 methods for this: - [com.atproto.repo.applyWrites](https://docs.bsky.app/docs/api/com-atproto-repo-apply-writes) Batch endpoint for writes that allows you to create, update, or delete multiple records. -Great job beating Part 1! Now onto Part 2. +Like the previous record you found at `{{at_uri}}`, you will write your own `codes.advent.challenge.day` record in your +own repository at the record key `2` and set the property `partTwo` to `{{code}}`. -Keeping it simple proof of concept, blah, blah will have a real one here another time. Add a new field `partTwo` to the -record with the value `{{code}}` +The contents of the record would look about like this: +```json +{ + "$type": "codes.advent.challenge.day", + "partTwo": "" +} +``` + +Once you have written the record to your own repository, please click "Check answer" below to see if you got it right. -[//]: # () \ No newline at end of file diff --git a/shared/lexicons/codes/advent/day.json b/shared/lexicons/codes/advent/day.json index f59d4a7..b9fc8ca 100644 --- a/shared/lexicons/codes/advent/day.json +++ b/shared/lexicons/codes/advent/day.json @@ -7,9 +7,6 @@ "key": "any", "record": { "type": "object", - "required": [ - "partOne" - ], "properties": { "partOne": { "type": "string" diff --git a/shared/src/advent/challenges/day_two.rs b/shared/src/advent/challenges/day_two.rs index 06ddae9..4a25284 100644 --- a/shared/src/advent/challenges/day_two.rs +++ b/shared/src/advent/challenges/day_two.rs @@ -33,10 +33,6 @@ impl AdventChallenge for DayTwo { true } - fn requires_manual_verification_part_two(&self) -> bool { - true - } - /// Create a record via the challenge agent and return the at_uri as additional context async fn build_additional_context( &self, @@ -58,7 +54,7 @@ impl AdventChallenge for DayTwo { })?; let record_data = advent::challenge::day::RecordData { - part_one: code.to_string(), + part_one: Some(code.to_string()), part_two: None, created_at: None, }; @@ -192,7 +188,7 @@ impl AdventChallenge for DayTwo { false => { Ok(ChallengeCheckResponse::Incorrect(format!( "The code {} is incorrect", - record_data.part_one + record_data.part_one.unwrap_or("".to_string()) ))) } } diff --git a/shared/src/lexicons/codes/advent/challenge/day.rs b/shared/src/lexicons/codes/advent/challenge/day.rs index 99482c2..f919613 100644 --- a/shared/src/lexicons/codes/advent/challenge/day.rs +++ b/shared/src/lexicons/codes/advent/challenge/day.rs @@ -6,7 +6,8 @@ use atrium_api::types::TryFromUnknown; pub struct RecordData { #[serde(skip_serializing_if = "core::option::Option::is_none")] pub created_at: core::option::Option, - pub part_one: String, + #[serde(skip_serializing_if = "core::option::Option::is_none")] + pub part_one: core::option::Option, #[serde(skip_serializing_if = "core::option::Option::is_none")] pub part_two: core::option::Option, } diff --git a/shared/src/lexicons/lib.rs b/shared/src/lexicons/lib.rs new file mode 100644 index 0000000..53ad200 --- /dev/null +++ b/shared/src/lexicons/lib.rs @@ -0,0 +1,3 @@ +// @generated - This file is generated by esquema-codegen (forked from atrium-codegen). DO NOT EDIT. +pub mod record; +pub mod codes; diff --git a/web/src/main.rs b/web/src/main.rs index 5c515f8..5ecc207 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -294,7 +294,7 @@ async fn main() -> Result<(), Box> { Ok(()) } -/// Landing page showing currently unlocked days and a login button +/// The default handler that will be used during the advent month, but not during amtosphere conf async fn home_handler(State(pool): State, session: AxumSessionStore) -> impl IntoResponse { //TODO make a helper function for this since it is similar to the middleware let now = chrono::Utc::now(); @@ -337,3 +337,50 @@ async fn home_handler(State(pool): State, session: AxumSessionStore) -> is_logged_in, }) } + +/// The default handler that will be used during the advent month, but not during amtosphere conf +async fn dec_home_handler( + State(pool): State, + session: AxumSessionStore, +) -> impl IntoResponse { + //TODO make a helper function for this since it is similar to the middleware + let now = chrono::Utc::now(); + let mut unlocked: Vec = Vec::new(); + + //HACK Yeah I don't like it either - bt + let prod: bool = env::var("PROD") + .map(|val| val == "true") + .unwrap_or_else(|_| true); + if prod { + if now.month() == 12 { + let today = now.day().min(25); + for d in 1..=today { + unlocked.push(d as u8); + } + } + } else { + for d in 1..=25 { + unlocked.push(d as u8); + } + } + + // Get completion status for all days at once + let did = session.get_did(); + let is_logged_in = session.logged_in(); + let all_statuses = get_all_days_completion_status(&pool, did.as_ref()) + .await + .unwrap_or_else(|_| (1..=25).map(|day| (day, CompletionStatus::None)).collect()); + + // Filter to only include unlocked days + let unlocked_with_status: Vec = all_statuses + .into_iter() + .filter(|(day, _)| unlocked.contains(day)) + .map(|(day, status)| DayStatus { day, status }) + .collect(); + + HtmlTemplate(HomeTemplate { + title: "at://advent", + unlocked_days: unlocked_with_status, + is_logged_in, + }) +} -- 2.51.2