cid
This commit is contained in:
2
.env
2
.env
@ -1,2 +1,2 @@
|
|||||||
DATABASE_URL=mysql://kirara:kirara169482@localhost:3306/caszl
|
DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin
|
||||||
UPLOAD_PATH=D:/Downloads/upload_path
|
UPLOAD_PATH=D:/Downloads/upload_path
|
||||||
|
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -345,9 +345,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.83"
|
version = "1.0.84"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
@ -800,9 +800,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.9"
|
version = "0.2.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
|
checksum = "f95b9abcae896730d42b78e09c155ed4ddf82c07b4de772c64aee5b2d8b7c150"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"fnv",
|
"fnv",
|
||||||
@ -1595,9 +1595,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sea-orm"
|
name = "sea-orm"
|
||||||
version = "0.12.4"
|
version = "0.12.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14d17105eb8049488d2528580ecc3f0912ab177d600f10e8e292d6994870ba6a"
|
checksum = "978e782d3c035ddd588310cd025ae78cd78c795ce6e22981138f30c278e9681d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@ -1783,9 +1783,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signature"
|
name = "signature"
|
||||||
version = "2.1.0"
|
version = "2.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500"
|
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
|
@ -27,6 +27,19 @@ pub struct Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {}
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::la_article_category::Entity",
|
||||||
|
from = "Column::Cid",
|
||||||
|
to = "super::la_article_category::Column::Id",
|
||||||
|
)]
|
||||||
|
LaArticleCategory
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::la_article_category::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::LaArticleCategory.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
@ -17,6 +17,15 @@ 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")]
|
||||||
|
LaArticle
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::la_article::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::LaArticle.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::entity::la_article;
|
use crate::entity::la_article;
|
||||||
|
use crate::entity::la_article_category;
|
||||||
use crate::params::article::{ArticleDetailParams, ArticleListParams};
|
use crate::params::article::{ArticleDetailParams, ArticleListParams};
|
||||||
use crate::response::article::{ArticleDetail, ArticleListItem, SiblingArticle};
|
use crate::response::article::{ArticleDetail, ArticleListItem, SiblingArticle};
|
||||||
use crate::response::common::{BaseResponse, PageResponse};
|
use crate::response::common::{BaseResponse, PageResponse};
|
||||||
@ -31,7 +32,15 @@ impl ArticleService {
|
|||||||
let page_size = params.page_size.unwrap_or(20);
|
let page_size = params.page_size.unwrap_or(20);
|
||||||
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| {
|
||||||
|
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 {
|
let count = match articles_selection.clone().count(&self.state.db_conn).await {
|
||||||
Ok(total) => total,
|
Ok(total) => total,
|
||||||
Err(_) => 0,
|
Err(_) => 0,
|
||||||
@ -118,13 +127,13 @@ impl ArticleService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match la_article::Entity::find_by_id(id)
|
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)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(Some(article)) => {
|
Ok(Some((article, category))) => {
|
||||||
// 上一篇文章
|
// 上一篇文章
|
||||||
let prev_result = la_article::Entity::find()
|
let prev_result = la_article::Entity::find()
|
||||||
.filter(la_article::Column::IsDelete.eq(0))
|
.filter(la_article::Column::IsDelete.eq(0))
|
||||||
@ -159,7 +168,10 @@ impl ArticleService {
|
|||||||
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: None,
|
category: match category {
|
||||||
|
Some(category) => Some(category.name),
|
||||||
|
None => None
|
||||||
|
},
|
||||||
title: article.title,
|
title: article.title,
|
||||||
intro: Option::from(article.intro),
|
intro: Option::from(article.intro),
|
||||||
summary: article.summary,
|
summary: article.summary,
|
||||||
|
@ -1 +1,2 @@
|
|||||||
pub mod app;
|
pub mod app;
|
||||||
|
pub mod article;
|
||||||
|
5
src/state/article.rs
Normal file
5
src/state/article.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
use crate::service::artile::ArticleService;
|
||||||
|
|
||||||
|
pub struct ArticleState {
|
||||||
|
pub article_service: ArticleService
|
||||||
|
}
|
Reference in New Issue
Block a user