From 696c3dce5b184ae8c6effec4e7024cf56bf1b1ae Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 25 Jun 2017 18:41:45 -0400 Subject: add tracking of clients --- data.go | 15 +++++++++++++++ migrations/20170625140530_client.sql | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 migrations/20170625140530_client.sql diff --git a/data.go b/data.go index 4897665..ba3157b 100644 --- a/data.go +++ b/data.go @@ -61,9 +61,16 @@ type LoveImport struct { Count int } +type Client struct { + Key string + Secret string + Name string +} + type DataStore interface { PutSession(*Session) error GetSession(key string) (*Session, error) + GetClient(key string) (*Client, error) PutScrobbles([]Scrobble) error PutNowPlaying(s Scrobble) error NowPlaying(userId int) *Scrobble @@ -114,6 +121,14 @@ func (store *SqlStore) GetSession(key string) (*Session, error) { return s, err } +func (store *SqlStore) GetClient(key string) (*Client, error) { + query := `SELECT secret, name FROM clients WHERE key = $1` + row := store.QueryRow(query, key) + c := &Client{Key: key} + err := row.Scan(&c.Secret, &c.Name) + return c, err +} + func (store *SqlStore) GetScrobblingUser(lfmName string) (int, string, error) { var password string var userId int diff --git a/migrations/20170625140530_client.sql b/migrations/20170625140530_client.sql new file mode 100644 index 0000000..b872526 --- /dev/null +++ b/migrations/20170625140530_client.sql @@ -0,0 +1,12 @@ + +-- +goose Up +-- SQL in section 'Up' is executed when this migration is applied +CREATE TABLE clients ( + key text PRIMARY KEY, + secret text, + name text +); + +-- +goose Down +-- SQL section 'Down' is executed when this migration is rolled back +DROP TABLE clients; -- cgit v1.2.3-70-g09d2