From 30f9cff3cbd3008eba3f33a96612e588876bc90e Mon Sep 17 00:00:00 2001 From: arinbalyan Date: Sat, 27 Jun 2026 23:38:37 +0530 Subject: [PATCH] fix: align Rust Location struct with scrappy's Location format (was expecting string, got object) --- src/scrape.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/scrape.rs b/src/scrape.rs index 0c517fd..1fee82d 100644 --- a/src/scrape.rs +++ b/src/scrape.rs @@ -53,13 +53,29 @@ pub struct Email { pub role: bool, } +#[derive(Debug, Default, Deserialize)] +pub struct Location { + pub city: Option, + pub state: Option, + pub country: Option, +} + +impl Location { + fn display(&self) -> String { + let parts: Vec<&str> = [self.city.as_deref(), self.state.as_deref(), self.country.as_deref()] + .into_iter().flatten().filter(|s| !s.is_empty()).collect(); + if parts.is_empty() { "remote".into() } else { parts.join(", ") } + } +} + #[derive(Debug, Deserialize)] pub struct JobPost { pub title: String, pub company_name: Option, pub company_url: Option, pub job_url: String, - pub location: Option, + #[serde(default)] + pub location: Option, #[serde(default)] pub is_remote: bool, pub description: Option, @@ -261,7 +277,7 @@ async fn insert_job(pool: &PgPool, job: &JobPost, emails: &[Email]) -> anyhow::R .bind(job.company_name.as_deref().unwrap_or("")) .bind(job.company_url.as_deref().unwrap_or("")) .bind(&job.job_url) - .bind(job.location.as_deref().unwrap_or("")) + .bind(job.location.as_ref().map(|l| l.display()).unwrap_or_default()) .bind(job.is_remote) .bind(job.description.as_deref().unwrap_or("")) .bind(&emails_json)