From 2abb18cb49466cedc8539585dafd7aaad5465a95 Mon Sep 17 00:00:00 2001 From: Akulij Date: Mon, 5 May 2025 19:41:11 +0300 Subject: [PATCH] get events for start buttons from database instead of hardcoded ones --- cmd/app/main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd/app/main.go b/cmd/app/main.go index 7fbc51c..30ec502 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -227,11 +227,24 @@ func handleChannelPost(bc BotController, update tgbotapi.Update) { func handleStartCommand(bc BotController, update tgbotapi.Update, user User) { bc.db.Model(&user).Update("state", "start") rows := [][]tgbotapi.InlineKeyboardButton{} - for _, d := range nearestDates { - k, v := getDateButton(d) + events, _ := bc.GetAllEvents() + for _, event := range events { + if event.Date.Sub(time.Now()) < 2*time.Hour { + continue + } + k, _ := getDateButton(*event.Date) + taken, _ := bc.CountReservationsByEventID(event.ID) + k = strings.Join([]string{ + k, + "(" + strconv.FormatInt(taken, 10) + "/" + strconv.Itoa(seatscnt) + ")", + }, " ") + if taken == seatscnt { + k += " (Распродано)" + } + token := "reservedate:" + strconv.FormatInt(event.ID, 10) rows = append(rows, tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData(k, v), + tgbotapi.NewInlineKeyboardButtonData(k, token), ), ) }