feat: list forms associated with a hostname
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
closes: #7
This commit is contained in:
parent
1c89173599
commit
9e4482780d
2 changed files with 48 additions and 1 deletions
|
@ -1,5 +1,25 @@
|
|||
{
|
||||
"db": "PostgreSQL",
|
||||
"1f1b56ba273dd27da300e0025a3dd2dddca8280299bbc6a90b79a10951f7641b": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "website_path",
|
||||
"ordinal": 0,
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT DISTINCT\n website_path\n FROM\n forms_submissions\n WHERE\n website_id = (SELECT ID FROM forms_websites WHERE hostname = $1)"
|
||||
},
|
||||
"657a97c81a7bae97b22a5bc7e297978acc2c7fa3859aa8adffc2b6976aafde82": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
|
29
src/db.rs
29
src/db.rs
|
@ -116,6 +116,30 @@ impl Database {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Get forms belonging to a host
|
||||
pub async fn list_forms(&self, host: &str) -> ServiceResult<Vec<String>> {
|
||||
struct S{
|
||||
website_path: String,
|
||||
}
|
||||
let mut forms = sqlx::query_as!(
|
||||
S,
|
||||
"SELECT DISTINCT
|
||||
website_path
|
||||
FROM
|
||||
forms_submissions
|
||||
WHERE
|
||||
website_id = (SELECT ID FROM forms_websites WHERE hostname = $1)",
|
||||
host)
|
||||
.fetch_all(&self.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut resp = Vec::with_capacity(forms.len());
|
||||
for f in forms.drain(0..) {
|
||||
resp.push(f.website_path);
|
||||
}
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
pub async fn get_form_submissions(
|
||||
&self,
|
||||
page: usize,
|
||||
|
@ -249,7 +273,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert!(db.ping().await);
|
||||
|
||||
let urls = ["example.com", "example.com", "example.net"];
|
||||
let urls = ["example.com", "example.org", "example.net"];
|
||||
for url in urls.iter() {
|
||||
db.delete_site(url).await.unwrap();
|
||||
// ensuring delete doesn't fail when record doesn't exist
|
||||
|
@ -264,6 +288,9 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
assert_eq!(db.list_forms(url).await.unwrap().len(), 1);
|
||||
|
||||
let subs = db.get_form_submissions(0, url, path).await.unwrap();
|
||||
assert_eq!(
|
||||
&serde_json::Value::default(),
|
||||
|
|
Loading…
Reference in a new issue