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 <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2023-06-09 16:01:57 +03:00 committed by tazjin
parent a970de3365
commit fd98f0644f

View file

@ -7,6 +7,13 @@ use std::net::SocketAddr;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use uuid::Uuid; 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 /// Represents a single record as filled in by a user. This is the
/// primary data structure we want to populate and persist somewhere. /// primary data structure we want to populate and persist somewhere.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@ -57,13 +64,13 @@ fn persist_record(ip: &SocketAddr, record: &Record) -> Result<()> {
} }
fn handle_submit(req: &Request) -> Result<Response> { 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() { if !submitted.record.validate() {
bail!("invalid record: {:?}", record); bail!("invalid record: {:?}", submitted.record);
} }
persist_record(req.remote_addr(), &record)?; persist_record(req.remote_addr(), &submitted.record)?;
Ok(Response::text("success")) Ok(Response::text("success"))
} }