From fd98f0644f60cb8718808c40a6e4717b003eb1a8 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 9 Jun 2023 16:01:57 +0300 Subject: fix(corp/rih): correct structure of frontend request Gotta use a shared crate for this .. Change-Id: I57669bdcace9676ff1311f3171c015702c934f56 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8734 Reviewed-by: tazjin Tested-by: BuildkiteCI --- corp/rih/backend/src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'corp') diff --git a/corp/rih/backend/src/main.rs b/corp/rih/backend/src/main.rs index 28e4e8dfde..168941e6f4 100644 --- a/corp/rih/backend/src/main.rs +++ b/corp/rih/backend/src/main.rs @@ -7,6 +7,13 @@ use std::net::SocketAddr; use std::time::{SystemTime, UNIX_EPOCH}; use uuid::Uuid; +/// Represents the request sent by the frontend application. +#[derive(Debug, Deserialize)] +struct FrontendReq { + captcha_token: String, + record: Record, +} + /// Represents a single record as filled in by a user. This is the /// primary data structure we want to populate and persist somewhere. #[derive(Debug, Deserialize, Serialize)] @@ -57,13 +64,13 @@ fn persist_record(ip: &SocketAddr, record: &Record) -> Result<()> { } fn handle_submit(req: &Request) -> Result { - let record: Record = rouille::input::json::json_input(req)?; + let submitted: FrontendReq = rouille::input::json::json_input(req)?; - if !record.validate() { - bail!("invalid record: {:?}", record); + if !submitted.record.validate() { + bail!("invalid record: {:?}", submitted.record); } - persist_record(req.remote_addr(), &record)?; + persist_record(req.remote_addr(), &submitted.record)?; Ok(Response::text("success")) } -- cgit 1.4.1