From e8b90e385c68e5c964bd49a861f7d26bd2fe7ace Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sun, 5 Mar 2023 18:28:14 +0000 Subject: [PATCH] remove unused lastfm models and migrations --- internal/data/lastfm.go | 72 ------------------- internal/data/models.go | 13 ++-- .../000005_create_lastfm_table.down.sql | 1 - migrations/000005_create_lastfm_table.up.sql | 10 --- 4 files changed, 4 insertions(+), 92 deletions(-) delete mode 100644 internal/data/lastfm.go delete mode 100644 migrations/000005_create_lastfm_table.down.sql delete mode 100644 migrations/000005_create_lastfm_table.up.sql diff --git a/internal/data/lastfm.go b/internal/data/lastfm.go deleted file mode 100644 index 033c898..0000000 --- a/internal/data/lastfm.go +++ /dev/null @@ -1,72 +0,0 @@ -package data - -import ( - "database/sql" - "errors" -) - -type LastFMUser struct { - ID int `json:"id"` - TwitchLogin string `json:"twitch_login"` - TwitchID string `json:"twitch_id"` - LastFMUser string `json:"lastfm_username"` -} - -type LastFMUserModel struct { - DB *sql.DB -} - -func (l LastFMUserModel) Get(login string) (*LastFMUser, error) { - query := ` - SELECT id, twitch_login, twitch_id, lastfm_username - FROM lastfm_users - WHERE twitch_login = $1` - - var lastfm LastFMUser - - err := l.DB.QueryRow(query, login).Scan( - &lastfm.ID, - &lastfm.TwitchLogin, - &lastfm.TwitchID, - &lastfm.LastFMUser, - ) - - if err != nil { - switch { - case errors.Is(err, sql.ErrNoRows): - return nil, ErrRecordNotFound - default: - return nil, err - } - } - - return &lastfm, nil -} - -func (l LastFMUserModel) Insert(lastfm *LastFMUser) error { - query := ` - INSERT into lastfm_users(twitch_login, twitch_id, lastfm_username) - VALUES ($1, $2, $3) - ON CONFLICT (twitch_id) - DO NOTHING - RETURNING id; - ` - - args := []interface{}{lastfm.TwitchLogin, lastfm.TwitchID, lastfm.LastFMUser} - - result, err := l.DB.Exec(query, args...) - if err != nil { - return err - } - - rowsAffected, err := result.RowsAffected() - if err != nil { - return err - } - - if rowsAffected == 0 { - return ErrLastFMUserRecordAlreadyExists - } - - return nil -} diff --git a/internal/data/models.go b/internal/data/models.go index db76d03..060b93b 100644 --- a/internal/data/models.go +++ b/internal/data/models.go @@ -43,10 +43,6 @@ type Models struct { SetHelp(name, helptext string) error Delete(name string) error } - LastFMUsers interface { - Get(name string) (*LastFMUser, error) - Insert(lastfm *LastFMUser) error - } Timers interface { Get(name string) (*Timer, error) Insert(timer *Timer) error @@ -58,10 +54,9 @@ type Models struct { func NewModels(db *sql.DB) Models { return Models{ - Channels: ChannelModel{DB: db}, - Users: UserModel{DB: db}, - Commands: CommandModel{DB: db}, - LastFMUsers: LastFMUserModel{DB: db}, - Timers: TimerModel{DB: db}, + Channels: ChannelModel{DB: db}, + Users: UserModel{DB: db}, + Commands: CommandModel{DB: db}, + Timers: TimerModel{DB: db}, } } diff --git a/migrations/000005_create_lastfm_table.down.sql b/migrations/000005_create_lastfm_table.down.sql deleted file mode 100644 index 1e5e721..0000000 --- a/migrations/000005_create_lastfm_table.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS lastfm_users; diff --git a/migrations/000005_create_lastfm_table.up.sql b/migrations/000005_create_lastfm_table.up.sql deleted file mode 100644 index 2143600..0000000 --- a/migrations/000005_create_lastfm_table.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE IF NOT EXISTS lastfm_users ( - id bigserial PRIMARY KEY, - twitch_login text NOT NULL, - twitch_id text UNIQUE NOT NULL, - lastfm_username text NOT NULL -); - -INSERT INTO lastfm_users (twitch_login,twitch_id,lastfm_username) VALUES - ('nourylul','31437432','nouryqt'); -