diff --git a/internal/api/response/ticker.go b/internal/api/response/ticker.go index 670d6caf..a1f9a846 100644 --- a/internal/api/response/ticker.go +++ b/internal/api/response/ticker.go @@ -41,6 +41,7 @@ type Twitter struct { type Telegram struct { Active bool `json:"active"` + Connected bool `json:"connected"` BotUsername string `json:"bot_username"` ChannelName string `json:"channel_name"` } @@ -86,6 +87,7 @@ func TickerResponse(t storage.Ticker, config config.Config) Ticker { }, Telegram: Telegram{ Active: t.Telegram.Active, + Connected: t.Telegram.Connected(), BotUsername: config.TelegramBotUser.UserName, ChannelName: t.Telegram.ChannelName, }, diff --git a/internal/api/tickers.go b/internal/api/tickers.go index 03e7efde..6104d288 100644 --- a/internal/api/tickers.go +++ b/internal/api/tickers.go @@ -188,14 +188,17 @@ func (h *handler) PutTickerTelegram(c *gin.Context) { return } - var tg storage.Telegram - err = c.Bind(&tg) + var body storage.Telegram + err = c.Bind(&body) if err != nil { c.JSON(http.StatusBadRequest, response.ErrorResponse(response.CodeNotFound, response.FormError)) return } - ticker.Telegram = tg + ticker.Telegram.Active = body.Active + if body.ChannelName != "" { + ticker.Telegram.ChannelName = body.ChannelName + } err = h.storage.SaveTicker(&ticker) if err != nil { diff --git a/internal/storage/ticker.go b/internal/storage/ticker.go index bc17d6c7..6b6f97df 100644 --- a/internal/storage/ticker.go +++ b/internal/storage/ticker.go @@ -75,6 +75,10 @@ func (tg *Telegram) Reset() { tg.ChannelName = "" } +func (tg *Telegram) Connected() bool { + return tg.ChannelName != "" +} + type Mastodon struct { Active bool `json:"active"` Server string `json:"server"`