feat: get all campaigns on an instance

This commit is contained in:
Aravinth Manivannan 2023-03-14 15:50:27 +05:30
parent 1c1617d684
commit 740b1a331e
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
1 changed files with 26 additions and 0 deletions

View File

@ -143,6 +143,32 @@ pub mod runners {
Ok(uuid)
}
pub async fn list_all_campaigns(
data: &AppData,
) -> ServiceResult<Vec<ListCampaignResp>> {
struct ListCampaign {
name: String,
id: Uuid,
}
let mut campaigns = sqlx::query_as!(
ListCampaign,
"SELECT name, id FROM survey_campaigns ORDER BY id;"
)
.fetch_all(&data.db)
.await?;
let mut list_resp = Vec::with_capacity(campaigns.len());
campaigns.drain(0..).for_each(|c| {
list_resp.push(ListCampaignResp {
name: c.name,
uuid: c.id.to_string(),
});
});
Ok(list_resp)
}
pub async fn list_campaign_runner(
username: &str,
data: &AppData,