예제 #1
0
 def add_vote(self, song: Song, voted_user_id: str):
     """ Add user id in voted users. Also update mark. """
     song.update(voted_users=fn.array_append(
         Song.voted_users, voted_user_id)).where(
             Song.id_music == song.id_music).execute()
     song.update(mark=song.mark +
                 1).where(Song.id_music == song.id_music).execute()
예제 #2
0
 def remove_vote(self, song: Song, voted_user_id: str):
     """ Remove user id from voted users. Also update mark. """
     song.update(voted_users=fn.array_remove(
         Song.voted_users, voted_user_id)).where(
             Song.id_music == song.id_music).execute()
     song.update(mark=song.mark -
                 1).where(Song.id_music == song.id_music).execute()
예제 #3
0
 def save_songs(self, songs: List[dict]):
     """ Save songs in the db. """
     for song in songs:
         Song.create(title=song.get('title'),
                     author=song.get('author'),
                     link=song.get('link'),
                     pos=song.get('pos'),
                     mark=song.get('mark'),
                     voted_users=song.get('voted_users'))
예제 #4
0
 def clear(self):
     """ Delete all songs form db. """
     Song.delete().execute()
예제 #5
0
 def nullify_song_votes(self, song: Song):
     """ Clear song voted users and mark. """
     song.update(mark=0).where(Song.id_music == song.id_music).execute()
     song.update(voted_users=[]).where(
         Song.id_music == song.id_music).execute()
예제 #6
0
 def get_song_by_id(self, id: int):
     return Song.get_by_id(id)
예제 #7
0
 def sort_songs(self, DESC=True):
     """ Sort songs in the db. """
     if DESC:
         return Song.select().order_by(Song.voted_users.desc()).execute()
     else:
         return Song.select().order_by(Song.voted_users.asc()).execute()
예제 #8
0
 def get_all_songs(self):
     """ Get list of all songs. """
     return Song.select().execute()
예제 #9
0
 def is_any_song_in_db(self):
     return Song.select().count() != 0