KevinHuSh
commited on
Commit
·
8a65ad8
1
Parent(s):
1eb186a
add seed data generation (#13)
Browse files* merge upstream
* add seed data generation
- migration/Cargo.toml +1 -0
- migration/src/m20220101_000001_create_table.rs +53 -13
- src/api/user_info.rs +53 -2
- src/entity/kb2_doc.rs +0 -3
- src/entity/tag_info.rs +0 -7
- src/main.rs +0 -3
- src/service/tag_info.rs +5 -2
- src/service/user_info.rs +5 -2
migration/Cargo.toml
CHANGED
@@ -10,6 +10,7 @@ path = "src/lib.rs"
|
|
10 |
|
11 |
[dependencies]
|
12 |
async-std = { version = "1", features = ["attributes", "tokio1"] }
|
|
|
13 |
|
14 |
[dependencies.sea-orm-migration]
|
15 |
version = "0.12.0"
|
|
|
10 |
|
11 |
[dependencies]
|
12 |
async-std = { version = "1", features = ["attributes", "tokio1"] }
|
13 |
+
chrono = "0.4.31"
|
14 |
|
15 |
[dependencies.sea-orm-migration]
|
16 |
version = "0.12.0"
|
migration/src/m20220101_000001_create_table.rs
CHANGED
@@ -1,5 +1,9 @@
|
|
1 |
-
use sea_orm_migration::prelude
|
|
|
2 |
|
|
|
|
|
|
|
3 |
#[derive(DeriveMigrationName)]
|
4 |
pub struct Migration;
|
5 |
|
@@ -25,9 +29,9 @@ impl MigrationTrait for Migration {
|
|
25 |
.col(ColumnDef::new(UserInfo::ListStyle).string().default("list"))
|
26 |
.col(ColumnDef::new(UserInfo::Language).string().default("chinese"))
|
27 |
.col(ColumnDef::new(UserInfo::Password).string().not_null())
|
28 |
-
.col(ColumnDef::new(UserInfo::LastLoginAt).timestamp_with_time_zone())
|
29 |
-
.col(ColumnDef::new(UserInfo::CreatedAt).timestamp_with_time_zone().not_null())
|
30 |
-
.col(ColumnDef::new(UserInfo::UpdatedAt).timestamp_with_time_zone().not_null())
|
31 |
.col(ColumnDef::new(UserInfo::IsDeleted).boolean().default(false))
|
32 |
.to_owned(),
|
33 |
)
|
@@ -51,8 +55,8 @@ impl MigrationTrait for Migration {
|
|
51 |
.col(ColumnDef::new(TagInfo::Color).tiny_unsigned().default(1))
|
52 |
.col(ColumnDef::new(TagInfo::Icon).tiny_unsigned().default(1))
|
53 |
.col(ColumnDef::new(TagInfo::FolderId).big_integer())
|
54 |
-
.col(ColumnDef::new(TagInfo::CreatedAt).timestamp_with_time_zone().not_null())
|
55 |
-
.col(ColumnDef::new(TagInfo::UpdatedAt).timestamp_with_time_zone().not_null())
|
56 |
.col(ColumnDef::new(TagInfo::IsDeleted).boolean().default(false))
|
57 |
.to_owned(),
|
58 |
)
|
@@ -92,7 +96,7 @@ impl MigrationTrait for Migration {
|
|
92 |
.col(ColumnDef::new(Kb2Doc::Did).big_integer())
|
93 |
.col(ColumnDef::new(Kb2Doc::KbProgress).float().default(0))
|
94 |
.col(ColumnDef::new(Kb2Doc::KbProgressMsg).string().default(""))
|
95 |
-
.col(ColumnDef::new(Kb2Doc::UpdatedAt).timestamp_with_time_zone().not_null())
|
96 |
.col(ColumnDef::new(Kb2Doc::IsDeleted).boolean().default(false))
|
97 |
.to_owned(),
|
98 |
)
|
@@ -146,8 +150,8 @@ impl MigrationTrait for Migration {
|
|
146 |
.col(ColumnDef::new(KbInfo::Uid).big_integer().not_null())
|
147 |
.col(ColumnDef::new(KbInfo::KbName).string().not_null())
|
148 |
.col(ColumnDef::new(KbInfo::Icon).tiny_unsigned().default(1))
|
149 |
-
.col(ColumnDef::new(KbInfo::CreatedAt).timestamp_with_time_zone().not_null())
|
150 |
-
.col(ColumnDef::new(KbInfo::UpdatedAt).timestamp_with_time_zone().not_null())
|
151 |
.col(ColumnDef::new(KbInfo::IsDeleted).boolean().default(false))
|
152 |
.to_owned(),
|
153 |
)
|
@@ -167,8 +171,8 @@ impl MigrationTrait for Migration {
|
|
167 |
.col(ColumnDef::new(DocInfo::Location).string().not_null())
|
168 |
.col(ColumnDef::new(DocInfo::Size).big_integer().not_null())
|
169 |
.col(ColumnDef::new(DocInfo::Type).string().not_null()).comment("doc|folder")
|
170 |
-
.col(ColumnDef::new(DocInfo::CreatedAt).timestamp_with_time_zone().not_null())
|
171 |
-
.col(ColumnDef::new(DocInfo::UpdatedAt).timestamp_with_time_zone().not_null())
|
172 |
.col(ColumnDef::new(DocInfo::IsDeleted).boolean().default(false))
|
173 |
.to_owned(),
|
174 |
)
|
@@ -188,13 +192,49 @@ impl MigrationTrait for Migration {
|
|
188 |
.col(ColumnDef::new(DialogInfo::KbId).big_integer().not_null())
|
189 |
.col(ColumnDef::new(DialogInfo::DialogName).string().not_null())
|
190 |
.col(ColumnDef::new(DialogInfo::History).string().comment("json"))
|
191 |
-
.col(ColumnDef::new(DialogInfo::CreatedAt).timestamp_with_time_zone().not_null())
|
192 |
-
.col(ColumnDef::new(DialogInfo::UpdatedAt).timestamp_with_time_zone().not_null())
|
193 |
.col(ColumnDef::new(DialogInfo::IsDeleted).boolean().default(false))
|
194 |
.to_owned(),
|
195 |
)
|
196 |
.await?;
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
Ok(())
|
199 |
}
|
200 |
|
|
|
1 |
+
use sea_orm_migration::{prelude::*, sea_orm::Statement};
|
2 |
+
use chrono::{FixedOffset, Utc};
|
3 |
|
4 |
+
fn now()->chrono::DateTime<FixedOffset>{
|
5 |
+
Utc::now().with_timezone(&FixedOffset::east_opt(3600*8).unwrap())
|
6 |
+
}
|
7 |
#[derive(DeriveMigrationName)]
|
8 |
pub struct Migration;
|
9 |
|
|
|
29 |
.col(ColumnDef::new(UserInfo::ListStyle).string().default("list"))
|
30 |
.col(ColumnDef::new(UserInfo::Language).string().default("chinese"))
|
31 |
.col(ColumnDef::new(UserInfo::Password).string().not_null())
|
32 |
+
.col(ColumnDef::new(UserInfo::LastLoginAt).timestamp_with_time_zone().default(Expr::current_timestamp()))
|
33 |
+
.col(ColumnDef::new(UserInfo::CreatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
34 |
+
.col(ColumnDef::new(UserInfo::UpdatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
35 |
.col(ColumnDef::new(UserInfo::IsDeleted).boolean().default(false))
|
36 |
.to_owned(),
|
37 |
)
|
|
|
55 |
.col(ColumnDef::new(TagInfo::Color).tiny_unsigned().default(1))
|
56 |
.col(ColumnDef::new(TagInfo::Icon).tiny_unsigned().default(1))
|
57 |
.col(ColumnDef::new(TagInfo::FolderId).big_integer())
|
58 |
+
.col(ColumnDef::new(TagInfo::CreatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
59 |
+
.col(ColumnDef::new(TagInfo::UpdatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
60 |
.col(ColumnDef::new(TagInfo::IsDeleted).boolean().default(false))
|
61 |
.to_owned(),
|
62 |
)
|
|
|
96 |
.col(ColumnDef::new(Kb2Doc::Did).big_integer())
|
97 |
.col(ColumnDef::new(Kb2Doc::KbProgress).float().default(0))
|
98 |
.col(ColumnDef::new(Kb2Doc::KbProgressMsg).string().default(""))
|
99 |
+
.col(ColumnDef::new(Kb2Doc::UpdatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
100 |
.col(ColumnDef::new(Kb2Doc::IsDeleted).boolean().default(false))
|
101 |
.to_owned(),
|
102 |
)
|
|
|
150 |
.col(ColumnDef::new(KbInfo::Uid).big_integer().not_null())
|
151 |
.col(ColumnDef::new(KbInfo::KbName).string().not_null())
|
152 |
.col(ColumnDef::new(KbInfo::Icon).tiny_unsigned().default(1))
|
153 |
+
.col(ColumnDef::new(KbInfo::CreatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
154 |
+
.col(ColumnDef::new(KbInfo::UpdatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
155 |
.col(ColumnDef::new(KbInfo::IsDeleted).boolean().default(false))
|
156 |
.to_owned(),
|
157 |
)
|
|
|
171 |
.col(ColumnDef::new(DocInfo::Location).string().not_null())
|
172 |
.col(ColumnDef::new(DocInfo::Size).big_integer().not_null())
|
173 |
.col(ColumnDef::new(DocInfo::Type).string().not_null()).comment("doc|folder")
|
174 |
+
.col(ColumnDef::new(DocInfo::CreatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
175 |
+
.col(ColumnDef::new(DocInfo::UpdatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
176 |
.col(ColumnDef::new(DocInfo::IsDeleted).boolean().default(false))
|
177 |
.to_owned(),
|
178 |
)
|
|
|
192 |
.col(ColumnDef::new(DialogInfo::KbId).big_integer().not_null())
|
193 |
.col(ColumnDef::new(DialogInfo::DialogName).string().not_null())
|
194 |
.col(ColumnDef::new(DialogInfo::History).string().comment("json"))
|
195 |
+
.col(ColumnDef::new(DialogInfo::CreatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
196 |
+
.col(ColumnDef::new(DialogInfo::UpdatedAt).timestamp_with_time_zone().default(Expr::current_timestamp()).not_null())
|
197 |
.col(ColumnDef::new(DialogInfo::IsDeleted).boolean().default(false))
|
198 |
.to_owned(),
|
199 |
)
|
200 |
.await?;
|
201 |
|
202 |
+
let tm = now();
|
203 |
+
let root_insert = Query::insert()
|
204 |
+
.into_table(UserInfo::Table)
|
205 |
+
.columns([UserInfo::Email, UserInfo::Nickname, UserInfo::Password])
|
206 |
+
.values_panic([
|
207 |
+
"[email protected]".into(),
|
208 |
+
"root".into(),
|
209 |
+
"123456".into()
|
210 |
+
])
|
211 |
+
.to_owned();
|
212 |
+
|
213 |
+
let doc_insert = Query::insert()
|
214 |
+
.into_table(DocInfo::Table)
|
215 |
+
.columns([DocInfo::Uid, DocInfo::DocName, DocInfo::Size, DocInfo::Type,
|
216 |
+
DocInfo::Location])
|
217 |
+
.values_panic([
|
218 |
+
1.into(),
|
219 |
+
"/".into(),
|
220 |
+
0.into(),
|
221 |
+
"folder".into(),
|
222 |
+
"".into()
|
223 |
+
])
|
224 |
+
.to_owned();
|
225 |
+
|
226 |
+
let tag_insert = Query::insert()
|
227 |
+
.into_table(TagInfo::Table)
|
228 |
+
.columns([TagInfo::Uid, TagInfo::TagName, TagInfo::Regx, TagInfo::Color, TagInfo::Icon])
|
229 |
+
.values_panic([1.into(), "视频".into(),".*\\.(mpg|mpeg|avi|rm|rmvb|mov|wmv|asf|dat|asx|wvx|mpe|mpa)".into(),1.into(),1.into()])
|
230 |
+
.values_panic([1.into(), "图片".into(),".*\\.(png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|avif|apng)".into(),2.into(),2.into()])
|
231 |
+
.values_panic([1.into(), "音乐".into(),".*\\.(WAV|FLAC|APE|ALAC|WavPack|WV|MP3|AAC|Ogg|Vorbis|Opus)".into(),3.into(),3.into()])
|
232 |
+
.values_panic([1.into(), "文档".into(),".*\\.(pdf|doc|ppt|yml|xml|htm|json|csv|txt|ini|xsl|wps|rtf|hlp)".into(),3.into(),3.into()])
|
233 |
+
.to_owned();
|
234 |
+
|
235 |
+
manager.exec_stmt(root_insert).await?;
|
236 |
+
manager.exec_stmt(doc_insert).await?;
|
237 |
+
manager.exec_stmt(tag_insert).await?;
|
238 |
Ok(())
|
239 |
}
|
240 |
|
src/api/user_info.rs
CHANGED
@@ -1,15 +1,23 @@
|
|
1 |
use std::collections::HashMap;
|
2 |
-
|
|
|
3 |
use actix_identity::Identity;
|
4 |
use actix_web::{HttpResponse, post, web};
|
|
|
|
|
5 |
use serde::{Deserialize, Serialize};
|
6 |
use crate::api::JsonResponse;
|
7 |
use crate::AppState;
|
|
|
8 |
use crate::entity::user_info::Model;
|
9 |
use crate::errors::{AppError, UserError};
|
10 |
use crate::service::user_info::Mutation;
|
11 |
use crate::service::user_info::Query;
|
12 |
|
|
|
|
|
|
|
|
|
13 |
pub(crate) fn create_auth_token(user: &Model) -> u64 {
|
14 |
use std::{
|
15 |
collections::hash_map::DefaultHasher,
|
@@ -58,8 +66,51 @@ async fn login(
|
|
58 |
#[post("/v1.0/register")]
|
59 |
async fn register(model: web::Json<Model>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
60 |
let mut result = HashMap::new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
let usr = Mutation::create_user(&data.conn, &model).await?;
|
62 |
-
result.insert("uid", usr.uid.unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
let json_response = JsonResponse {
|
64 |
code: 200,
|
65 |
err: "".to_owned(),
|
|
|
1 |
use std::collections::HashMap;
|
2 |
+
use std::io::SeekFrom;
|
3 |
+
use std::ptr::null;
|
4 |
use actix_identity::Identity;
|
5 |
use actix_web::{HttpResponse, post, web};
|
6 |
+
use chrono::{FixedOffset, Utc};
|
7 |
+
use sea_orm::ActiveValue::NotSet;
|
8 |
use serde::{Deserialize, Serialize};
|
9 |
use crate::api::JsonResponse;
|
10 |
use crate::AppState;
|
11 |
+
use crate::entity::{doc_info, tag_info};
|
12 |
use crate::entity::user_info::Model;
|
13 |
use crate::errors::{AppError, UserError};
|
14 |
use crate::service::user_info::Mutation;
|
15 |
use crate::service::user_info::Query;
|
16 |
|
17 |
+
fn now()->chrono::DateTime<FixedOffset>{
|
18 |
+
Utc::now().with_timezone(&FixedOffset::east_opt(3600*8).unwrap())
|
19 |
+
}
|
20 |
+
|
21 |
pub(crate) fn create_auth_token(user: &Model) -> u64 {
|
22 |
use std::{
|
23 |
collections::hash_map::DefaultHasher,
|
|
|
66 |
#[post("/v1.0/register")]
|
67 |
async fn register(model: web::Json<Model>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
68 |
let mut result = HashMap::new();
|
69 |
+
let u = Query::find_user_infos(&data.conn, &model.email).await?;
|
70 |
+
if let Some(_) = u {
|
71 |
+
let json_response = JsonResponse {
|
72 |
+
code: 500,
|
73 |
+
err: "Email registered!".to_owned(),
|
74 |
+
data: (),
|
75 |
+
};
|
76 |
+
return Ok(HttpResponse::Ok()
|
77 |
+
.content_type("application/json")
|
78 |
+
.body(serde_json::to_string(&json_response)?));
|
79 |
+
}
|
80 |
+
|
81 |
let usr = Mutation::create_user(&data.conn, &model).await?;
|
82 |
+
result.insert("uid", usr.uid.clone().unwrap());
|
83 |
+
crate::service::doc_info::Mutation::create_doc_info(&data.conn, doc_info::Model{
|
84 |
+
did:Default::default(),
|
85 |
+
uid: usr.uid.clone().unwrap(),
|
86 |
+
doc_name: "/".into(),
|
87 |
+
size: 0,
|
88 |
+
location: "".into(),
|
89 |
+
r#type: "folder".to_string(),
|
90 |
+
created_at: now(),
|
91 |
+
updated_at: now(),
|
92 |
+
is_deleted:Default::default(),
|
93 |
+
}).await?;
|
94 |
+
let tnm = vec!["视频","图片","音乐","文档"];
|
95 |
+
let tregx = vec![
|
96 |
+
".*\\.(mpg|mpeg|avi|rm|rmvb|mov|wmv|asf|dat|asx|wvx|mpe|mpa)",
|
97 |
+
".*\\.(png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|avif|apng)",
|
98 |
+
".*\\.(WAV|FLAC|APE|ALAC|WavPack|WV|MP3|AAC|Ogg|Vorbis|Opus)",
|
99 |
+
".*\\.(pdf|doc|ppt|yml|xml|htm|json|csv|txt|ini|xsl|wps|rtf|hlp)"
|
100 |
+
];
|
101 |
+
for i in 0..4 {
|
102 |
+
crate::service::tag_info::Mutation::create_tag(&data.conn, tag_info::Model{
|
103 |
+
tid: Default::default(),
|
104 |
+
uid: usr.uid.clone().unwrap(),
|
105 |
+
tag_name: tnm[i].to_owned(),
|
106 |
+
regx: tregx[i].to_owned(),
|
107 |
+
color: (i+1).to_owned() as i16,
|
108 |
+
icon: (i+1).to_owned() as i16,
|
109 |
+
folder_id: 0,
|
110 |
+
created_at: Default::default(),
|
111 |
+
updated_at: Default::default(),
|
112 |
+
}).await?;
|
113 |
+
}
|
114 |
let json_response = JsonResponse {
|
115 |
code: 200,
|
116 |
err: "".to_owned(),
|
src/entity/kb2_doc.rs
CHANGED
@@ -11,7 +11,6 @@ pub struct Model {
|
|
11 |
pub kb_id: i64,
|
12 |
#[sea_orm(index)]
|
13 |
pub did: i64,
|
14 |
-
<<<<<<< HEAD
|
15 |
#[serde(skip_deserializing)]
|
16 |
pub kb_progress: f32,
|
17 |
#[serde(skip_deserializing)]
|
@@ -20,8 +19,6 @@ pub struct Model {
|
|
20 |
pub updated_at: DateTime<FixedOffset>,
|
21 |
#[serde(skip_deserializing)]
|
22 |
pub is_deleted: bool,
|
23 |
-
=======
|
24 |
-
>>>>>>> upstream/main
|
25 |
}
|
26 |
|
27 |
#[derive(Debug, Clone, Copy, EnumIter)]
|
|
|
11 |
pub kb_id: i64,
|
12 |
#[sea_orm(index)]
|
13 |
pub did: i64,
|
|
|
14 |
#[serde(skip_deserializing)]
|
15 |
pub kb_progress: f32,
|
16 |
#[serde(skip_deserializing)]
|
|
|
19 |
pub updated_at: DateTime<FixedOffset>,
|
20 |
#[serde(skip_deserializing)]
|
21 |
pub is_deleted: bool,
|
|
|
|
|
22 |
}
|
23 |
|
24 |
#[derive(Debug, Clone, Copy, EnumIter)]
|
src/entity/tag_info.rs
CHANGED
@@ -11,19 +11,12 @@ pub struct Model {
|
|
11 |
#[sea_orm(index)]
|
12 |
pub uid: i64,
|
13 |
pub tag_name: String,
|
14 |
-
<<<<<<< HEAD
|
15 |
#[serde(skip_deserializing)]
|
16 |
pub regx: String,
|
17 |
pub color: i16,
|
18 |
pub icon: i16,
|
19 |
#[serde(skip_deserializing)]
|
20 |
pub folder_id: i64,
|
21 |
-
=======
|
22 |
-
pub regx: Option<String>,
|
23 |
-
pub color: u16,
|
24 |
-
pub icon: u16,
|
25 |
-
pub dir: Option<String>,
|
26 |
-
>>>>>>> upstream/main
|
27 |
|
28 |
#[serde(skip_deserializing)]
|
29 |
pub created_at: DateTime<FixedOffset>,
|
|
|
11 |
#[sea_orm(index)]
|
12 |
pub uid: i64,
|
13 |
pub tag_name: String,
|
|
|
14 |
#[serde(skip_deserializing)]
|
15 |
pub regx: String,
|
16 |
pub color: i16,
|
17 |
pub icon: i16,
|
18 |
#[serde(skip_deserializing)]
|
19 |
pub folder_id: i64,
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
#[serde(skip_deserializing)]
|
22 |
pub created_at: DateTime<FixedOffset>,
|
src/main.rs
CHANGED
@@ -98,11 +98,8 @@ fn init(cfg: &mut web::ServiceConfig) {
|
|
98 |
cfg.service(api::kb_info::delete);
|
99 |
cfg.service(api::kb_info::list);
|
100 |
cfg.service(api::kb_info::add_docs_to_kb);
|
101 |
-
<<<<<<< HEAD
|
102 |
cfg.service(api::kb_info::anti_kb_docs);
|
103 |
cfg.service(api::kb_info::all_relevents);
|
104 |
-
=======
|
105 |
-
>>>>>>> upstream/main
|
106 |
|
107 |
cfg.service(api::doc_info::list);
|
108 |
cfg.service(api::doc_info::delete);
|
|
|
98 |
cfg.service(api::kb_info::delete);
|
99 |
cfg.service(api::kb_info::list);
|
100 |
cfg.service(api::kb_info::add_docs_to_kb);
|
|
|
101 |
cfg.service(api::kb_info::anti_kb_docs);
|
102 |
cfg.service(api::kb_info::all_relevents);
|
|
|
|
|
103 |
|
104 |
cfg.service(api::doc_info::list);
|
105 |
cfg.service(api::doc_info::delete);
|
src/service/tag_info.rs
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
use chrono::{FixedOffset, Utc};
|
2 |
use sea_orm::{ActiveModelTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder, ColumnTrait, QueryFilter};
|
3 |
-
use sea_orm::ActiveValue::Set;
|
4 |
use crate::entity::tag_info;
|
5 |
use crate::entity::tag_info::Entity;
|
6 |
|
@@ -51,7 +51,10 @@ impl Mutation {
|
|
51 |
regx: Set(form_data.regx.to_owned()),
|
52 |
color: Set(form_data.color.to_owned()),
|
53 |
icon: Set(form_data.icon.to_owned()),
|
54 |
-
folder_id:
|
|
|
|
|
|
|
55 |
created_at: Set(now()),
|
56 |
updated_at: Set(now()),
|
57 |
}
|
|
|
1 |
use chrono::{FixedOffset, Utc};
|
2 |
use sea_orm::{ActiveModelTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder, ColumnTrait, QueryFilter};
|
3 |
+
use sea_orm::ActiveValue::{Set, NotSet};
|
4 |
use crate::entity::tag_info;
|
5 |
use crate::entity::tag_info::Entity;
|
6 |
|
|
|
51 |
regx: Set(form_data.regx.to_owned()),
|
52 |
color: Set(form_data.color.to_owned()),
|
53 |
icon: Set(form_data.icon.to_owned()),
|
54 |
+
folder_id: match form_data.folder_id {
|
55 |
+
0 => NotSet,
|
56 |
+
_ => Set(form_data.folder_id.to_owned())
|
57 |
+
},
|
58 |
created_at: Set(now()),
|
59 |
updated_at: Set(now()),
|
60 |
}
|
src/service/user_info.rs
CHANGED
@@ -23,8 +23,11 @@ impl Query {
|
|
23 |
.await
|
24 |
}
|
25 |
|
26 |
-
pub async fn find_user_infos(db: &DbConn) -> Result<
|
27 |
-
Entity::find()
|
|
|
|
|
|
|
28 |
}
|
29 |
|
30 |
pub async fn find_user_infos_in_page(
|
|
|
23 |
.await
|
24 |
}
|
25 |
|
26 |
+
pub async fn find_user_infos(db: &DbConn, email:&String) -> Result<Option<user_info::Model>, DbErr> {
|
27 |
+
Entity::find()
|
28 |
+
.filter(user_info::Column::Email.eq(email))
|
29 |
+
.one(db)
|
30 |
+
.await
|
31 |
}
|
32 |
|
33 |
pub async fn find_user_infos_in_page(
|