diff --git a/TODOS.md b/TODOS.md index baec18c..a3bd974 100644 --- a/TODOS.md +++ b/TODOS.md @@ -63,4 +63,6 @@ These errors should encompass: - Wrong Data / Not Authorized and other 400 base - Not Found Error: for 404s - Internal Errors: for 500s - \ No newline at end of file + +Repository functions also need to be redesigned to be Results. + diff --git a/src/admin_examples/user_repository.rs b/src/admin_examples/user_repository.rs index af3745f..a44d41a 100644 --- a/src/admin_examples/user_repository.rs +++ b/src/admin_examples/user_repository.rs @@ -34,7 +34,16 @@ impl AdminRepository for UserRepository { name: "User", lookup_key: "id", display_list: &["id", "username"], - fields: &["username", "description"], + fields: &[ + "username", + "first_name", + "last_name", + "email", + "is_staff", + "is_active", + "is_superuser", + ], + // fields_readonly: &["last_login", "date_joined"] } .into() } @@ -93,6 +102,30 @@ impl AdminRepository for UserRepository { user.password = Set(value.as_str().unwrap().to_owned()); } + if let Some(value) = data.get("first_name") { + user.first_name = Set(value.as_str().map(|s| s.to_owned())); + } + + if let Some(value) = data.get("last_name") { + user.last_name = Set(value.as_str().map(|s| s.to_owned())); + } + + if let Some(value) = data.get("email") { + user.email = Set(value.as_str().map(|s| s.to_owned())); + } + + if let Some(value) = data.get("is_staff") { + user.is_staff = Set(value.as_bool().unwrap_or(false)); + } + + if let Some(value) = data.get("is_active") { + user.is_active = Set(value.as_bool().unwrap_or(false)); + } + + if let Some(value) = data.get("is_superuser") { + user.is_superuser = Set(value.as_bool().unwrap_or(false)); + } + if let Ok(user) = user.insert(&self.connection).await { let id = user.id.to_string(); return Some(model.build_item(&*id, serde_json::to_value(&user).unwrap()));