def downvote_song(): user_name = request.json.get("user_name") user_password = request.json.get("user_password") song_title = request.json.get("song_title") valid = valid_parameters(user_name=user_name, user_password=user_password, song_title=song_title) if valid != True: return valid user = Users.get_user(user_name) if user is None: return {"error": f"the user {user_name} does not exist"} if user.password != user.parse_password(user_password): return {"error": f"either the user name or the password are wrong"} s = SongsList.get_song(song_title) if s is None: return {"error": "no such song in the songs collection"} s.downvote() set_from_db.write_songs_to_file() return { "message": "OK", "data": { "song_title": song_title, "rating": s.rating } }
def main(): set_from_db.get_songs_from_file() set_from_db.get_users_from_file() # Users.initiate_users() # SongsList.initiate_songs() Users.add_user("eytan", "123") e = Users.get_user("eytan") e.change_password("123", "456") e.add_playlist("lala") e.add_playlist("lala2") p = e.get_playlist("lala") s1 = Song("hamilton", 2010, "rap", "lin manuel miranda") s2 = Song("hamilton_1", 2010, "rap", "lin manuel miranda") SongsList.add_song(s1) SongsList.add_song(s2) e.add_song_to_playlist("lala", "hamilton") e.add_song_to_playlist("lala", "hamilton_1") e.add_song_to_playlist("lala2", "hamilton_1") set_from_db.write_users_to_file() set_from_db.write_songs_to_file() print("h")
def set_songs(): songs = request.json.get("songs") set_from_db.get_songs_from_source(songs) set_from_db.write_songs_to_file() return {"messgae": "OK"}
def add_song(): song_title = request.json.get("song_title") song_genre = request.json.get("song_genre") song_year = request.json.get("song_year") song_performer = request.json.get("song_performer") valid = valid_parameters(song_title=song_title, song_genre=song_genre, song_year=song_year, song_performer=song_performer) if valid != True: return valid s = Song(song_title, song_year, song_genre, song_performer) add_song = SongsList.add_song(s) if add_song is None: return {"error": "this song already exist in the collection"} set_from_db.write_songs_to_file() return {"message": "OK", "data": song_title}
def delete_all_songs(): SongsList.songs_list = {} set_from_db.write_songs_to_file() return {"message": "OK"}