From: Jacob Casper Date: Fri, 17 Apr 2020 02:14:20 +0000 (-0500) Subject: Track artist popularity X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=30baa977ecf2af70a4be2b7ea49cc7ceefa3e4c5;p=brackets.git Track artist popularity --- diff --git a/migrations/005-alter_artist_add_popularity.sql b/migrations/005-alter_artist_add_popularity.sql new file mode 100644 index 0000000..fdd4e49 --- /dev/null +++ b/migrations/005-alter_artist_add_popularity.sql @@ -0,0 +1,3 @@ +ALTER TABLE ARTIST +ADD COLUMN POPULARITY INT NOT NULL DEFAULT 0 +CHECK (POPULARITY >= 0 AND POPULARITY <= 100); diff --git a/routes/artist/artist.go b/routes/artist/artist.go index 33122f5..d26f66d 100644 --- a/routes/artist/artist.go +++ b/routes/artist/artist.go @@ -24,12 +24,12 @@ func Index(env *env.Env) routes.Handler { if artistId != "" { artist := types.Artist{} row := env.Db.Db.QueryRow(` -SELECT ID, NAME +SELECT ID, NAME, POPULARITY FROM ARTIST WHERE ID = ?`, artistId, ) - if err := row.Scan(&artist.ID, &artist.Name); err != nil { + if err := row.Scan(&artist.ID, &artist.Name, &artist.Popularity); err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } @@ -44,7 +44,7 @@ WHERE ID = ?`, } rows, err := env.Db.Db.Query(` -SELECT ID, NAME +SELECT ID, NAME, POPULARITY FROM ARTIST LIMIT 20`, ) @@ -57,7 +57,7 @@ LIMIT 20`, artists := make([]types.Artist, 0) for rows.Next() { artist := types.Artist{} - if err := rows.Scan(&artist.ID, &artist.Name); err != nil { + if err := rows.Scan(&artist.ID, &artist.Name, &artist.Popularity); err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } @@ -104,10 +104,11 @@ func Add(env *env.Env) routes.Handler { defer env.Db.Mu.Unlock() env.Db.Db.Exec(` INSERT INTO ARTIST -(ID, NAME) -VALUES (?, ?)`, +(ID, NAME, POPULARITY) +VALUES (?, ?, ?)`, artist.ID, artist.Name, + artist.Popularity, ) for _, genre := range artist.Genres { @@ -183,7 +184,7 @@ WHERE g.NAME = lower(?) artists := make([]types.Artist, 0) for rows.Next() { artist := types.Artist{} - if err := rows.Scan(&artist.ID, &artist.Name); err != nil { + if err := rows.Scan(&artist.ID, &artist.Name, &artist.Popularity); err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return }