feat: REST API endpoint to list form submissions

This commit is contained in:
Aravinth Manivannan 2022-12-30 20:02:50 +05:30
parent ff9864f5ad
commit 0e08a294fc
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88

View file

@ -67,6 +67,30 @@ impl Ctx {
.unwrap(); .unwrap();
Ok(res) Ok(res)
} }
/// List all forms associated with hostname
pub async fn get_all_forms_for_host(
&self,
owner: &str,
host: &str,
) -> ServiceResult<Vec<String>> {
let _site = self.db.get_site(owner, host).await?;
let mut form_url = self.settings.form.url.clone();
form_url.set_path("/api/v1/forms/host");
form_url.set_query(Some(&format!("host={}", host)));
let res = self
.client
.get(form_url)
.bearer_auth(&self.settings.form.api_key)
.send()
.await
.unwrap()
.json()
.await
.unwrap();
Ok(res)
}
} }
#[cfg(test)] #[cfg(test)]
@ -132,6 +156,13 @@ mod tests {
subs[0].value, subs[0].value,
Some(serde_json::to_value(&site_info).unwrap()) Some(serde_json::to_value(&site_info).unwrap())
); );
let forms = ctx
.get_all_forms_for_host(NAME, &page.domain)
.await
.unwrap();
assert_eq!(vec![site_info.path.clone()], forms);
ctx.delete_form_submission(NAME, subs[0].id, &site_info) ctx.delete_form_submission(NAME, subs[0].id, &site_info)
.await .await
.unwrap(); .unwrap();