diff --git a/src/main/java/ru/cathub/telegabot/bot/KeyboardHelper.java b/src/main/java/ru/cathub/telegabot/bot/KeyboardHelper.java index 1f29c62..a4ed1bc 100644 --- a/src/main/java/ru/cathub/telegabot/bot/KeyboardHelper.java +++ b/src/main/java/ru/cathub/telegabot/bot/KeyboardHelper.java @@ -78,11 +78,12 @@ public class KeyboardHelper { row2.add(new KeyboardButton(EDIT_BOOKS)); KeyboardRow row3 = new KeyboardRow(); - row1.add(new KeyboardButton(SET_BOOKS_GOAL)); - row2.add(new KeyboardButton(BACK)); + row3.add(new KeyboardButton(SET_BOOKS_GOAL2)); + row3.add(new KeyboardButton(BACK)); keyboardRows.add(row1); keyboardRows.add(row2); + keyboardRows.add(row3); ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(keyboardRows); keyboardMarkup.setResizeKeyboard(true); diff --git a/src/main/java/ru/cathub/telegabot/service/ProfileService.java b/src/main/java/ru/cathub/telegabot/service/ProfileService.java index 17edc33..6395246 100644 --- a/src/main/java/ru/cathub/telegabot/service/ProfileService.java +++ b/src/main/java/ru/cathub/telegabot/service/ProfileService.java @@ -6,4 +6,6 @@ import ru.cathub.telegabot.exception.ServiceException; public interface ProfileService { void enterProfileEditingMode(BotUser user); void handleProfileUpdate(BotUser user, String input) throws ServiceException; + + void handleBooksGoalUpdate(BotUser user); } diff --git a/src/main/java/ru/cathub/telegabot/service/impl/ProfileServiceImpl.java b/src/main/java/ru/cathub/telegabot/service/impl/ProfileServiceImpl.java index dd84f4f..f58f5d1 100644 --- a/src/main/java/ru/cathub/telegabot/service/impl/ProfileServiceImpl.java +++ b/src/main/java/ru/cathub/telegabot/service/impl/ProfileServiceImpl.java @@ -10,7 +10,7 @@ import ru.cathub.telegabot.service.ProfileService; import ru.cathub.telegabot.service.TelegramClientService; import ru.cathub.telegabot.utils.Constants; -import java.util.Optional; +import static ru.cathub.telegabot.utils.Constants.SET_BOOKS_GOAL; @Service @RequiredArgsConstructor @@ -43,15 +43,17 @@ public class ProfileServiceImpl implements ProfileService { } } - private void handleBooksGoalUpdate(BotUser user) { + @Override + public void handleBooksGoalUpdate(BotUser user) { + user.setWorkingMode(BotUser.WorkingMode.EDIT_PROFILE); + userRepository.save(user); telegramClientService.sendMessage( user, - "Текущая цель: " + user.getBooksToRead() + "\nВведите новое количество книг:", - KeyboardHelper.getBackKeyboard() + "Текущая цель: " + user.getBooksToRead() + "\nВведите новое количество книг:" ); } - private void processFieldUpdate(BotUser user, String input) { + private void processFieldUpdate(BotUser user, String input) throws ServiceException { try { int goal = Integer.parseInt(input); if (goal < 0) throw new NumberFormatException(); diff --git a/src/main/java/ru/cathub/telegabot/service/impl/TelegramBotServiceImpl.java b/src/main/java/ru/cathub/telegabot/service/impl/TelegramBotServiceImpl.java index 00c5f47..d913781 100644 --- a/src/main/java/ru/cathub/telegabot/service/impl/TelegramBotServiceImpl.java +++ b/src/main/java/ru/cathub/telegabot/service/impl/TelegramBotServiceImpl.java @@ -51,7 +51,7 @@ public class TelegramBotServiceImpl implements TelegramBotService { bookManageService.processBookInput(botUser,text); break; case SET_BOOKS_GOAL: - profileService.handleProfileUpdate(botUser, text); + profileService.handleBooksGoalUpdate(botUser); break; default: switch (botUser.getWorkingMode()) {