|
4 | 4 | import com.booking.bot.dto.OrganizationDto; |
5 | 5 | import com.booking.bot.state.Context; |
6 | 6 | import com.booking.bot.state.Stage; |
7 | | -import com.fasterxml.jackson.core.JsonProcessingException; |
8 | | -import com.fasterxml.jackson.databind.ObjectMapper; |
9 | 7 | import lombok.RequiredArgsConstructor; |
| 8 | +import org.springframework.data.domain.Page; |
10 | 9 | import org.springframework.stereotype.Service; |
11 | 10 | import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; |
12 | 11 | import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton; |
@@ -48,25 +47,20 @@ public InlineKeyboardMarkup getOrganizationTypeKeyboard(Context context) { |
48 | 47 | } |
49 | 48 |
|
50 | 49 | public InlineKeyboardMarkup getChoiceOrganizationKeyboard(Context context) { |
| 50 | + //TODO: сделать кнопки страниц |
51 | 51 | List<List<InlineKeyboardButton>> rowList = new ArrayList<>(); |
52 | 52 | System.out.println(context.getCallbackData()); |
53 | | - System.out.println(botAdapter.getAllOrganizations()); |
54 | | -// List<OrganizationDto> organizationsByType = botAdapter.getAllOrganizationsByType(context.getCallbackData()); |
55 | | -// System.out.println(organizationsByType.toString()); |
56 | | -// long countOrganizations = organizationsByType.stream() |
57 | | -// .filter(o -> o.typeOrganization().equals(type)) |
58 | | -// .count(); |
59 | | -// List<InlineKeyboardButton> pagesButtonRow = new ArrayList<>(); |
60 | | -// long pages = countOrganizations >= 10 && countOrganizations % 10 == 0 ? countOrganizations / 10 : countOrganizations / 10 + 1; |
61 | | -// for (int i = 1; i <= pages; i++) { |
62 | | -// pagesButtonRow.add(InlineKeyboardButton.builder().text(String.valueOf(i)).callbackData(String.valueOf(i)).build()); |
63 | | -// } |
64 | | -// organizationsByType.forEach(organizationDto -> rowList.add( |
65 | | -// List.of(InlineKeyboardButton.builder() |
66 | | -// .text(organizationDto.name()) |
67 | | -// .callbackData(organizationDto.id().toString()) |
68 | | -// .build()))); |
69 | | -// rowList.add(pagesButtonRow); |
| 53 | + Page<OrganizationDto> organizationsByTypePage = botAdapter.getAllOrganizationsByType(context.getCallbackData()); |
| 54 | + List<InlineKeyboardButton> pagesButtonRow = new ArrayList<>(); |
| 55 | + for (int i = 1; i <= organizationsByTypePage.getTotalPages(); i++) { |
| 56 | + pagesButtonRow.add(InlineKeyboardButton.builder().text(String.valueOf(i)).callbackData(String.valueOf(i)).build()); |
| 57 | + } |
| 58 | + organizationsByTypePage.getContent().forEach(organizationDto -> rowList.add( |
| 59 | + List.of(InlineKeyboardButton.builder() |
| 60 | + .text(organizationDto.name()) |
| 61 | + .callbackData(organizationDto.id().toString()) |
| 62 | + .build()))); |
| 63 | + rowList.add(pagesButtonRow); |
70 | 64 | rowList.add(List.of(InlineKeyboardButton.builder() |
71 | 65 | .text("<< Назад") |
72 | 66 | .callbackData("TYPE") |
|
0 commit comments