Can update account information

This commit is contained in:
2025-04-07 21:13:36 +02:00
parent 559eadfd05
commit 1977b5209c
3 changed files with 32 additions and 19 deletions

View File

@ -1,4 +1,5 @@
use crate::connections::db_connection::db;
use crate::controllers::server_controller::ServerConstraints;
use crate::models::accounts::{Account, AccountID, NewAccount};
use crate::models::users::UserID;
use crate::schema::accounts;
@ -11,6 +12,18 @@ pub struct UpdateAccountQuery {
pub name: String,
}
impl UpdateAccountQuery {
pub fn check_error(&self) -> Option<&'static str> {
let constraints = ServerConstraints::default();
if !constraints.account_name.check_str(&self.name) {
return Some("Invalid account name length!");
}
None
}
}
/// Create a new account
pub async fn create(user_id: UserID, query: &UpdateAccountQuery) -> anyhow::Result<Account> {
let new_account = NewAccount {