mirror of
https://github.com/flibusta-apps/users_settings_server.git
synced 2025-12-06 06:35:39 +01:00
Refactor is_need_send function to include a Query parameter for is_private
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::Path,
|
extract::{Path, Query},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
@@ -11,8 +11,13 @@ use crate::prisma::chat_donate_notifications;
|
|||||||
|
|
||||||
use super::Database;
|
use super::Database;
|
||||||
|
|
||||||
async fn is_need_send(Path(chat_id): Path<i64>, db: Database) -> impl IntoResponse {
|
async fn is_need_send(
|
||||||
const NOTIFICATION_DELTA_DAYS: i64 = 60;
|
Path(chat_id): Path<i64>,
|
||||||
|
Query(is_private): Query<String>,
|
||||||
|
db: Database,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
const NOTIFICATION_DELTA_DAYS_PRIVATE: i64 = 60;
|
||||||
|
const NOTIFICATION_DELTA_DAYS: i64 = 7;
|
||||||
|
|
||||||
let notification = db
|
let notification = db
|
||||||
.chat_donate_notifications()
|
.chat_donate_notifications()
|
||||||
@@ -21,10 +26,15 @@ async fn is_need_send(Path(chat_id): Path<i64>, db: Database) -> impl IntoRespon
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let delta_days = if is_private == "true" {
|
||||||
|
NOTIFICATION_DELTA_DAYS_PRIVATE
|
||||||
|
} else {
|
||||||
|
NOTIFICATION_DELTA_DAYS
|
||||||
|
};
|
||||||
|
|
||||||
match notification {
|
match notification {
|
||||||
Some(notification) => {
|
Some(notification) => {
|
||||||
let result = notification.sended.naive_local()
|
let result = notification.sended.naive_local() + Duration::days(delta_days)
|
||||||
+ Duration::days(NOTIFICATION_DELTA_DAYS)
|
|
||||||
<= chrono::offset::Local::now().naive_local();
|
<= chrono::offset::Local::now().naive_local();
|
||||||
Json(result).into_response()
|
Json(result).into_response()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user