From f241f2a81655c69221fbe5535b5c2516d6afc7ff Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Fri, 12 Aug 2022 02:50:45 +0200 Subject: [PATCH] add comments --- cmd/bot/main.go | 2 -- internal/data/channel.go | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/bot/main.go b/cmd/bot/main.go index c9e5abf..8d12c73 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -73,7 +73,6 @@ func main() { app.Logger.Errorw("Missing room-id in message tag", "roomId", roomId, ) - return } @@ -87,7 +86,6 @@ func main() { return } } - }) // Received a WhisperMessage (Twitch DM). diff --git a/internal/data/channel.go b/internal/data/channel.go index 8759275..0282552 100644 --- a/internal/data/channel.go +++ b/internal/data/channel.go @@ -18,6 +18,9 @@ type ChannelModel struct { DB *sql.DB } +// Get takes the login name for a channel and queries the database for an +// existing entry with that login value. If it exists it returns a +// pointer to a Channel. func (c ChannelModel) Get(login string) (*Channel, error) { query := ` SELECT id, added_at, login, twitchid @@ -45,6 +48,7 @@ func (c ChannelModel) Get(login string) (*Channel, error) { return &channel, nil } +// Insert takes in a channel struct and inserts it into the database. func (c ChannelModel) Insert(channel *Channel) error { query := ` INSERT INTO channels(login, twitchid) @@ -75,7 +79,7 @@ func (c ChannelModel) Insert(channel *Channel) error { return nil } -// GetAll() returns a slice of all channels in the database. +// GetAll() returns a pointer to a slice of all channels (`[]*Channel`) in the database. func (c ChannelModel) GetAll() ([]*Channel, error) { query := ` SELECT id, added_at, login, twitchid @@ -128,7 +132,7 @@ func (c ChannelModel) GetAll() ([]*Channel, error) { return channels, nil } -// GetAll() returns a slice of all channels in the database. +// GetJoinable() returns a slice of channel names (Channel.Login) in the database. func (c ChannelModel) GetJoinable() ([]string, error) { query := ` SELECT login @@ -178,6 +182,8 @@ func (c ChannelModel) GetJoinable() ([]string, error) { return channels, nil } +// Delete takes in a login name and queries the database and if there is an +// entry with that login name deletes the entry. func (c ChannelModel) Delete(login string) error { // Prepare the statement. query := `