diff options
author | Vincent Ambo <mail@tazj.in> | 2023-06-09T13·01+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2023-06-10T11·23+0000 |
commit | fd98f0644f60cb8718808c40a6e4717b003eb1a8 (patch) | |
tree | 3fb0df0c8480334679f4e251897bf4b3c9086bf1 /corp/rih | |
parent | a970de336574e046e63763d93f9a70d5b1e8464b (diff) |
fix(corp/rih): correct structure of frontend request r/6255
Gotta use a shared crate for this .. Change-Id: I57669bdcace9676ff1311f3171c015702c934f56 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8734 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to '')
-rw-r--r-- | corp/rih/backend/src/main.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/corp/rih/backend/src/main.rs b/corp/rih/backend/src/main.rs index 28e4e8dfde00..168941e6f4c7 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<Response> { - 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")) } |