update
This commit is contained in:
1
.env
1
.env
@ -1,3 +1,2 @@
|
||||
DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin
|
||||
#UPLOAD_PATH=/var/www/uploads/caszl
|
||||
UPLOAD_PATH="/Volumes/iMac Doc/likeadmin-java"
|
||||
|
BIN
caszl-front-rs
Executable file
BIN
caszl-front-rs
Executable file
Binary file not shown.
@ -29,11 +29,11 @@ pub struct Model {
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::la_article_category::Entity",
|
||||
from = "Column::Cid",
|
||||
to = "super::la_article_category::Column::Id",
|
||||
belongs_to = "super::la_article_category::Entity",
|
||||
from = "Column::Cid",
|
||||
to = "super::la_article_category::Column::Id"
|
||||
)]
|
||||
LaArticleCategory
|
||||
LaArticleCategory,
|
||||
}
|
||||
|
||||
impl Related<super::la_article_category::Entity> for Entity {
|
||||
|
@ -19,7 +19,7 @@ pub struct Model {
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::la_article::Entity")]
|
||||
LaArticle
|
||||
LaArticle,
|
||||
}
|
||||
|
||||
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 app_state = AppState { db_conn, upload_path };
|
||||
let app_state = AppState {
|
||||
db_conn,
|
||||
upload_path,
|
||||
};
|
||||
|
||||
let app = routes::create_routes(Arc::new(app_state));
|
||||
Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
||||
|
@ -10,7 +10,7 @@ pub fn create_routes(app_state: Arc<AppState>) -> IntoMakeService<Router> {
|
||||
.nest(
|
||||
"/api",
|
||||
Router::new()
|
||||
.nest_service("/uploads",ServeDir::new(&app_state.upload_path))
|
||||
.nest_service("/uploads", ServeDir::new(&app_state.upload_path))
|
||||
.nest("/article", Router::new().route("/list", get(article_list)))
|
||||
.nest(
|
||||
"/pc",
|
||||
|
@ -11,7 +11,6 @@ use axum::Json;
|
||||
use chrono::{TimeZone, Utc};
|
||||
use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, QueryTrait};
|
||||
|
||||
|
||||
pub struct ArticleService {
|
||||
pub state: Arc<AppState>,
|
||||
}
|
||||
@ -33,13 +32,9 @@ 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 {
|
||||
Some(cid) => {
|
||||
query.filter(la_article::Column::Cid.eq(cid))
|
||||
}
|
||||
None => { query }
|
||||
}
|
||||
.apply_if(Some(params.cid), |mut 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,
|
||||
@ -79,7 +74,11 @@ impl ArticleService {
|
||||
let article_item = ArticleListItem {
|
||||
id: article.id,
|
||||
title: article.title,
|
||||
image: Some(article.image),
|
||||
image: Option::from(if article.image != "" {
|
||||
format!("/uploads/{}", article.image)
|
||||
} else {
|
||||
String::from("")
|
||||
}),
|
||||
intro: Some(article.intro),
|
||||
visit: article.visit,
|
||||
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::IsShow.eq(1))
|
||||
.one(&self.state.db_conn)
|
||||
@ -148,7 +148,7 @@ impl ArticleService {
|
||||
id: article.id,
|
||||
title: article.title,
|
||||
}),
|
||||
_ => None
|
||||
_ => None,
|
||||
};
|
||||
let next_result = la_article::Entity::find()
|
||||
.filter(la_article::Column::IsDelete.eq(0))
|
||||
@ -163,19 +163,23 @@ impl ArticleService {
|
||||
id: article.id,
|
||||
title: article.title,
|
||||
}),
|
||||
_ => None
|
||||
_ => None,
|
||||
};
|
||||
let article_detail = ArticleDetail {
|
||||
id: article.id,
|
||||
cid: Option::from(article.cid),
|
||||
category: match category {
|
||||
Some(category) => Some(category.name),
|
||||
None => None
|
||||
None => None,
|
||||
},
|
||||
title: article.title,
|
||||
intro: Option::from(article.intro),
|
||||
summary: article.summary,
|
||||
image: Option::from(article.image),
|
||||
image: Option::from(if article.image != "" {
|
||||
format!("/uploads/{}", article.image)
|
||||
} else {
|
||||
String::from("")
|
||||
}),
|
||||
content: article.content,
|
||||
author: article.author,
|
||||
visit: article.visit,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::service::artile::ArticleService;
|
||||
|
||||
pub struct ArticleState {
|
||||
pub article_service: ArticleService
|
||||
}
|
||||
pub article_service: ArticleService,
|
||||
}
|
||||
|
Reference in New Issue
Block a user