From 94b58c9dea85a3ce7ab0b3ab451ef3081cbf5772 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sun, 17 Mar 2024 00:48:51 +0100 Subject: [PATCH] Refactor is_need_send function to include a Query parameter for is_private --- src/views/donate_notifications.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/views/donate_notifications.rs b/src/views/donate_notifications.rs index 9d477a4..fab40ee 100644 --- a/src/views/donate_notifications.rs +++ b/src/views/donate_notifications.rs @@ -1,5 +1,5 @@ use axum::{ - extract::Path, + extract::{Path, Query}, http::StatusCode, response::IntoResponse, routing::{get, post}, @@ -11,8 +11,13 @@ use crate::prisma::chat_donate_notifications; use super::Database; -async fn is_need_send(Path(chat_id): Path, db: Database) -> impl IntoResponse { - const NOTIFICATION_DELTA_DAYS: i64 = 60; +async fn is_need_send( + Path(chat_id): Path, + Query(is_private): Query, + db: Database, +) -> impl IntoResponse { + const NOTIFICATION_DELTA_DAYS_PRIVATE: i64 = 60; + const NOTIFICATION_DELTA_DAYS: i64 = 7; let notification = db .chat_donate_notifications() @@ -21,10 +26,15 @@ async fn is_need_send(Path(chat_id): Path, db: Database) -> impl IntoRespon .await .unwrap(); + let delta_days = if is_private == "true" { + NOTIFICATION_DELTA_DAYS_PRIVATE + } else { + NOTIFICATION_DELTA_DAYS + }; + match notification { Some(notification) => { - let result = notification.sended.naive_local() - + Duration::days(NOTIFICATION_DELTA_DAYS) + let result = notification.sended.naive_local() + Duration::days(delta_days) <= chrono::offset::Local::now().naive_local(); Json(result).into_response() }