mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 02:25:41 +00:00
notifications view
This commit is contained in:
@@ -154,8 +154,8 @@ pub mod runners {
|
||||
let res;
|
||||
if let Some(email) = &payload.email {
|
||||
res = sqlx::query!(
|
||||
"INSERT INTO mcaptcha_users
|
||||
(name , password, email, secret) VALUES ($1, $2, $3, $4)",
|
||||
"insert into mcaptcha_users
|
||||
(name , password, email, secret) values ($1, $2, $3, $4)",
|
||||
&username,
|
||||
&hash,
|
||||
&email,
|
||||
@@ -182,7 +182,7 @@ pub mod runners {
|
||||
if msg.contains("mcaptcha_users_name_key") {
|
||||
return Err(ServiceError::UsernameTaken);
|
||||
} else if msg.contains("mcaptcha_users_email_key") {
|
||||
return Err(ServiceError::EmailTaken);
|
||||
return Err(ServiceError::UsernameTaken);
|
||||
} else if msg.contains("mcaptcha_users_secret_key") {
|
||||
continue;
|
||||
} else {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub mod account;
|
||||
pub mod auth;
|
||||
pub mod mcaptcha;
|
||||
pub mod meta;
|
||||
mod notifications;
|
||||
pub mod notifications;
|
||||
pub mod pow;
|
||||
mod routes;
|
||||
|
||||
|
||||
@@ -63,25 +63,39 @@ pub async fn get_notification(
|
||||
let receiver = id.identity().unwrap();
|
||||
// TODO handle error where payload.to doesnt exist
|
||||
|
||||
let mut notifications = sqlx::query_file_as!(
|
||||
Notification,
|
||||
"src/api/v1/notifications/get_all_unread.sql",
|
||||
&receiver
|
||||
)
|
||||
.fetch_all(&data.db)
|
||||
.await?;
|
||||
|
||||
let resp: Vec<NotificationResp> = notifications
|
||||
.drain(0..)
|
||||
.map(|x| {
|
||||
let y: NotificationResp = x.into();
|
||||
y
|
||||
})
|
||||
.collect();
|
||||
let resp = runner::get_notification(&data, &receiver).await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(resp))
|
||||
}
|
||||
|
||||
pub mod runner {
|
||||
use super::*;
|
||||
pub async fn get_notification(
|
||||
data: &AppData,
|
||||
receiver: &str,
|
||||
) -> ServiceResult<Vec<NotificationResp>> {
|
||||
// TODO handle error where payload.to doesnt exist
|
||||
|
||||
let mut notifications = sqlx::query_file_as!(
|
||||
Notification,
|
||||
"src/api/v1/notifications/get_all_unread.sql",
|
||||
&receiver
|
||||
)
|
||||
.fetch_all(&data.db)
|
||||
.await?;
|
||||
|
||||
let resp = notifications
|
||||
.drain(0..)
|
||||
.map(|x| {
|
||||
let y: NotificationResp = x.into();
|
||||
y
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(resp)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
mod add;
|
||||
mod get;
|
||||
mod mark_read;
|
||||
pub mod add;
|
||||
pub mod get;
|
||||
pub mod mark_read;
|
||||
|
||||
pub mod routes {
|
||||
|
||||
|
||||
@@ -44,11 +44,9 @@ async fn auth_works() {
|
||||
confirm_password: PASSWORD.into(),
|
||||
email: None,
|
||||
};
|
||||
let resp = test::call_service(
|
||||
&app,
|
||||
post_request!(&msg, ROUTES.auth.register).to_request(),
|
||||
)
|
||||
.await;
|
||||
let resp =
|
||||
test::call_service(&app, post_request!(&msg, ROUTES.auth.register).to_request())
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
// delete user
|
||||
delete_user(NAME, &data).await;
|
||||
|
||||
Reference in New Issue
Block a user