update axum to 0.7
This commit is contained in:
5
.env
5
.env
@ -1,2 +1,3 @@
|
||||
DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin
|
||||
UPLOAD_PATH="/Volumes/iMac Doc/likeadmin-java"
|
||||
DATABASE_URL=mysql://cas:Root123456789.@localhost:3306/caszl
|
||||
UPLOAD_PATH=D:/Documents/中科云旧服务器备份/www/www/uploads/caszl
|
||||
PORT=3000
|
861
Cargo.lock
generated
861
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@ -6,13 +6,13 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
axum = "0.6.20"
|
||||
chrono = "0.4.31"
|
||||
axum = "0.7.4"
|
||||
chrono = "0.4.35"
|
||||
dotenvy = "0.15.7"
|
||||
hyper = { version = "0.14.27", features = ["full"] }
|
||||
sea-orm = { version = "0.12.4", features = ["sqlx-mysql", "runtime-tokio-native-tls", "macros"] }
|
||||
serde = { version = "1.0.192", features = ["derive"] }
|
||||
serde_json = "1.0.108"
|
||||
tokio = { version = "1.34.0", features = ["full"] }
|
||||
hyper = { version = "1.2.0", features = ["full"] }
|
||||
sea-orm = { version = "0.12.15", features = ["sqlx-mysql", "runtime-tokio-native-tls", "macros"] }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.114"
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
tower = "0.4.13"
|
||||
tower-http = { version = "0.4.4", features = ["fs"] }
|
||||
tower-http = { version = "0.5.2", features = ["fs"] }
|
||||
|
@ -1,17 +1,17 @@
|
||||
use crate::entity::la_article;
|
||||
|
||||
use crate::params::article::{ArticleDetailParams, ArticleListParams};
|
||||
use crate::state::app::AppState;
|
||||
use axum::extract::{Query, State};
|
||||
use axum::Json;
|
||||
use chrono::{TimeZone, Utc};
|
||||
use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, QueryTrait};
|
||||
use serde_json::{json, Value};
|
||||
use std::fmt::Debug;
|
||||
|
||||
|
||||
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::response::article::{ArticleDetail, ArticleListItem};
|
||||
use crate::response::common::{BaseResponse, PageResponse};
|
||||
use crate::service::artile::ArticleService;
|
||||
use crate::service::article::ArticleService;
|
||||
|
||||
pub async fn article_list(
|
||||
State(state): State<Arc<AppState>>,
|
||||
|
10
src/main.rs
10
src/main.rs
@ -9,18 +9,20 @@ mod service;
|
||||
mod state;
|
||||
|
||||
use crate::state::app::AppState;
|
||||
use axum::{Server, ServiceExt};
|
||||
|
||||
use sea_orm::Database;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenvy::dotenv().ok();
|
||||
let db_url = env::var("DATABASE_URL").expect(".env 文件中没有设置 DATABASE_URL");
|
||||
let upload_path = env::var("UPLOAD_PATH").expect(".env 文件中没有设置 UPLOAD_PATH");
|
||||
let port = env::var("PORT").expect(".env 文件中没有设置 PORT");
|
||||
|
||||
let db_conn = Database::connect(&db_url).await.expect("数据库链接失败");
|
||||
let db_conn = Database::connect(&db_url).await.expect("连接数据库失败");
|
||||
|
||||
let app_state = AppState {
|
||||
db_conn,
|
||||
@ -28,8 +30,8 @@ async fn main() {
|
||||
};
|
||||
|
||||
let app = routes::create_routes(Arc::new(app_state));
|
||||
Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
||||
.serve(app)
|
||||
let listener = TcpListener::bind(format!("0.0.0.0:{}", port))
|
||||
.await
|
||||
.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entity::la_article;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use axum::http::StatusCode;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
|
@ -1 +1 @@
|
||||
pub mod artile;
|
||||
pub mod article;
|
||||
|
@ -32,17 +32,14 @@ impl ArticleService {
|
||||
let articles_selection = la_article::Entity::find()
|
||||
.filter(la_article::Column::IsDelete.ne(1))
|
||||
.filter(la_article::Column::IsShow.ne(0))
|
||||
.apply_if(Some(params.cid), |mut query, v| match v {
|
||||
.apply_if(Some(params.cid), |query, v| match v {
|
||||
Some(cid) => query.filter(la_article::Column::Cid.eq(cid)),
|
||||
None => query,
|
||||
});
|
||||
let count = match articles_selection.clone().count(&self.state.db_conn).await {
|
||||
Ok(total) => total,
|
||||
Err(_) => 0,
|
||||
};
|
||||
let count = articles_selection.clone().count(&self.state.db_conn).await.unwrap_or_else(|_| 0);
|
||||
|
||||
let articles_result = articles_selection
|
||||
.apply_if(Some(params.sort), |mut query, v| {
|
||||
.apply_if(Some(params.sort), |query, v| {
|
||||
match v {
|
||||
Some(sort_str) => {
|
||||
// 最热
|
@ -1,4 +1,4 @@
|
||||
use crate::service::artile::ArticleService;
|
||||
use crate::service::article::ArticleService;
|
||||
|
||||
pub struct ArticleState {
|
||||
pub article_service: ArticleService,
|
||||
|
Reference in New Issue
Block a user