go through upload, create kb, add doc to kb (#11)

* add field progress msg into docinfo; add file processing procedure

* go through upload, create kb, add doc to kb
This commit is contained in:
KevinHuSh
2023-12-19 19:28:01 +08:00
committed by GitHub
parent d94c6df4a4
commit 249b27c1e0
24 changed files with 537 additions and 85 deletions

View File

@ -1,5 +1,5 @@
use chrono::Local;
use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder};
use sea_orm::{ActiveModelTrait, ColumnTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder, Unset, Unchanged, ConditionalStatement};
use sea_orm::ActiveValue::Set;
use sea_orm::QueryFilter;
use crate::api::doc_info::Params;
@ -24,6 +24,14 @@ impl Query {
.await
}
pub async fn find_doc_infos_by_name(db: &DbConn, uid: i64, name: String) -> Result<Vec<doc_info::Model>, DbErr> {
Entity::find()
.filter(doc_info::Column::DocName.eq(name))
.filter(doc_info::Column::Uid.eq(uid))
.all(db)
.await
}
pub async fn find_doc_infos_by_params(db: &DbConn, params: Params) -> Result<Vec<doc_info::Model>, DbErr> {
// Setup paginator
let paginator = Entity::find();
@ -80,18 +88,34 @@ impl Mutation {
dids: &[i64]
) -> Result<(), DbErr> {
for did in dids {
let d = doc2_doc::Entity::find().filter(doc2_doc::Column::Did.eq(did.to_owned())).all(db).await?;
let _ = doc2_doc::ActiveModel {
parent_id: Set(dest_did),
did: Set(*did),
id: Set(d[0].id),
did: Set(did.to_owned()),
parent_id: Set(dest_did)
}
.save(db)
.await
.unwrap();
.update(db)
.await?;
}
Ok(())
}
pub async fn place_doc(
db: &DbConn,
dest_did: i64,
did: i64
) -> Result<doc2_doc::ActiveModel, DbErr> {
doc2_doc::ActiveModel {
id: Default::default(),
parent_id: Set(dest_did),
did: Set(did),
}
.save(db)
.await
}
pub async fn create_doc_info(
db: &DbConn,
form_data: doc_info::Model,
@ -103,6 +127,7 @@ impl Mutation {
size: Set(form_data.size.to_owned()),
r#type: Set(form_data.r#type.to_owned()),
kb_progress: Set(form_data.kb_progress.to_owned()),
kb_progress_msg: Set(form_data.kb_progress_msg.to_owned()),
location: Set(form_data.location.to_owned()),
created_at: Set(Local::now().date_naive()),
updated_at: Set(Local::now().date_naive()),
@ -129,6 +154,7 @@ impl Mutation {
size: Set(form_data.size.to_owned()),
r#type: Set(form_data.r#type.to_owned()),
kb_progress: Set(form_data.kb_progress.to_owned()),
kb_progress_msg: Set(form_data.kb_progress_msg.to_owned()),
location: Set(form_data.location.to_owned()),
created_at: Default::default(),
updated_at: Set(Local::now().date_naive()),
@ -150,4 +176,4 @@ impl Mutation {
pub async fn delete_all_doc_infos(db: &DbConn) -> Result<DeleteResult, DbErr> {
Entity::delete_many().exec(db).await
}
}
}