master
veypi 1 year ago
parent 72c864a854
commit f206d770ee

@ -22,7 +22,7 @@ thiserror = "1.0"
sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "mysql", "macros", "migrate", "chrono"] }
sea-orm = { version = "^0.12.0", features = [ "sqlx-mysql",
"runtime-tokio-rustls", "macros", "debug-print", "with-chrono",
"runtime-tokio-rustls", "macros", "with-chrono",
"with-json", "with-uuid" ] }

@ -5,15 +5,11 @@
// Distributed under terms of the MIT license.
//
use actix_web::{delete, get, post, web, Responder};
use actix_web::{get, web, Responder};
use proc::access_read;
use serde::{Deserialize, Serialize};
use tracing::info;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
use crate::{
models::{self, app_user},
AppState, Error, Result,
};
use crate::{models::app_user, AppState, Error, Result};
#[get("/app/{aid}/user/{uid}")]
#[access_read("app")]
@ -22,24 +18,28 @@ pub async fn get(
stat: web::Data<AppState>,
) -> Result<impl Responder> {
let (mut aid, mut uid) = params.into_inner();
let mut q = app_user::Entity::find();
if uid == "-" {
uid = "".to_string();
} else {
q = q.filter(app_user::Column::UserId.eq(uid.clone()));
}
if aid == "-" {
aid = "".to_string();
} else {
q = q.filter(app_user::Column::AppId.eq(aid.clone()));
}
let sql = format!("select * from app_user where");
info!("111|{}|{}|", aid, uid);
if uid.is_empty() && aid.is_empty() {
Err(Error::Missing("uid or aid".to_string()))
} else {
let s = sqlx::query_as::<_, app_user::Model>(
"select * from app_user where app_id = ? and user_id = ?",
)
.bind(aid)
.bind(uid)
.fetch_all(stat.sqlx())
.await?;
let s: Vec<app_user::Model> = q.all(stat.db()).await?;
// let s = sqlx::query_as::<_, app_user::Model>(
// "select * from app_user where app_id = ? and user_id = ?",
// )
// .bind(aid)
// .bind(uid)
// .fetch_all(stat.sqlx())
// .await?;
Ok(web::Json(s))
}
}

@ -37,24 +37,6 @@ pub async fn get(id: web::Path<String>, stat: web::Data<AppState>) -> Result<imp
#[access_read("user")]
pub async fn list(stat: web::Data<AppState>) -> Result<impl Responder> {
let res: Vec<user::Model> = user::Entity::find().all(stat.db()).await?;
// let result = sqlx::query!(
// "select id,updated,created,username,nickname,email,icon,status, used, space from user",
// )
// .map(|row| models::user::Model {
// id: row.id,
// created: row.created,
// updated: row.updated,
// username: row.username,
// nickname: row.nickname,
// email: row.email,
// status: row.status,
// used: row.used,
// space: row.space,
// icon: row.icon,
// ..Default::default()
// })
// .fetch_all(CONFIG.sqlx())
// .await?;
Ok(web::Json(res))
}
@ -154,8 +136,9 @@ values ( ?, ?, ? )
};
if i == 0 {
// let result: Vec<models::access::Model> = access::Entity::find().all(db).await?;
info!("asd");
let result = sqlx::query_as::<_, access::Model>(
"select access.name,access.rid,access.level from access, user_role, role WHERE user_role.user_id = ? && access.role_id=user_role.role_id && role.id=user_role.role_id && role.app_id = ?",
"select access.* from access, user_role, role WHERE user_role.user_id = ? && access.role_id=user_role.role_id && role.id=user_role.role_id && role.app_id = ?",
)
.bind(&u.id)
.bind(stat.uuid.clone())

@ -11,13 +11,17 @@
use std::{
fs::File,
io::{self, Read},
str::FromStr,
time::Duration,
};
use clap::{Args, Parser, Subcommand};
use lazy_static::lazy_static;
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use sqlx::{mysql::MySqlPoolOptions, Pool};
use sqlx::{
mysql::{MySqlConnectOptions, MySqlPoolOptions},
Pool,
};
use crate::Result;
@ -153,6 +157,7 @@ impl AppState {
"mysql://{}:{}@{}/{}",
self.db_user, self.db_pass, self.db_url, self.db_name
);
let p = MySqlPoolOptions::new()
.max_connections(5)
.connect_lazy(&url)?;
@ -170,6 +175,7 @@ impl AppState {
.connect_timeout(Duration::from_secs(8))
.acquire_timeout(Duration::from_secs(8))
.idle_timeout(Duration::from_secs(8))
.sqlx_logging(false)
.max_lifetime(Duration::from_secs(8));
self._db = Some(Database::connect(opt).await?);

@ -17,7 +17,6 @@ use thiserror::Error as ThisError;
use tracing::info;
pub type Result<T> = std::result::Result<T, Error>;
pub type JsonResult<T> = std::result::Result<JsonResponse<T>, Error>;
#[derive(Serialize, Deserialize)]
pub struct JsonResponse<T> {

Loading…
Cancel
Save