model: remove DeleteUserRequest

This commit is contained in:
Valentin Tolmer 2021-08-31 15:53:51 +02:00 committed by nitnelave
parent 0bcabc7d0c
commit 4af60e5668
4 changed files with 9 additions and 29 deletions

View File

@ -92,11 +92,6 @@ impl Default for User {
}
}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
pub struct DeleteUserRequest {
pub user_id: String,
}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct Group {
pub display_name: String,

View File

@ -3,7 +3,7 @@ use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
pub use lldap_model::{AddUserToGroupRequest, CreateGroupRequest, DeleteUserRequest, Group, User};
pub use lldap_model::{AddUserToGroupRequest, CreateGroupRequest, Group, User};
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
pub struct BindRequest {
@ -40,7 +40,7 @@ pub trait BackendHandler: Clone + Send {
async fn list_groups(&self) -> Result<Vec<Group>>;
async fn get_user_details(&self, user_id: &str) -> Result<User>;
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
async fn delete_user(&self, user_id: &str) -> Result<()>;
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
@ -58,7 +58,7 @@ mockall::mock! {
async fn list_groups(&self) -> Result<Vec<Group>>;
async fn get_user_details(&self, user_id: &str) -> Result<User>;
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()>;
async fn delete_user(&self, user_id: &str) -> Result<()>;
async fn create_group(&self, request: CreateGroupRequest) -> Result<i32>;
async fn get_user_groups(&self, user: &str) -> Result<HashSet<String>>;
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> Result<()>;

View File

@ -193,10 +193,10 @@ impl BackendHandler for SqlBackendHandler {
Ok(())
}
async fn delete_user(&self, request: DeleteUserRequest) -> Result<()> {
async fn delete_user(&self, user_id: &str) -> Result<()> {
let delete_query = Query::delete()
.from_table(Users::Table)
.and_where(Expr::col(Users::UserId).eq(request.user_id))
.and_where(Expr::col(Users::UserId).eq(user_id))
.to_string(DbQueryBuilder {});
sqlx::query(&delete_query).execute(&self.sql_pool).await?;
Ok(())
@ -517,12 +517,7 @@ mod tests {
insert_user(&handler, "Jennz", "boupBoup").await;
// Remove a user
let _request_result = handler
.delete_user(DeleteUserRequest {
user_id: "Jennz".to_owned(),
})
.await
.unwrap();
let _request_result = handler.delete_user("Jennz").await.unwrap();
let users = handler
.list_users(None)
@ -536,18 +531,8 @@ mod tests {
// Insert new user and remove two
insert_user(&handler, "NewBoi", "Joni").await;
let _request_result = handler
.delete_user(DeleteUserRequest {
user_id: "Hector".to_owned(),
})
.await
.unwrap();
let _request_result = handler
.delete_user(DeleteUserRequest {
user_id: "NewBoi".to_owned(),
})
.await
.unwrap();
let _request_result = handler.delete_user("Hector").await.unwrap();
let _request_result = handler.delete_user("NewBoi").await.unwrap();
let users = handler
.list_users(None)

View File

@ -31,7 +31,7 @@ mockall::mock! {
async fn get_user_details(&self, user_id: &str) -> DomainResult<User>;
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<String>>;
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
async fn delete_user(&self, request: DeleteUserRequest) -> DomainResult<()>;
async fn delete_user(&self, user_id: &str) -> DomainResult<()>;
async fn create_group(&self, request: CreateGroupRequest) -> DomainResult<i32>;
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> DomainResult<()>;
}