diff --git a/internal/data/channel.go b/internal/data/channel.go index 7f85dc6..f66abbc 100644 --- a/internal/data/channel.go +++ b/internal/data/channel.go @@ -18,6 +18,33 @@ type ChannelModel struct { DB *sql.DB } +func (c ChannelModel) Get(login string) (*Channel, error) { + query := ` + SELECT id, added_at, login, twitchid + FROM channels + WHERE login = $1` + + var channel Channel + + err := c.DB.QueryRow(query, login).Scan( + &channel.ID, + &channel.AddedAt, + &channel.Login, + &channel.TwitchID, + ) + + if err != nil { + switch { + case errors.Is(err, sql.ErrNoRows): + return nil, ErrRecordNotFound + default: + return nil, err + } + } + + return &channel, nil +} + func (c ChannelModel) Insert(channel *Channel) error { query := ` INSERT INTO channels(login, twitchid) @@ -48,33 +75,6 @@ func (c ChannelModel) Insert(channel *Channel) error { return nil } -func (c ChannelModel) Get(login string) (*Channel, error) { - query := ` - SELECT id, added_at, login, twitchid - FROM channels - WHERE login = $1` - - var channel Channel - - err := c.DB.QueryRow(query, login).Scan( - &channel.ID, - &channel.AddedAt, - &channel.Login, - &channel.TwitchID, - ) - - if err != nil { - switch { - case errors.Is(err, sql.ErrNoRows): - return nil, ErrRecordNotFound - default: - return nil, err - } - } - - return &channel, nil -} - // GetAll() returns a slice of all channels in the database. func (c ChannelModel) GetAll() ([]*Channel, error) { query := `