Skip to content

Commit

Permalink
Merge pull request #149 from systemli/adjust-put-telegram-api
Browse files Browse the repository at this point in the history
✨ Streamline Telegram Configuration API
  • Loading branch information
0x46616c6b authored Oct 14, 2022
2 parents 1a54ef5 + 329516a commit 6ae8695
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/api/response/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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,
},
Expand Down
9 changes: 6 additions & 3 deletions internal/api/tickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/storage/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 6ae8695

Please sign in to comment.