11package com .booking .bot .service ;
22
33import com .booking .bot .adapter .BotAdapter ;
4+ import com .booking .bot .dto .OrganizationDto ;
45import com .booking .bot .dto .PersonDto ;
56import lombok .RequiredArgsConstructor ;
67import org .springframework .beans .factory .annotation .Autowired ;
@@ -27,64 +28,75 @@ public ChatServiceImpl(BotAdapter botAdapter, MenuService menuService) {
2728 }
2829
2930 Map <Long , String > chatState = new HashMap <>();
31+ Map <Long , String > chatData = new HashMap <>();
3032
3133 public SendMessage commandSwitch (Long userId , String command , Message message ) {
3234 String userName = message .getFrom ().getUserName ();
33- switch (command ) {
34- case "/start" -> {
35- botAdapter .addPerson (new PersonDto (userId , userName ), "/person" );
36- chatState .put (userId , "/start" );
37- return SendMessage .builder ()
38- .text ("Hi, " + userName + "! Сервис по бронированию." )
39- .chatId (message .getChatId ().toString ())
40- .replyMarkup (menuService .getKeyboard (chatState , message ,command ))
41- .build ();
42- }
43- case "/find" -> {
44- chatState .put (userId , "/types" );
45- return SendMessage .builder ()
46- .text ("Выбери тип организации:" )
47- .chatId (message .getChatId ().toString ())
48- .replyMarkup (menuService .getKeyboard (chatState , message ,command ))
49- .build ();
50- }
51- default -> {
52- return SendMessage .builder ()
53- .text ("Я не понимаю что ты хочешь от меня" )
54- .chatId (message .getChatId ().toString ())
55- .build ();
56- }
35+ if ("/start" .equals (command )) {
36+ botAdapter .addPerson (new PersonDto (userId , userName ), "/person" );
37+ chatState .put (userId , "main menu" );
38+ return SendMessage .builder ()
39+ .text ("Hi, " + userName + "! Сервис по бронированию." )
40+ .chatId (message .getChatId ().toString ())
41+ .replyMarkup (menuService .getKeyboard (chatState , message , command ))
42+ .build ();
5743 }
44+ return SendMessage .builder ()
45+ .text ("Я не понимаю что ты хочешь от меня" )
46+ .chatId (message .getChatId ().toString ())
47+ .build ();
5848 }
5949
6050 public EditMessageText commandSwitch (Long userId , String command , Message message , Integer lastMessageId ) {
6151 String userName = message .getFrom ().getUserName ();
6252 switch (command ) {
6353 case "/start" -> {
64- chatState .put (userId , "/start " );
54+ chatState .put (userId , "main menu " );
6555 return EditMessageText .builder ()
6656 .messageId (lastMessageId )
6757 .text ("Hi, " + userName + "! Сервис по бронированию." )
6858 .chatId (message .getChatId ().toString ())
69- .replyMarkup (menuService .getKeyboard (chatState , message ,command ))
59+ .replyMarkup (menuService .getKeyboard (chatState , message , command ))
7060 .build ();
7161 }
7262 case "/find" -> {
73- chatState .put (userId , "start > types " );
63+ chatState .put (userId , "choice of organization type " );
7464 return EditMessageText .builder ()
7565 .messageId (lastMessageId )
7666 .text ("Выбери тип организации:" )
7767 .chatId (message .getChatId ().toString ())
78- .replyMarkup (menuService .getKeyboard (chatState , message ,command ))
68+ .replyMarkup (menuService .getKeyboard (chatState , message , command ))
69+ .build ();
70+ }
71+ case "back from description" -> {
72+ chatState .put (userId ,"choice of organizations" );
73+ return EditMessageText .builder ()
74+ .messageId (lastMessageId )
75+ .text ("Выбери организацию:" )
76+ .chatId (message .getChatId ().toString ())
77+ .replyMarkup (menuService .getKeyboard (chatState , message , chatData .get (userId )))
7978 .build ();
8079 }
8180 default -> {
82- if ("types > organizations" .equals (chatState .get (userId ))) {
81+ if ("choice of organizations" .equals (chatState .get (userId ))) {
8382 return EditMessageText .builder ()
8483 .messageId (lastMessageId )
8584 .text ("Выбери организацию:" )
8685 .chatId (message .getChatId ().toString ())
87- .replyMarkup (menuService .getKeyboard (chatState , message ,command ))
86+ .replyMarkup (menuService .getKeyboard (chatState , message , command ))
87+ .build ();
88+ }
89+ if ("description of the organization" .equals (chatState .get (userId ))) {
90+ OrganizationDto organization = botAdapter .getOrganizationById ("/organization?id={id}" , command );
91+ chatData .put (userId ,organization .typeOrganization ());
92+ return EditMessageText .builder ()
93+ .messageId (lastMessageId )
94+ .text (organization .name () + ":" +
95+ "\n Рейтинг = " + organization .rating () +
96+ "\n Средний чек = " + organization .averageCheck () +
97+ "\n Расписание = " + organization .schedule ())
98+ .chatId (message .getChatId ().toString ())
99+ .replyMarkup (menuService .getKeyboard (chatState , message , command ))
88100 .build ();
89101 }
90102 return null ;
0 commit comments