Skip to content

Commit

Permalink
refactor: use axum_auto_routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Jan 19, 2024
1 parent b954836 commit d3ec41e
Show file tree
Hide file tree
Showing 32 changed files with 125 additions and 102 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "c974e5cb42e8d8344cee910b76005ec46b4dd3ed" }
starknet-id = { git = "https://github.com/starknet-id/starknetid.rs", rev = "2b30c2453b96789a628c86d2edebb1023fa2e77d" }
axum_auto_routes = { git = "https://github.com/Th0rgal/axum_auto_routes.git", rev = "f9e1d2083e887cd264642359c4aa851938da6f09" }
axum = "0.6.18"
futures = "0.3.28"
mongodb = "2.5.0"
Expand All @@ -26,3 +27,4 @@ lazy_static = "1.4.0"
regex = "1.10.2"
bs58 = "0.5.0"
ed25519-dalek = "2.1.0"
ctor = "0.2.6"
2 changes: 2 additions & 0 deletions src/endpoints/addr_has_rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use axum::{
response::IntoResponse,
Json,
};
use axum_auto_routes::route;
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
use starknet::core::types::FieldElement;
Expand All @@ -23,6 +24,7 @@ pub struct AddrHasRevQuery {
addr: FieldElement,
}

#[route(get, "/addr_has_rev", crate::endpoints::addr_has_rev)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<AddrHasRevQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/addr_to_available_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use axum::{
response::IntoResponse,
Json,
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
Expand All @@ -25,6 +26,7 @@ pub struct AddrQuery {
addr: FieldElement,
}

#[route(get, "/addr_to_available_ids", crate::endpoints::addr_to_available_ids)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<AddrQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/addr_to_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use axum::{
response::IntoResponse,
Json,
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::{
bson::{doc, Document},
Expand Down Expand Up @@ -53,6 +54,7 @@ async fn aggregate_data(
read_cursor(cursor).await
}

#[route(get, "/addr_to_domain", crate::endpoints::addr_to_domain)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<AddrToDomainQuery>,
Expand Down
6 changes: 6 additions & 0 deletions src/endpoints/addr_to_external_domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::IntoResponse,
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
Expand All @@ -23,6 +24,11 @@ pub struct DomainQuery {
addr: FieldElement,
}

#[route(
get,
"/addr_to_external_domains",
crate::endpoints::addr_to_external_domains
)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<DomainQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/addr_to_full_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use axum::{
response::IntoResponse,
Json,
};
use axum_auto_routes::route;
use futures::future::join_all;
use futures::stream::StreamExt;
use mongodb::{
Expand Down Expand Up @@ -52,6 +53,7 @@ pub struct FullIdResponse {
full_ids: Vec<FullId>,
}

#[route(get, "/addr_to_full_ids", crate::endpoints::addr_to_full_ids)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<AddrQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/addr_to_token_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use mongodb::bson::{doc, Bson};
use serde::{Deserialize, Serialize};
use starknet::core::types::FieldElement;
Expand All @@ -22,6 +23,7 @@ pub struct TokenIdQuery {
addr: FieldElement,
}

#[route(get, "/addr_to_token_id", crate::endpoints::addr_to_token_id)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<TokenIdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/addrs_to_domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::{
http::StatusCode,
response::IntoResponse,
};
use axum_auto_routes::route;
use futures::stream::StreamExt;
use mongodb::{
bson::{doc, Document},
Expand Down Expand Up @@ -56,6 +57,7 @@ async fn run_aggregation_pipeline(
process_cursor(cursor, results).await
}

#[route(post, "/addrs_to_domains", crate::endpoints::addrs_to_domains)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Json(query): Json<AddrToDomainsQuery>,
Expand Down
6 changes: 6 additions & 0 deletions src/endpoints/crosschain/solana/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
utils::{get_error, to_hex},
};
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use axum_auto_routes::route;
use chrono::{Duration, Utc};
use ed25519_dalek::{Signature, Verifier, VerifyingKey};
use mongodb::bson::doc;
Expand Down Expand Up @@ -64,6 +65,11 @@ lazy_static::lazy_static! {
static ref SOL_SUBDOMAIN_STR: FieldElement = FieldElement::from_dec_str("9145722242464647959622012987758").unwrap();
}

#[route(
post,
"/crosschain/solana/claim",
crate::endpoints::crosschain::solana::claim
)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Json(query): Json<SigQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/data_to_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
use starknet::core::types::FieldElement;
Expand All @@ -24,6 +25,7 @@ pub struct StarknetIdQuery {
data: FieldElement,
}

#[route(get, "/data_to_ids", crate::endpoints::data_to_ids)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<StarknetIdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/domain_to_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::{bson::doc, options::AggregateOptions};
use serde::{Deserialize, Serialize};
Expand All @@ -23,6 +24,7 @@ pub struct DomainQuery {
domain: String,
}

#[route(get, "/domain_to_addr", crate::endpoints::domain_to_addr)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<DomainQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/domain_to_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::bson::{doc, from_bson, Bson, Document};
use serde::Deserialize;
Expand All @@ -17,6 +18,7 @@ pub struct DomainQuery {
domain: String,
}

#[route(get, "/domain_to_data", crate::endpoints::domain_to_data)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<DomainQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/galxe/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use crate::models::AppState;
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::{bson::doc, bson::Document};
use serde::{Deserialize, Serialize};
Expand All @@ -16,6 +17,7 @@ pub struct SimpleResponse {
result: &'static str,
}

#[route(post, "/galxe/verify", crate::endpoints::galxe::verify)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Json(query): Json<EmailQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/id_to_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::bson::{doc, from_bson, Bson, Document};
use serde::Deserialize;
Expand All @@ -18,6 +19,7 @@ pub struct IdQuery {
id: FieldElement,
}

#[route(get, "/id_to_data", crate::endpoints::id_to_data)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/referral/add_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
http::StatusCode,
response::IntoResponse,
};
use axum_auto_routes::route;
use chrono::Utc;
use mongodb::{
bson::{doc, DateTime as BsonDateTime},
Expand All @@ -18,6 +19,7 @@ pub struct AddClickQuery {
sponsor_addr: FieldElement,
}

#[route(post, "/referral/add_click", crate::endpoints::referral::add_click)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Json(query): Json<AddClickQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/referral/click_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use chrono::{DateTime, NaiveDateTime, Utc};
use futures::StreamExt;
use mongodb::bson::{doc, Bson, DateTime as BsonDateTime};
Expand All @@ -22,6 +23,7 @@ pub struct IdQuery {
spacing: i64,
}

#[route(get, "/referral/click_count", crate::endpoints::referral::click_count)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/referral/revenue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use chrono::{DateTime, NaiveDateTime, Utc};
use futures::StreamExt;
use mongodb::bson::{doc, Bson, DateTime as BsonDateTime};
Expand All @@ -22,6 +23,7 @@ pub struct IdQuery {
spacing: i64,
}

#[route(get, "/referral/revenue", crate::endpoints::referral::revenue)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/referral/sales_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use chrono::{DateTime, NaiveDateTime, Utc};
use futures::StreamExt;
use mongodb::bson::{doc, Bson, DateTime as BsonDateTime};
Expand All @@ -22,6 +23,7 @@ pub struct IdQuery {
spacing: i64,
}

#[route(get, "/referral/sales_count", crate::endpoints::referral::sales_count)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<IdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/renewal/get_metahash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use futures::TryStreamExt;
use mongodb::bson::{doc, Bson};
use serde::{Deserialize, Serialize};
Expand All @@ -24,6 +25,7 @@ pub struct GetMetaHashQuery {
addr: FieldElement,
}

#[route(get, "/renewal/get_metahash", crate::endpoints::renewal::get_metahash)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<GetMetaHashQuery>,
Expand Down
6 changes: 6 additions & 0 deletions src/endpoints/renewal/get_non_subscribed_domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::StatusCode,
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::{bson::doc, options::AggregateOptions};
use regex::Regex;
Expand All @@ -23,6 +24,11 @@ lazy_static::lazy_static! {
static ref DOMAIN_REGEX: Regex = Regex::new(r"^[^.]+\.stark$").unwrap();
}

#[route(
get,
"/renewal/get_non_subscribed_domains",
crate::endpoints::renewal::get_non_subscribed_domains
)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<StarknetIdQuery>,
Expand Down
6 changes: 6 additions & 0 deletions src/endpoints/renewal/get_renewal_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::{HeaderMap, HeaderValue, StatusCode},
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::{bson::doc, options::FindOptions};
use serde::{Deserialize, Serialize};
Expand All @@ -24,6 +25,11 @@ pub struct StarknetIdQuery {
domain: String,
}

#[route(
get,
"/renewal/get_renewal_data",
crate::endpoints::renewal::get_renewal_data
)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<StarknetIdQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/starkscan/fetch_nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use axum::{
http::StatusCode,
response::{IntoResponse, Json},
};
use axum_auto_routes::route;
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -44,6 +45,7 @@ pub struct StarkscanNftProps {
minted_at_timestamp: i64,
}

#[route(get, "/starkscan/fetch_nfts", crate::endpoints::starkscan::fetch_nfts)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<FetchNftsQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/stats/count_addrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::{
response::IntoResponse,
Json,
};
use axum_auto_routes::route;
use futures::StreamExt;
use mongodb::bson::{doc, Bson};
use serde::{Deserialize, Serialize};
Expand All @@ -20,6 +21,7 @@ pub struct CountAddrsQuery {
since: i64,
}

#[route(get, "/stats/count_addrs", crate::endpoints::stats::count_addrs)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<CountAddrsQuery>,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/stats/count_club_domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::{
response::IntoResponse,
Json,
};
use axum_auto_routes::route;
use futures::TryStreamExt;
use mongodb::bson::{self, doc, Bson};
use serde::{Deserialize, Serialize};
Expand All @@ -22,6 +23,7 @@ pub struct CountClubDomainsQuery {
since: i64,
}

#[route(get, "/stats/count_club_domains", crate::endpoints::stats::count_club_domains)]
pub async fn handler(
State(state): State<Arc<AppState>>,
Query(query): Query<CountClubDomainsQuery>,
Expand Down
Loading

0 comments on commit d3ec41e

Please sign in to comment.