feat: REST API endpoint to list form submissions
This commit is contained in:
parent
ff9864f5ad
commit
0e08a294fc
1 changed files with 31 additions and 0 deletions
|
@ -67,6 +67,30 @@ impl Ctx {
|
|||
.unwrap();
|
||||
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)]
|
||||
|
@ -132,6 +156,13 @@ mod tests {
|
|||
subs[0].value,
|
||||
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)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in a new issue