chore: get rid of direct DB init and use db_*

This commit is contained in:
realaravinth
2022-05-27 18:25:27 +05:30
parent cd72ae6ffe
commit d7fd23f565
25 changed files with 55 additions and 63 deletions

View File

@@ -48,7 +48,7 @@ const PAGE: &str = "Dashboard";
)]
async fn panel(data: AppData, id: Identity) -> PageResult<impl Responder> {
let username = id.identity().unwrap();
let sitekeys = data.dblib.get_all_user_captchas(&username).await?;
let sitekeys = data.db.get_all_user_captchas(&username).await?;
let body = IndexPage::new(sitekeys).render_once().unwrap();
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")

View File

@@ -74,7 +74,7 @@ pub async fn notifications(data: AppData, id: Identity) -> PageResult<impl Respo
// TODO handle error where payload.to doesnt exist
// let mut notifications = runner::get_notification(&data, &receiver).await?;
let mut notifications = data.dblib.get_all_unread_notifications(&receiver).await?;
let mut notifications = data.db.get_all_unread_notifications(&receiver).await?;
let notifications = notifications.drain(0..).map(|x| x.into()).collect();
let body = IndexPage::new(notifications).render_once().unwrap();

View File

@@ -69,9 +69,9 @@ pub struct IndexPage<'a> {
async fn settings(data: AppData, id: Identity) -> PageResult<impl Responder> {
let username = id.identity().unwrap();
let secret = data.dblib.get_secret(&username).await?;
let secret = data.db.get_secret(&username).await?;
let secret = secret.secret;
let email = data.dblib.get_email(&username).await?;
let email = data.db.get_email(&username).await?;
let data = IndexPage {
email,

View File

@@ -61,8 +61,8 @@ pub async fn advance(
let username = id.identity().unwrap();
let key = path.into_inner();
let config = data.dblib.get_captcha_config(&username, &key).await?;
let levels = data.dblib.get_captcha_levels(Some(&username), &key).await?;
let config = data.db.get_captcha_config(&username, &key).await?;
let levels = data.db.get_captcha_levels(Some(&username), &key).await?;
let body = AdvanceEditPage::new(config, levels, key)
.render_once()
@@ -103,9 +103,9 @@ pub async fn easy(
let username = id.identity().unwrap();
let key = path.into_inner();
match data.dblib.get_traffic_pattern(&username, &key).await {
match data.db.get_traffic_pattern(&username, &key).await {
Ok(c) => {
let config = data.dblib.get_captcha_config(&username, &key).await?;
let config = data.db.get_captcha_config(&username, &key).await?;
let pattern = TrafficPatternRequest {
peak_sustainable_traffic: c.peak_sustainable_traffic as u32,
avg_traffic: c.avg_traffic as u32,

View File

@@ -45,7 +45,7 @@ impl IndexPage {
)]
pub async fn list_sitekeys(data: AppData, id: Identity) -> PageResult<impl Responder> {
let username = id.identity().unwrap();
let res = data.dblib.get_all_user_captchas(&username).await?;
let res = data.db.get_all_user_captchas(&username).await?;
let body = IndexPage::new(res).render_once().unwrap();
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")

View File

@@ -67,8 +67,8 @@ pub async fn view_sitekey(
) -> PageResult<impl Responder> {
let username = id.identity().unwrap();
let key = path.into_inner();
let config = data.dblib.get_captcha_config(&username, &key).await?;
let levels = data.dblib.get_captcha_levels(Some(&username), &key).await?;
let config = data.db.get_captcha_config(&username, &key).await?;
let levels = data.db.get_captcha_levels(Some(&username), &key).await?;
let stats = data.stats.fetch(&data, &username, &key).await?;
let body = IndexPage::new(stats, config, levels, key)