From 9cd11a7f37ebe5e568ca982fe0dcecb31c5146c7 Mon Sep 17 00:00:00 2001 From: matresnan <1358168412@qq.com> Date: Tue, 19 Aug 2025 23:04:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=8F=92=E5=85=A5=E5=8F=82=E6=95=B0=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93=E5=AE=9A=E4=B9=89=E5=B9=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=8F=8A=E5=86=97=E4=BD=99=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构代码以通过模块化导入使用InsertArgs结构体并移除重复定义。 - 优化数据库插入参数结构体定义并移除不必要的命名空间前缀以提升代码可读性和维护性。 --- src/db.rs | 11 ++--------- src/main.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/db.rs b/src/db.rs index f720416..71137f0 100644 --- a/src/db.rs +++ b/src/db.rs @@ -3,6 +3,8 @@ use serde::Serialize; use std::{fs, path::Path}; use welds::{connections::sqlite::SqliteClient, prelude::*}; +use crate::InsertArgs; + #[derive(WeldsModel, Clone, Serialize)] #[welds(table = "authorize")] pub struct Authorize { @@ -16,15 +18,6 @@ pub struct Authorize { pub insert_time: String, } -pub struct InsertArgs { - pub project: String, - pub token: String, - pub device_id: String, - pub disable: i8, - pub expire: String, - pub insert_time: String, -} - /// 包装类,内部持有 SQLite 连接 pub struct Db { client: SqliteClient, diff --git a/src/main.rs b/src/main.rs index 0ef72fa..dd8b0b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,7 +72,7 @@ async fn create_token( let token: String = state.generator.generate(16); let _token_id = state .db - .insert_authorize(db::InsertArgs { + .insert_authorize(InsertArgs { project: args.project.clone(), token: token.clone(), device_id: args.device_id.clone(), @@ -224,6 +224,15 @@ fn add_day(t: &str, days: i64) -> Result { Ok(new_time.format("%Y-%m-%d %H:%M:%S").to_string()) } +pub struct InsertArgs { + pub project: String, + pub token: String, + pub device_id: String, + pub disable: i8, + pub expire: String, + pub insert_time: String, +} + #[derive(Clone)] struct AppState { db: Arc,