|
6 | 6 | import com.booking.bot.state.Context; |
7 | 7 | import com.booking.bot.state.Stage; |
8 | 8 | import com.fasterxml.jackson.core.JsonProcessingException; |
9 | | -import com.fasterxml.jackson.databind.ObjectMapper; |
10 | 9 | import lombok.RequiredArgsConstructor; |
11 | 10 | import org.springframework.stereotype.Service; |
12 | 11 | import org.telegram.telegrambots.meta.api.methods.send.SendMessage; |
|
18 | 17 | public class ChatServiceImpl implements ChatService { |
19 | 18 | private final MenuService menuService; |
20 | 19 | private final BotAdapter botAdapter; |
21 | | - public SendMessage sendMessage(Context context,Message message) throws JsonProcessingException { |
| 20 | + |
| 21 | + public SendMessage sendMessage(Context context, Message message) throws JsonProcessingException { |
22 | 22 | Long userId = message.getFrom().getId(); |
23 | 23 | String userName = message.getFrom().getUserName(); |
24 | 24 | if (context.getStage().equals(Stage.MAIN)) { |
@@ -55,35 +55,33 @@ public EditMessageText editMessageText(Context context, Message message) throws |
55 | 55 | .build(); |
56 | 56 | } |
57 | 57 | case ORGANIZATIONS -> { |
| 58 | + if (context.getBeforeStage() == Stage.TYPE) { |
| 59 | + context.setType(context.getCallbackData()); |
| 60 | + context.setPage(0); |
| 61 | + context.setBeforeStage(Stage.ORGANIZATIONS); |
| 62 | + } else { |
| 63 | + context.setPage(Integer.parseInt(context.getCallbackData())); |
| 64 | + } |
| 65 | + return EditMessageText.builder() |
| 66 | + .messageId(context.getMessageId()) |
| 67 | + .text("Выбери организацию:") |
| 68 | + .chatId(message.getChatId().toString()) |
| 69 | + .replyMarkup(menuService.getChoiceOrganizationKeyboard(context)) |
| 70 | + .build(); |
| 71 | + } |
| 72 | + case DESCRIPTION -> { |
| 73 | + OrganizationDto organization = botAdapter.getOrganizationById(context.getCallbackData()); |
58 | 74 | return EditMessageText.builder() |
59 | 75 | .messageId(context.getMessageId()) |
60 | | - .text("Выбери организацию:") |
| 76 | + .text(organization.name() + ":" + |
| 77 | + "\nРейтинг = " + organization.rating() + |
| 78 | + "\nСредний чек = " + organization.averageCheck() + |
| 79 | + "\nРасписание = " + organization.schedule()) |
61 | 80 | .chatId(message.getChatId().toString()) |
62 | | - .replyMarkup(menuService.getChoiceOrganizationKeyboard(context)) |
| 81 | + .replyMarkup(menuService.getDescriptionOrganizationKeyboard(context)) |
63 | 82 | .build(); |
64 | 83 | } |
65 | 84 | default -> { |
66 | | -// if ("choice of organizations".equals(chatState.get(userId))) { |
67 | | -// return EditMessageText.builder() |
68 | | -// .messageId(lastMessageId) |
69 | | -// .text("Выбери организацию:") |
70 | | -// .chatId(message.getChatId().toString()) |
71 | | -// .replyMarkup(menuService.getKeyboard(chatState, message, command)) |
72 | | -// .build(); |
73 | | -// } |
74 | | -// if ("description of the organization".equals(chatState.get(userId))) { |
75 | | -// OrganizationDto organization = botAdapter.getOrganizationById(command); |
76 | | -// chatData.put(userId, organization.typeOrganization()); |
77 | | -// return EditMessageText.builder() |
78 | | -// .messageId(lastMessageId) |
79 | | -// .text(organization.name() + ":" + |
80 | | -// "\nРейтинг = " + organization.rating() + |
81 | | -// "\nСредний чек = " + organization.averageCheck() + |
82 | | -// "\nРасписание = " + organization.schedule()) |
83 | | -// .chatId(message.getChatId().toString()) |
84 | | -// .replyMarkup(menuService.getKeyboard(chatState, message, command)) |
85 | | -// .build(); |
86 | | -// } |
87 | 85 | return null; |
88 | 86 | } |
89 | 87 | } |
|
0 commit comments