Skip to content

Commit

Permalink
Merge pull request #114 from pheobeayo/fix-#103
Browse files Browse the repository at this point in the history
Fix: Resolved warnings during cargo build
  • Loading branch information
Marchand-Nicolas authored Nov 25, 2024
2 parents 148a9f5 + d234711 commit d35e809
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/endpoints/campaigns/get_free_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub async fn handler(
if let Ok(spent) = doc.get_bool("spent") {
if spent {
if let Ok(spent_by) = doc.get_str("spent_by") {
if (spent_by == to_hex(&query.addr)) {
if spent_by == to_hex(&query.addr) {
let r = doc.get_str("r").unwrap();
let s = doc.get_str("s").unwrap();
return (
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/referral/add_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn handler(
let update_options = UpdateOptions::builder().upsert(true).build();

let today = Utc::now().date_naive().and_hms_opt(0, 0, 0).unwrap();
let today_bson = BsonDateTime::from_millis(today.timestamp() * 1000);
let today_bson = BsonDateTime::from_millis(today.and_utc().timestamp() * 1000);

let result = sponsor_usage
.update_one(
Expand Down
51 changes: 26 additions & 25 deletions src/endpoints/referral/click_count.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{models::AppState, utils::get_error};
use crate::{ models::AppState, utils::get_error };
use axum::{
extract::{Query, State},
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
extract::{ Query, State },
http::{ HeaderMap, HeaderValue, StatusCode },
response::{ IntoResponse, Json },
};
use axum_auto_routes::route;
use chrono::{NaiveDateTime, TimeZone, Utc};
use chrono::{ Utc, DateTime };
use futures::StreamExt;
use mongodb::bson::{doc, Bson, DateTime as BsonDateTime};
use serde::{Deserialize, Serialize};
use mongodb::bson::{ doc, Bson, DateTime as BsonDateTime };
use serde::{ Deserialize, Serialize };
use std::sync::Arc;

#[derive(Serialize)]
Expand All @@ -26,40 +26,39 @@ pub struct IdQuery {
#[route(get, "/referral/click_count", crate::endpoints::referral::click_count)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Query(query): Query<IdQuery>
) -> impl IntoResponse {
let mut headers = HeaderMap::new();
headers.insert("Cache-Control", HeaderValue::from_static("max-age=30"));

let sponsor_usage = state
.starknetid_db
.collection::<mongodb::bson::Document>("sponsor_usage");
let sponsor_usage = state.starknetid_db.collection::<mongodb::bson::Document>("sponsor_usage");

let mut output = Data { counts: vec![] };
let mut i = 0;
loop {
let start_naive_dt =
NaiveDateTime::from_timestamp_opt(query.since_day + i * query.spacing, 0).unwrap();
let start_time = Utc.from_utc_datetime(&start_naive_dt);
let start_time = DateTime::from_timestamp(
query.since_day + i * query.spacing,
0
).unwrap();


let end_naive_dt =
NaiveDateTime::from_timestamp_opt(query.since_day + (i + 1) * query.spacing, 0)
.unwrap();
let end_time = Utc.from_utc_datetime(&end_naive_dt);
let end_time = DateTime::from_timestamp(
query.since_day + (i + 1) * query.spacing,
0
).unwrap();


let documents = sponsor_usage
.find(
doc! {
let documents = sponsor_usage.find(
doc! {
"sponsor_addr": &query.sponsor,
"day": {
"$gt": BsonDateTime::from_millis(start_time.timestamp() * 1000),
"$lt": BsonDateTime::from_millis(end_time.timestamp() * 1000)
},
"_cursor.to": Bson::Null,
},
None,
)
.await;
None
).await;

let mut count = 0;

Expand All @@ -72,7 +71,9 @@ pub async fn handler(
}
}
}
Err(e) => return get_error(format!("Error while fetching from database: {:?}", e)),
Err(e) => {
return get_error(format!("Error while fetching from database: {:?}", e));
}
}

output.counts.push(count);
Expand Down
52 changes: 27 additions & 25 deletions src/endpoints/referral/revenue.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{models::AppState, utils::get_error};
use crate::{ models::AppState, utils::get_error };
use axum::{
extract::{Query, State},
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
extract::{ Query, State },
http::{ HeaderMap, HeaderValue, StatusCode },
response::{ IntoResponse, Json },
};
use axum_auto_routes::route;
use chrono::{NaiveDateTime, TimeZone, Utc};
use chrono::{ Utc, DateTime };
use futures::StreamExt;
use mongodb::bson::{doc, Bson, DateTime as BsonDateTime};
use serde::{Deserialize, Serialize};
use mongodb::bson::{ doc, Bson, DateTime as BsonDateTime };
use serde::{ Deserialize, Serialize };
use std::sync::Arc;

#[derive(Serialize)]
Expand All @@ -26,30 +26,31 @@ pub struct IdQuery {
#[route(get, "/referral/revenue", crate::endpoints::referral::revenue)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Query(query): Query<IdQuery>
) -> impl IntoResponse {
let mut headers = HeaderMap::new();
headers.insert("Cache-Control", HeaderValue::from_static("max-age=30"));

let referral_revenues = state
.starknetid_db
.collection::<mongodb::bson::Document>("referral_revenues");
let referral_revenues =
state.starknetid_db.collection::<mongodb::bson::Document>("referral_revenues");

let mut output = Data { revenues: vec![] };
let mut i = 0;
loop {
let start_naive_dt =
NaiveDateTime::from_timestamp_opt(query.since_date + i * query.spacing, 0).unwrap();
let start_time = Utc.from_utc_datetime(&start_naive_dt);
let start_time = DateTime::from_timestamp(
query.since_date + i * query.spacing,
0
).unwrap();


let end_naive_dt =
NaiveDateTime::from_timestamp_opt(query.since_date + (i + 1) * query.spacing, 0)
.unwrap();
let end_time = Utc.from_utc_datetime(&end_naive_dt);
let end_time = DateTime::from_timestamp(
query.since_date + (i + 1) * query.spacing,
0
).unwrap();


let documents = referral_revenues
.find(
doc! {
let documents = referral_revenues.find(
doc! {
"sponsor_addr": &query.sponsor,
"amount": { "$gt": 0 },
"timestamp": {
Expand All @@ -58,9 +59,8 @@ pub async fn handler(
},
"_cursor.to": Bson::Null,
},
None,
)
.await;
None
).await;

let mut sum = 0;

Expand All @@ -73,7 +73,9 @@ pub async fn handler(
}
}
}
Err(e) => return get_error(format!("Error while fetching from database: {:?}", e)),
Err(e) => {
return get_error(format!("Error while fetching from database: {:?}", e));
}
}

output.revenues.push(sum);
Expand Down
52 changes: 27 additions & 25 deletions src/endpoints/referral/sales_count.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{models::AppState, utils::get_error};
use crate::{ models::AppState, utils::get_error };
use axum::{
extract::{Query, State},
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
extract::{ Query, State },
http::{ HeaderMap, HeaderValue, StatusCode },
response::{ IntoResponse, Json },
};
use axum_auto_routes::route;
use chrono::{NaiveDateTime, TimeZone, Utc};
use chrono::{ Utc, DateTime };
use futures::StreamExt;
use mongodb::bson::{doc, Bson, DateTime as BsonDateTime};
use serde::{Deserialize, Serialize};
use mongodb::bson::{ doc, Bson, DateTime as BsonDateTime };
use serde::{ Deserialize, Serialize };
use std::sync::Arc;

#[derive(Serialize)]
Expand All @@ -26,30 +26,31 @@ pub struct IdQuery {
#[route(get, "/referral/sales_count", crate::endpoints::referral::sales_count)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Query(query): Query<IdQuery>
) -> impl IntoResponse {
let mut headers = HeaderMap::new();
headers.insert("Cache-Control", HeaderValue::from_static("max-age=30"));

let referral_revenues = state
.starknetid_db
.collection::<mongodb::bson::Document>("referral_revenues");
let referral_revenues =
state.starknetid_db.collection::<mongodb::bson::Document>("referral_revenues");

let mut output = Data { counts: vec![] };
let mut i = 0;
loop {
let start_naive_dt =
NaiveDateTime::from_timestamp_opt(query.since_date + i * query.spacing, 0).unwrap();
let start_time = Utc.from_utc_datetime(&start_naive_dt);
let start_time = DateTime::from_timestamp(
query.since_date + i * query.spacing,
0
).unwrap();


let end_naive_dt =
NaiveDateTime::from_timestamp_opt(query.since_date + (i + 1) * query.spacing, 0)
.unwrap();
let end_time = Utc.from_utc_datetime(&end_naive_dt);
let end_time = DateTime::from_timestamp(
query.since_date + (i + 1) * query.spacing,
0
).unwrap();


let documents = referral_revenues
.find(
doc! {
let documents = referral_revenues.find(
doc! {
"sponsor_addr": &query.sponsor,
"amount": { "$gt": 0 },
"timestamp": {
Expand All @@ -58,9 +59,8 @@ pub async fn handler(
},
"_cursor.to": Bson::Null,
},
None,
)
.await;
None
).await;

let mut count = 0;

Expand All @@ -72,7 +72,9 @@ pub async fn handler(
}
}
}
Err(e) => return get_error(format!("Error while fetching from database: {:?}", e)),
Err(e) => {
return get_error(format!("Error while fetching from database: {:?}", e));
}
}

output.counts.push(count);
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::{
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use chrono::NaiveDateTime;
use chrono::DateTime;
use futures::StreamExt;
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -155,7 +155,7 @@ pub async fn handler(
},
Attribute {
trait_type: "Domain expiry".to_string(),
value: vec![NaiveDateTime::from_timestamp_opt(expiry.into(), 0)
value: vec![DateTime::from_timestamp(expiry.into(), 0)
.map(|dt| dt.format("%b %d, %Y").to_string())
.unwrap_or_else(|| "Invalid date".into())],
},
Expand Down

0 comments on commit d35e809

Please sign in to comment.