Skip to content

Commit

Permalink
fix(Error): prevent actionj if task already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitroPodolsky committed Mar 3, 2024
1 parent a3116d6 commit b8e3962
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/telegram/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::db::{
insert_category, insert_homework, insert_user, select_all_categories, select_category,
insert_category, insert_homework, insert_user, select_all_categories, select_category, select_task,
};
use crate::models::{MyDialogue, State};
use crate::telegram::utils::{check_deadline, get_telegram_user_id, pages};
use teloxide::{
prelude::*,
requests::Requester,
types::{CallbackQuery, Message},
types::{InlineKeyboardButton, InlineKeyboardMarkup},
Bot,
};
use crate::telegram::utils::{check_deadline,pages,get_telegram_user_id};

pub async fn add(bot: Bot, dialogue: MyDialogue, msg: Message) -> crate::errors::Result<()> {
let categories = select_all_categories().unwrap();
Expand All @@ -30,7 +30,7 @@ pub async fn add(bot: Bot, dialogue: MyDialogue, msg: Message) -> crate::errors:
.reply_markup(InlineKeyboardMarkup::new(products))
.await?;

dialogue.update(State::ReceiveProductChoice).await?;
dialogue.update(State::ReceivAddChoice).await?;
return Ok(());
} else {
let mut products = categories[..4]
Expand All @@ -55,7 +55,7 @@ pub async fn add(bot: Bot, dialogue: MyDialogue, msg: Message) -> crate::errors:
.reply_markup(InlineKeyboardMarkup::new(products))
.await?;

dialogue.update(State::ReceiveProductChoice).await?;
dialogue.update(State::ReceivAddChoice).await?;
}

Ok(())
Expand Down Expand Up @@ -117,14 +117,20 @@ pub async fn send_taskname(
msg: Message,
category: String,
) -> crate::errors::Result<()> {
bot.send_message(dialogue.chat_id(), "Send description of the homework:")
.await?;
dialogue
.update(State::AddDescription {
category,
taskname: msg.text().unwrap().to_string(),
})
.await?;
if let Ok(_task) = select_task(msg.text().unwrap()) {
bot.send_message(dialogue.chat_id(), "Task already exists, Send another name")
.await?;
} else {
bot.send_message(dialogue.chat_id(), "Send description of the homework:")
.await?;
dialogue
.update(State::AddDescription {
category,
taskname: msg.text().unwrap().to_string(),
})
.await?;
}

Ok(())
}

Expand Down

0 comments on commit b8e3962

Please sign in to comment.