Skip to content

Commit

Permalink
update to the new edtion 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Feb 26, 2025
1 parent 93dbcd7 commit 2a1048f
Show file tree
Hide file tree
Showing 30 changed files with 55 additions and 57 deletions.
37 changes: 18 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rustfulapi"
authors = ["Mahdi Robatipoor<[email protected]>"]
description = "RESTful API template built with Rust language"
edition = "2021"
edition = "2024"
homepage = "https://github.com/robatipoor/rustfulapi"
keywords = ["web", "api", "rest","orm"]
license = "MIT"
Expand All @@ -18,8 +18,8 @@ name = "migration"
path = "./src/bin/migration.rs"

[dependencies]
axum = { version = "0.7.9", features = ["ws"] }
axum-extra = { version = "0.9.6", features = ["typed-header"] }
axum = { version = "0.8.1", features = ["ws"] }
axum-extra = { version = "0.10.0", features = ["typed-header"] }
sea-orm = { version = "1.1.2", features = [
"sqlx-postgres",
"runtime-tokio-rustls",
Expand All @@ -31,34 +31,33 @@ sea-orm-migration = { version = "1.1.2", features = [
] }
anyhow = "1.0.94"
argon2 = "0.5.3"
async-trait = "0.1.83"
base64 = "0.22.1"
chrono = { version = "0.4.39", default-features = false, features = [
"clock",
"serde",
] }
config = "0.14.1"
fake = { version = "3.0.1", features = ["derive", "uuid", "chrono"] }
config = "0.15.8"
fake = { version = "4.0.0", features = ["derive", "uuid", "chrono"] }
futures = "0.3.31"
itertools = "0.13.0"
itertools = "0.14.0"
jsonwebtoken = "9.3.0"
lettre = { version = "0.11.11", features = ["tokio1-native-tls", "builder"] }
log = "0.4.22"
log-derive = "0.4.1"
openssl = "0.10.68"
rand = "0.8.5"
rand_core = { version = "0.6.4", features = ["std"] }
redis = { version = "0.27.6", features = ["tokio-comp"] }
rand = "0.9.0"
rand_core = { version = "0.9.2", features = ["std"] }
redis = { version = "0.29.0", features = ["tokio-comp"] }
reqwest = { version = "0.12.9", features = ["json", "multipart", "stream"] }
scraper = "0.22.0"
sentry = "0.35.0"
scraper = "0.23.1"
sentry = "0.36.0"
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
sha2 = "0.10.8"
strum = { version = "0.26.3", features = ["derive"] }
strum = { version = "0.27.1", features = ["derive"] }
tera = "1.20.0"
test-context = "0.3.0"
thiserror = "2.0.6"
test-context = "0.4.1"
thiserror = "2.0.11"
tokio = { version = "1.42.0", features = ["full"] }
tracing = { version = "0.1.41", features = ["attributes"] }
tracing-appender = "0.2.3"
Expand All @@ -70,10 +69,10 @@ tracing-subscriber = { version = "0.3.19", features = [
] }
url = "2.5.2"
utoipa = { version = "5.2.0", features = ["axum_extras", "uuid", "chrono"] }
utoipa-swagger-ui = { version = "8.0.3", features = ["axum"] }
utoipa-axum = "0.1.2"
utoipa-swagger-ui = { version = "9.0.0", features = ["axum"] }
utoipa-axum = "0.2.0"
uuid = { version = "1.11.0", features = ["v4", "serde"] }
tokio-tungstenite = "0.24.0"
garde = { version = "0.20.0", features = ["full"] }
tokio-tungstenite = "0.26.2"
garde = { version = "0.22.0", features = ["full"] }
regex = "1.11.1"
wiremock = "0.6.2"
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rustfmt configurations from master branch, check rustfmt version
# (cargo fmt --version).
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md
edition = "2021"
edition = "2024"
tab_spaces = 2
reorder_imports = true
2 changes: 1 addition & 1 deletion scripts/init_mockserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [[ -n $RUNNING_CONTAINER ]]; then
else
echo >&2 "update exceptions"
curl -X PUT -H "Content-Type: application/json" \
-d @"${SCRIPT_PATH}"/mockserver-expections/init.json \
-d @"${SCRIPT_PATH}"/mockserver-expectations/init.json \
localhost:"${PORT}"/mockserver/expectation
echo >&2 "you can kill container with command :"
echo >&2 "docker kill ${RUNNING_CONTAINER}"
Expand Down
2 changes: 1 addition & 1 deletion src/bin/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use futures::FutureExt;
use rustfulapi::constant::CONFIG;
use rustfulapi::error::AppResult;
use rustfulapi::server::worker::MessengerTask;
use rustfulapi::server::AppServer;
use rustfulapi::server::worker::MessengerTask;
use rustfulapi::{configure, util};
use tracing::info;

Expand Down
4 changes: 2 additions & 2 deletions src/client/redis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
configure::{redis::RedisConfig, AppConfig},
configure::{AppConfig, redis::RedisConfig},
constant::CONFIG,
error::AppResult,
};
Expand All @@ -22,7 +22,7 @@ pub trait RedisClientExt: ClientBuilder {
) -> impl std::future::Future<Output = Result<(), RedisError>>;
fn exist(&self, key: &str) -> impl std::future::Future<Output = Result<bool, RedisError>>;
fn get(&self, key: &str)
-> impl std::future::Future<Output = Result<Option<String>, RedisError>>;
-> impl std::future::Future<Output = Result<Option<String>, RedisError>>;
fn del(&self, key: &str) -> impl std::future::Future<Output = Result<bool, RedisError>>;
fn ttl(&self, key: &str) -> impl std::future::Future<Output = Result<i64, RedisError>>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/configure/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use tracing::{subscriber, Subscriber};
use tracing::{Subscriber, subscriber};
use tracing_appender::{
non_blocking::WorkerGuard,
rolling::{RollingFileAppender, Rotation},
};
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_log::LogTracer;
use tracing_subscriber::{fmt::MakeWriter, layer::SubscriberExt, EnvFilter, Registry};
use tracing_subscriber::{EnvFilter, Registry, fmt::MakeWriter, layer::SubscriberExt};

use crate::error::AppResult;

Expand Down
2 changes: 1 addition & 1 deletion src/constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{path::PathBuf, sync::LazyLock, time::Duration};
use utoipa::OpenApi;

use crate::{
client::{email::EmailClient, http::HttpClient, redis::RedisClient, ClientBuilder},
client::{ClientBuilder, email::EmailClient, http::HttpClient, redis::RedisClient},
configure::{env::get_profile, get_static_dir, template::TemplateEngine},
handler::openapi::ApiDoc,
};
Expand Down
2 changes: 1 addition & 1 deletion src/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fake::Dummy;
use fake::faker::internet::en::SafeEmail;
use fake::faker::lorem::en::{Paragraph, Sentence};
use fake::Dummy;
use garde::Validate;
use lettre::Message;
pub use request::*;
Expand Down
2 changes: 1 addition & 1 deletion src/dto/request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fake::faker::internet::en::{Password, SafeEmail, Username};
use fake::Dummy;
use fake::faker::internet::en::{Password, SafeEmail, Username};
use garde::Validate;
use serde::{Deserialize, Serialize};
use strum::Display;
Expand Down
4 changes: 2 additions & 2 deletions src/entity/user.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use chrono::{DateTime, Utc};
use fake::faker::internet::en::{FreeEmail, Password, Username};
use fake::Dummy;
use fake::faker::internet::en::{FreeEmail, Password, Username};
use sea_orm::entity::prelude::*;

use crate::error::ResourceType;

use super::role::RoleUser;
use super::AppEntity;
use super::role::RoleUser;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Dummy, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
Expand Down
2 changes: 1 addition & 1 deletion src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::{
Json,
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
use serde::Deserialize;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/handler/admin/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::extract::{Query, State};
use axum::Json;
use axum::extract::{Query, State};
use tracing::info;

use crate::error::{AppResponseError, AppResult};
Expand Down
2 changes: 1 addition & 1 deletion src/handler/openapi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use utoipa::{
openapi::security::{Http, HttpAuthScheme, SecurityScheme},
Modify,
openapi::security::{Http, HttpAuthScheme, SecurityScheme},
};

use crate::dto::*;
Expand Down
2 changes: 1 addition & 1 deletion src/handler/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::client::redis::RedisClientExt;
use crate::dto::{MessageResponse, ServiceStatusResponse};
use crate::error::{AppResponseError, AppResult};
use crate::server::state::AppState;
use axum::extract::State;
use axum::Json;
use axum::extract::State;
use tracing::error;

// Health check.
Expand Down
2 changes: 1 addition & 1 deletion src/handler/token.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::extract::State;
use axum::Json;
use axum::extract::State;
use garde::Validate;
use tracing::{info, warn};

Expand Down
2 changes: 1 addition & 1 deletion src/handler/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::extract::{Query, State};
use axum::Json;
use axum::extract::{Query, State};
use garde::Validate;
use tracing::{info, warn};

Expand Down
4 changes: 2 additions & 2 deletions src/repo/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::Utc;
use sea_orm::{
sea_query::Expr, ActiveModelTrait, ColumnTrait, Condition, ConnectionTrait, DatabaseConnection,
DatabaseTransaction, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, Set,
ActiveModelTrait, ColumnTrait, Condition, ConnectionTrait, DatabaseConnection,
DatabaseTransaction, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, Set, sea_query::Expr,
};
use uuid::Uuid;

Expand Down
2 changes: 1 addition & 1 deletion src/server/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::sync::Arc;
use tokio::sync::Notify;

use crate::client::{
ClientBuilder,
database::{DatabaseClient, DatabaseClientExt},
email::EmailClient,
http::HttpClient,
redis::RedisClient,
ClientBuilder,
};
use crate::configure::AppConfig;
use crate::error::AppResult;
Expand Down
2 changes: 1 addition & 1 deletion src/service/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::constant::EXPIRE_TWO_FACTOR_CODE_SECS;
use crate::dto::*;
use crate::entity;
use crate::entity::message::MessageKind;
use crate::error::invalid_input_error;
use crate::error::AppResult;
use crate::error::ToAppResult;
use crate::error::invalid_input_error;
use crate::repo;
use crate::server::state::AppState;
use crate::service;
Expand Down
5 changes: 2 additions & 3 deletions src/util/claim.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::{sync::LazyLock, time::Duration};

use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
headers::{Authorization, authorization::Bearer},
};

use axum::RequestPartsExt;
use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use axum::RequestPartsExt;
use chrono::Utc;
use fake::Dummy;
use jsonwebtoken::Header;
Expand Down Expand Up @@ -63,7 +63,6 @@ impl UserClaims {
}
}

#[async_trait::async_trait]
impl FromRequestParts<AppState> for UserClaims {
type Rejection = AppError;

Expand Down
2 changes: 1 addition & 1 deletion src/util/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod tests {
use super::store_file;
use crate::constant::{APP_IMAGE, IMAGES_PATH};

use test_context::{test_context, AsyncTestContext};
use test_context::{AsyncTestContext, test_context};
use tokio::fs;
use uuid::Uuid;

Expand Down
2 changes: 1 addition & 1 deletion src/util/hash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use argon2::{
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
Argon2,
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString, rand_core::OsRng},
};

pub fn argon_hash(content: impl AsRef<str>) -> Result<String, argon2::password_hash::Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/util/password.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::hash;
use crate::error::{invalid_input_error, AppResult};
use crate::error::{AppResult, invalid_input_error};
use tracing::debug;

pub async fn hash(password: String) -> AppResult<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/util/random.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{distributions::Alphanumeric, Rng};
use rand::{Rng, distr::Alphanumeric};

pub fn generate_random_string(len: usize) -> String {
rand::thread_rng()
rand::rng()
.sample_iter(&Alphanumeric)
.take(len)
.map(char::from)
Expand Down
4 changes: 2 additions & 2 deletions src/util/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::error::AppResult;
use anyhow::anyhow;
use futures::stream::{SplitSink, SplitStream};
use futures::{SinkExt, StreamExt};
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde::de::DeserializeOwned;
use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};

Expand All @@ -23,7 +23,7 @@ where
T: Serialize,
{
sender
.send(Message::Text(serde_json::to_string(msg)?))
.send(Message::Text(serde_json::to_string(msg)?.into()))
.await?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/api/context/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::LazyLock;

use rustfulapi::{
client::database::{drop_database, migrate_database, setup_new_database, DatabaseClient},
client::database::{DatabaseClient, drop_database, migrate_database, setup_new_database},
configure::{AppConfig, Profile},
error::AppResult,
server::{self, state::AppState, worker::MessengerTask},
Expand All @@ -11,7 +11,7 @@ use tokio::task::JoinHandle;
use tracing::info;
use wiremock::MockServer;

use crate::helper::{api::Api, email::MailHogClient, INIT_SUBSCRIBER};
use crate::helper::{INIT_SUBSCRIBER, api::Api, email::MailHogClient};

#[allow(dead_code)]
pub struct AppTestContext {
Expand Down
2 changes: 1 addition & 1 deletion tests/api/helper/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ mod tests {
use fake::{Fake, Faker};
use rustfulapi::{
client::{
email::{EmailClient, EmailClientExt},
ClientBuilder,
email::{EmailClient, EmailClientExt},
},
constant::{CONFIG, TEMPLATE_ENGIN},
dto::{Email, Template},
Expand Down
2 changes: 1 addition & 1 deletion tests/api/helper/http.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use wiremock::{matchers::*, Request};
use wiremock::{Mock, MockServer, ResponseTemplate};
use wiremock::{Request, matchers::*};

#[allow(dead_code)]
pub async fn http_mock_server() -> MockServer {
Expand Down
2 changes: 1 addition & 1 deletion tests/api/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustfulapi::configure;
use std::sync::LazyLock;
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt};

pub mod api;
pub mod assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/api/user_endpoint_tests/test_user_active.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fake::{Fake, Faker};
use rustfulapi::dto::{request::*, LoginResponse};
use rustfulapi::dto::{LoginResponse, request::*};
use test_context::test_context;

use crate::{assert_ok, context::app::AppTestContext};
Expand Down

0 comments on commit 2a1048f

Please sign in to comment.