Skip to content

Commit

Permalink
调整控制台分页查询用户列表接口入参
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Dec 7, 2023
1 parent c65f27f commit bc2df1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/console/model/user_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ pub struct UserInfo {

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PageParams {
pub struct UserPageParams {
pub like_username: Option<String>,
pub offset: Option<i64>,
pub limit: Option<i64>,
pub is_rev: Option<bool>,
pub page_no: Option<usize>,
pub page_size: Option<usize>,
}

impl UserPageParams {
pub fn get_limit_info(&self) -> (usize, usize) {
let limit = self.page_size.unwrap_or(0xffff_ffff);
let offset = (self.page_no.unwrap_or(1) - 1) * limit;
(limit, offset)
}
}
9 changes: 5 additions & 4 deletions src/console/user_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
user::{model::UserDto, UserManagerReq, UserManagerResult},
};

use super::model::user_model::PageParams;
use super::model::user_model::UserPageParams;

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -81,12 +81,13 @@ pub async fn reset_password(

pub async fn get_user_page_list(
app: Data<Arc<AppShareData>>,
web::Query(param): web::Query<PageParams>,
web::Query(param): web::Query<UserPageParams>,
) -> actix_web::Result<impl Responder> {
let (limit, offset) = param.get_limit_info();
let msg = UserManagerReq::QueryPageList {
like_username: param.like_username,
offset: param.offset,
limit: param.limit,
offset: Some(offset as i64),
limit: Some(limit as i64),
is_rev: param.is_rev.unwrap_or_default(),
};
match app.user_manager.send(msg).await.unwrap().unwrap() {
Expand Down
4 changes: 3 additions & 1 deletion src/user/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ impl From<UserDo> for UserDto {
Self {
username: Arc::new(value.username),
nickname: Some(value.nickname),
password: Some(value.password),
//password: Some(value.password),
//不直接返回密码
password: None,
gmt_create: Some(value.gmt_create as i64 * 1000),
gmt_modified: Some(value.gmt_modified as i64 * 1000),
enable: Some(value.enable),
Expand Down

0 comments on commit bc2df1e

Please sign in to comment.