start saving stars
This commit is contained in:
parent
517e147028
commit
c7af853358
|
@ -310,3 +310,13 @@ class PysonicApi(object):
|
||||||
tag.append(folder)
|
tag.append(folder)
|
||||||
yield doc.prettify()
|
yield doc.prettify()
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def star_view(self, id, **kwargs):
|
||||||
|
self.library.set_starred(cherrypy.request.login, int(id), starred=True)
|
||||||
|
print(cherrypy.request.login)
|
||||||
|
yield self.response()[0].prettify()
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def unstar_view(self, id, **kwargs):
|
||||||
|
self.library.set_starred(cherrypy.request.login, int(id), starred=False)
|
||||||
|
yield self.response()[0].prettify()
|
||||||
|
|
|
@ -73,6 +73,15 @@ class PysonicDatabase(object):
|
||||||
'email' TEXT)"""
|
'email' TEXT)"""
|
||||||
cursor.execute(users_table)
|
cursor.execute(users_table)
|
||||||
version = 1
|
version = 1
|
||||||
|
if version < 2:
|
||||||
|
logging.warning("migrating database to v2 from %s", version)
|
||||||
|
users_table = """CREATE TABLE 'stars' (
|
||||||
|
'userid' INTEGER,
|
||||||
|
'nodeid' INTEGER,
|
||||||
|
primary key ('userid', 'nodeid'))"""
|
||||||
|
cursor.execute(users_table)
|
||||||
|
version = 2
|
||||||
|
|
||||||
cursor.execute("""UPDATE meta SET value=? WHERE key="db_version";""", (str(version), ))
|
cursor.execute("""UPDATE meta SET value=? WHERE key="db_version";""", (str(version), ))
|
||||||
logging.warning("db schema is version {}".format(version))
|
logging.warning("db schema is version {}".format(version))
|
||||||
|
|
||||||
|
@ -154,3 +163,10 @@ class PysonicDatabase(object):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise NotFoundError("User doesn't exist")
|
raise NotFoundError("User doesn't exist")
|
||||||
|
|
||||||
|
def set_starred(self, user_id, node_id, starred=True):
|
||||||
|
with closing(self.db.cursor()) as cursor:
|
||||||
|
if starred:
|
||||||
|
query = "INSERT INTO stars (userid, nodeid) VALUES (?, ?);"
|
||||||
|
else:
|
||||||
|
query = "DELETE FROM stars WHERE userid=? and nodeid=?;"
|
||||||
|
cursor.execute(query, (user_id, node_id))
|
||||||
|
|
|
@ -94,6 +94,9 @@ class PysonicLibrary(object):
|
||||||
"largeImageUrl": "",
|
"largeImageUrl": "",
|
||||||
"similarArtists": []}
|
"similarArtists": []}
|
||||||
|
|
||||||
|
def set_starred(self, username, node_id, starred):
|
||||||
|
self.db.set_starred(self.db.get_user(username)["id"], node_id, starred)
|
||||||
|
|
||||||
def get_user(self, user):
|
def get_user(self, user):
|
||||||
if type(user) is int:
|
if type(user) is int:
|
||||||
return self.db.get_user(username)
|
return self.db.get_user(username)
|
||||||
|
|
Loading…
Reference in New Issue