From 7daffe767cf18b7e6522f3c81f5dcb45694cc694 Mon Sep 17 00:00:00 2001
From: realaravinth <realaravinth@batsense.net>
Date: Sat, 14 May 2022 16:27:28 +0530
Subject: [PATCH] feat: implement get captcha cooldown period interface for
 sqlx postgres

---
 db/db-sqlx-postgres/src/lib.rs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/db/db-sqlx-postgres/src/lib.rs b/db/db-sqlx-postgres/src/lib.rs
index aab70be3..5abaa641 100644
--- a/db/db-sqlx-postgres/src/lib.rs
+++ b/db/db-sqlx-postgres/src/lib.rs
@@ -513,6 +513,25 @@ impl MCDatabase for Database {
         }
         Ok(new_levels)
     }
+
+    /// Get captcha's cooldown period
+    async fn get_captcha_cooldown(&self, captcha_key: &str) -> DBResult<i32> {
+        struct DurationResp {
+            duration: i32,
+        }
+
+        let resp = sqlx::query_as!(
+            DurationResp,
+            "SELECT duration FROM mcaptcha_config  
+            WHERE key = $1",
+            captcha_key,
+        )
+        .fetch_one(&self.pool)
+        .await
+        .map_err(|e| map_row_not_found_err(e, DBError::CaptchaNotFound))?;
+
+        Ok(resp.duration)
+    }
 }
 
 fn now_unix_time_stamp() -> i64 {