update
This commit is contained in:
1
.env
1
.env
@ -1,3 +1,2 @@
|
|||||||
DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin
|
DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin
|
||||||
#UPLOAD_PATH=/var/www/uploads/caszl
|
|
||||||
UPLOAD_PATH="/Volumes/iMac Doc/likeadmin-java"
|
UPLOAD_PATH="/Volumes/iMac Doc/likeadmin-java"
|
||||||
|
BIN
caszl-front-rs
Executable file
BIN
caszl-front-rs
Executable file
Binary file not shown.
@ -31,9 +31,9 @@ pub enum Relation {
|
|||||||
#[sea_orm(
|
#[sea_orm(
|
||||||
belongs_to = "super::la_article_category::Entity",
|
belongs_to = "super::la_article_category::Entity",
|
||||||
from = "Column::Cid",
|
from = "Column::Cid",
|
||||||
to = "super::la_article_category::Column::Id",
|
to = "super::la_article_category::Column::Id"
|
||||||
)]
|
)]
|
||||||
LaArticleCategory
|
LaArticleCategory,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Related<super::la_article_category::Entity> for Entity {
|
impl Related<super::la_article_category::Entity> for Entity {
|
||||||
|
@ -19,7 +19,7 @@ pub struct Model {
|
|||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
#[sea_orm(has_many = "super::la_article::Entity")]
|
#[sea_orm(has_many = "super::la_article::Entity")]
|
||||||
LaArticle
|
LaArticle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Related<super::la_article::Entity> for Entity {
|
impl Related<super::la_article::Entity> for Entity {
|
||||||
|
@ -22,7 +22,10 @@ async fn main() {
|
|||||||
|
|
||||||
let db_conn = Database::connect(&db_url).await.expect("数据库链接失败");
|
let db_conn = Database::connect(&db_url).await.expect("数据库链接失败");
|
||||||
|
|
||||||
let app_state = AppState { db_conn, upload_path };
|
let app_state = AppState {
|
||||||
|
db_conn,
|
||||||
|
upload_path,
|
||||||
|
};
|
||||||
|
|
||||||
let app = routes::create_routes(Arc::new(app_state));
|
let app = routes::create_routes(Arc::new(app_state));
|
||||||
Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
||||||
|
@ -11,7 +11,6 @@ use axum::Json;
|
|||||||
use chrono::{TimeZone, Utc};
|
use chrono::{TimeZone, Utc};
|
||||||
use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, QueryTrait};
|
use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, QueryTrait};
|
||||||
|
|
||||||
|
|
||||||
pub struct ArticleService {
|
pub struct ArticleService {
|
||||||
pub state: Arc<AppState>,
|
pub state: Arc<AppState>,
|
||||||
}
|
}
|
||||||
@ -33,13 +32,9 @@ impl ArticleService {
|
|||||||
let articles_selection = la_article::Entity::find()
|
let articles_selection = la_article::Entity::find()
|
||||||
.filter(la_article::Column::IsDelete.ne(1))
|
.filter(la_article::Column::IsDelete.ne(1))
|
||||||
.filter(la_article::Column::IsShow.ne(0))
|
.filter(la_article::Column::IsShow.ne(0))
|
||||||
.apply_if(Some(params.cid), |mut query, v| {
|
.apply_if(Some(params.cid), |mut query, v| match v {
|
||||||
match v {
|
Some(cid) => query.filter(la_article::Column::Cid.eq(cid)),
|
||||||
Some(cid) => {
|
None => query,
|
||||||
query.filter(la_article::Column::Cid.eq(cid))
|
|
||||||
}
|
|
||||||
None => { query }
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
let count = match articles_selection.clone().count(&self.state.db_conn).await {
|
let count = match articles_selection.clone().count(&self.state.db_conn).await {
|
||||||
Ok(total) => total,
|
Ok(total) => total,
|
||||||
@ -79,7 +74,11 @@ impl ArticleService {
|
|||||||
let article_item = ArticleListItem {
|
let article_item = ArticleListItem {
|
||||||
id: article.id,
|
id: article.id,
|
||||||
title: article.title,
|
title: article.title,
|
||||||
image: Some(article.image),
|
image: Option::from(if article.image != "" {
|
||||||
|
format!("/uploads/{}", article.image)
|
||||||
|
} else {
|
||||||
|
String::from("")
|
||||||
|
}),
|
||||||
intro: Some(article.intro),
|
intro: Some(article.intro),
|
||||||
visit: article.visit,
|
visit: article.visit,
|
||||||
collect: false,
|
collect: false,
|
||||||
@ -127,7 +126,8 @@ impl ArticleService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match la_article::Entity::find_by_id(id).find_also_related(la_article_category::Entity)
|
match la_article::Entity::find_by_id(id)
|
||||||
|
.find_also_related(la_article_category::Entity)
|
||||||
.filter(la_article::Column::IsDelete.eq(0))
|
.filter(la_article::Column::IsDelete.eq(0))
|
||||||
.filter(la_article::Column::IsShow.eq(1))
|
.filter(la_article::Column::IsShow.eq(1))
|
||||||
.one(&self.state.db_conn)
|
.one(&self.state.db_conn)
|
||||||
@ -148,7 +148,7 @@ impl ArticleService {
|
|||||||
id: article.id,
|
id: article.id,
|
||||||
title: article.title,
|
title: article.title,
|
||||||
}),
|
}),
|
||||||
_ => None
|
_ => None,
|
||||||
};
|
};
|
||||||
let next_result = la_article::Entity::find()
|
let next_result = la_article::Entity::find()
|
||||||
.filter(la_article::Column::IsDelete.eq(0))
|
.filter(la_article::Column::IsDelete.eq(0))
|
||||||
@ -163,19 +163,23 @@ impl ArticleService {
|
|||||||
id: article.id,
|
id: article.id,
|
||||||
title: article.title,
|
title: article.title,
|
||||||
}),
|
}),
|
||||||
_ => None
|
_ => None,
|
||||||
};
|
};
|
||||||
let article_detail = ArticleDetail {
|
let article_detail = ArticleDetail {
|
||||||
id: article.id,
|
id: article.id,
|
||||||
cid: Option::from(article.cid),
|
cid: Option::from(article.cid),
|
||||||
category: match category {
|
category: match category {
|
||||||
Some(category) => Some(category.name),
|
Some(category) => Some(category.name),
|
||||||
None => None
|
None => None,
|
||||||
},
|
},
|
||||||
title: article.title,
|
title: article.title,
|
||||||
intro: Option::from(article.intro),
|
intro: Option::from(article.intro),
|
||||||
summary: article.summary,
|
summary: article.summary,
|
||||||
image: Option::from(article.image),
|
image: Option::from(if article.image != "" {
|
||||||
|
format!("/uploads/{}", article.image)
|
||||||
|
} else {
|
||||||
|
String::from("")
|
||||||
|
}),
|
||||||
content: article.content,
|
content: article.content,
|
||||||
author: article.author,
|
author: article.author,
|
||||||
visit: article.visit,
|
visit: article.visit,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::service::artile::ArticleService;
|
use crate::service::artile::ArticleService;
|
||||||
|
|
||||||
pub struct ArticleState {
|
pub struct ArticleState {
|
||||||
pub article_service: ArticleService
|
pub article_service: ArticleService,
|
||||||
}
|
}
|
Reference in New Issue
Block a user