From 0e08a294fc185c49a3fb285eedcec803f87ad37e Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 30 Dec 2022 20:02:50 +0530 Subject: [PATCH] feat: REST API endpoint to list form submissions --- src/ctx/api/v1/forms.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ctx/api/v1/forms.rs b/src/ctx/api/v1/forms.rs index 3ca5a55..959ca20 100644 --- a/src/ctx/api/v1/forms.rs +++ b/src/ctx/api/v1/forms.rs @@ -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> { + 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();