fix: request first_name in user creation db function

it is required column in table
This commit is contained in:
Akulij 2025-04-10 20:46:23 +09:00
parent a9919a9307
commit 1006fbe5c1
3 changed files with 10 additions and 10 deletions

View File

@ -71,9 +71,8 @@ pub async fn secret_command_handler(
admin_password: String, admin_password: String,
) -> Result<(), teloxide::RequestError> { ) -> Result<(), teloxide::RequestError> {
println!("Admin Pass: {}", admin_password); println!("Admin Pass: {}", admin_password);
let user = db let tguser = msg.from.clone().unwrap();
.get_or_init_user(msg.from.clone().unwrap().id.0 as i64) let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
.await;
println!("MSG: {}", msg.html_text().unwrap()); println!("MSG: {}", msg.html_text().unwrap());
match cmd { match cmd {
SecretCommands::Secret { pass } => { SecretCommands::Secret { pass } => {

View File

@ -62,7 +62,7 @@ impl DB {
.unwrap(); .unwrap();
} }
pub async fn get_or_init_user(&mut self, userid: i64) -> User { pub async fn get_or_init_user(&mut self, userid: i64, firstname: &str) -> User {
use self::schema::users::dsl::*; use self::schema::users::dsl::*;
let connection = &mut self.pool.get().await.unwrap(); let connection = &mut self.pool.get().await.unwrap();
@ -76,7 +76,7 @@ impl DB {
match user { match user {
Some(existing_user) => existing_user, Some(existing_user) => existing_user,
None => diesel::insert_into(users) None => diesel::insert_into(users)
.values((id.eq(userid as i64), is_admin.eq(false))) .values((id.eq(userid as i64), is_admin.eq(false), first_name.eq(firstname)))
.get_result(connection) .get_result(connection)
.await .await
.unwrap(), .unwrap(),

View File

@ -97,7 +97,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.branch( .branch(
Update::filter_message() Update::filter_message()
.filter_async(async |msg: Message, mut db: DB| { .filter_async(async |msg: Message, mut db: DB| {
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await; let tguser = msg.from.unwrap();
let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
user.is_admin user.is_admin
}) })
.enter_dialogue::<Message, PostgresStorage<Json>, State>() .enter_dialogue::<Message, PostgresStorage<Json>, State>()
@ -248,7 +249,8 @@ fn command_handler(
.branch( .branch(
dptree::entry() dptree::entry()
.filter_async(async |msg: Message, mut db: DB| { .filter_async(async |msg: Message, mut db: DB| {
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await; let tguser = msg.from.unwrap();
let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
user.is_admin user.is_admin
}) })
.filter_command::<AdminCommands>() .filter_command::<AdminCommands>()
@ -262,9 +264,8 @@ async fn user_command_handler(
msg: Message, msg: Message,
cmd: UserCommands, cmd: UserCommands,
) -> Result<(), teloxide::RequestError> { ) -> Result<(), teloxide::RequestError> {
let user = db let tguser = msg.from.clone().unwrap();
.get_or_init_user(msg.from.clone().unwrap().id.0 as i64) let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
.await;
println!("MSG: {}", msg.html_text().unwrap()); println!("MSG: {}", msg.html_text().unwrap());
match cmd { match cmd {
UserCommands::Start => { UserCommands::Start => {