예제 #1
0
def get_album(albumID):  # noqa: E501
    """obtiene un álbum

    Obtiene los datos del álbum identificada por albumID  # noqa: E501

    :param albumID: ID del álbum
    :type albumID: str

    :rtype: AlbumItem
    """
    sql = "SELECT * FROM get_album_by_id( {} )".format(albumID)
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_author_name_by_id( {} )".format(
        datos['authorid'])
    query2 = engine.execute(sql2)
    datos2 = query2.first()

    sql3 = "SELECT * FROM get_songs_of_album( {} )".format(albumID)
    query3 = engine.execute(sql3)
    songs = []
    for item in query3:
        genero = []
        genero.append(item[4])
        song = SongItem(item[0], item[1], item[2], datos['authorid'],
                        datos2[0], albumID, datos['name'], genero)
        songs.append(song)

    return AlbumItem(datos['id'], datos['name'], datos['authorid'], datos2[0],
                     datos['publishdate'], datos['description'], songs)
예제 #2
0
def get_song(songID):  # noqa: E501
    """obtiene información de una canción

    Obtiene los datos de la canción identificada por songID  # noqa: E501

    :param songID: ID de la canción
    :type songID: str

    :rtype: SongItem
    """

    sql = "SELECT * FROM get_songinfo_by_id( {} )".format(songID)
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_album_by_id( {} )".format(datos[3])
    query2 = engine.execute(sql2)

    datos2 = query2.first()

    sql3 = "SELECT * FROM get_author_name_by_id( {} )".format(datos2[3])
    query3 = engine.execute(sql3)

    datos3 = query3.first()
    genero = []
    genero.append(datos[4])

    return SongItem(datos[0], datos[1], datos[2], datos2[3], datos3[0],
                    datos[3], datos2[1], genero)
예제 #3
0
def add_playlist_song(playlistID, songID = None):  # noqa: E501
    """añade una canción a una lista de reproducción

    Un usuario añade una canción a una lista de reproducción de su propiedad. # noqa: E501

    :param playlistID: ID de la playlist
    :type playlistID: str
    :param songID: Song to add
    :type songID: str

    :rtype: PlaylistItem
    """
    sql = "SELECT * FROM check_list_user( {} , {} )".format(auth.get_userid(), playlistID)
    query = engine.execute(sql)
    datos = query.first()

    if datos[0] == 0:
        return 'Not found', 404

    sql = "SELECT * FROM get_songinfo_by_id( {} )".format(int(songID))
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql = "SELECT * FROM insert_song_in_list( {} , {} ); COMMIT;".format(playlistID, int(songID))
    engine.execute(sql)

    sql = "SELECT * FROM get_list_by_id( {} )".format(playlistID)
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_userinfo_by_id( {} )".format(datos[2])
    query2 = engine.execute(sql2)
    datos2 = query2.first()

    sql3 = "SELECT * FROM get_songs_of_list( {} )".format(playlistID)
    query3 = engine.execute(sql3)
    songs = []
    for item in query3:
        sql4 = "SELECT * FROM get_album_by_id( {} )".format(item[3])
        query4 = engine.execute(sql4)

        datos4 = query4.first()

        sql5 = "SELECT * FROM get_author_name_by_id( {} )".format(datos4[3])
        query5 = engine.execute(sql5)

        datos5 = query5.first()
        genero = []
        genero.append(item[4])
        song = SongItem(item[0], item[1], item[2], datos4[3], datos5[0], item[3], datos4[1], genero)
        songs.append(song)

    return PlaylistItem(datos[0], datos[1], datos[2], datos2[2], datos[3], datos[4], songs)
예제 #4
0
def update_playlist(playlistID, playlistItem=None):  # noqa: E501
    """actualiza la información de una playlist

    Un usuario actualiza la información de una playlist de su propiedad. # noqa: E501

    :param playlistID: ID de la playlist
    :type playlistID: str
    :param playlistItem: Playlist item to update
    :type playlistItem: dict | bytes

    :rtype: PlaylistItem
    """
    sql = "SELECT * FROM check_list_user( {} , {} )".format(auth.get_userid(), playlistID)
    query = engine.execute(sql)
    datos = query.first()

    if datos[0] == 0:
        return 'Not found', 404

    if connexion.request.is_json:
        playlistItem = PlaylistItemNew.from_dict(connexion.request.get_json())  # noqa: E501

    sql = "SELECT * FROM update_list( {} , '{}' , '{}' ); COMMIT;"\
        .format(playlistID, playlistItem.name, playlistItem.description)
    engine.execute(sql)

    sql = "SELECT * FROM get_list_by_id( {} )".format(playlistID)
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_userinfo_by_id( {} )".format(datos[2])
    query2 = engine.execute(sql2)
    datos2 = query2.first()

    sql3 = "SELECT * FROM get_songs_of_list( {} )".format(playlistID)
    query3 = engine.execute(sql3)
    songs = []
    for item in query3:
        sql4 = "SELECT * FROM get_album_by_id( {} )".format(item[3])
        query4 = engine.execute(sql4)

        datos4 = query4.first()

        sql5 = "SELECT * FROM get_author_name_by_id( {} )".format(datos4[3])
        query5 = engine.execute(sql5)

        datos5 = query5.first()

        genero = []
        genero.append(item[4])
        song = SongItem(item[0], item[1], item[2], datos4[3], datos5[0], item[3], datos4[1], genero)
        songs.append(song)

    return PlaylistItem(datos[0], datos[1], datos[2], datos2[2], datos[3], datos[4], songs)
예제 #5
0
def get_profile(profileID):  # noqa: E501
    """obtiene un perfil de usuario identificado por profileID

    Obtiene un perfil de usuario identificado por profileID.  # noqa: E501

    :param profileID: ID del perfil
    :type profileID: str

    :rtype: ProfileItem
    """

    sql = "SELECT * FROM get_userinfo_by_id( {} )".format(profileID)
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_followed_by_user( {} , 10000, 0)".format(
        profileID)
    query2 = engine.execute(sql2)
    friends = []
    for item in query2:
        friend = FriendItem(item[0], item[1], item[2], item[3])
        friends.append(friend)

    sql3 = "SELECT * FROM get_list_by_ownerid( {} , 10000, 0)".format(
        profileID)
    query3 = engine.execute(sql3)
    lists = []
    for item in query3:
        sql4 = "SELECT * FROM get_songs_of_list( {} )".format(item[0])
        query4 = engine.execute(sql4)
        songs = []
        for item2 in query4:
            sql5 = "SELECT * FROM get_album_by_id( {} )".format(item2[3])
            query5 = engine.execute(sql5)

            datos5 = query5.first()

            sql6 = "SELECT * FROM get_author_name_by_id( {} )".format(
                datos5[3])
            query6 = engine.execute(sql6)

            datos6 = query6.first()

            genero = []
            genero.append(item2[4])
            song = SongItem(item2[0], item2[1], item2[2], datos5[3], datos6[0],
                            item2[3], datos5[1], genero)
            songs.append(song)
        list = PlaylistItem(item[0], item[1], item[2], datos[2], item[3],
                            item[4], songs)
        lists.append(list)
    return ProfileItem(datos[0], datos[1], datos[2], datos[3], friends, lists)
예제 #6
0
def add_playlist(playlistItem=None):  # noqa: E501
    """crea una lista de reproducción

    Un usuario crea una lista de reproducción. # noqa: E501

    :param playlistItem: Playlist item to add
    :type playlistItem: dict | bytes

    :rtype: PlaylistItem
    """
    if connexion.request.is_json:
        playlistItem = PlaylistItemNew.from_dict(connexion.request.get_json())  # noqa: E501

    sql = "SELECT * FROM insert_new_play_list( '{}' , {} , '{}' ); COMMIT;"\
        .format(playlistItem.name, auth.get_userid(), playlistItem.description)
    engine.execute(sql)

    sql = "SELECT * FROM search_one_list( {} , '{}' , '{}' )".\
        format(auth.get_userid(), playlistItem.description, playlistItem.name)
    query = engine.execute(sql)
    newdatos = query.first()

    sql = "SELECT * FROM get_list_by_id( {} )".format(newdatos[0])
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_userinfo_by_id( {} )".format(datos[2])
    query2 = engine.execute(sql2)
    datos2 = query2.first()

    sql3 = "SELECT * FROM get_songs_of_list( {} )".format(newdatos[0])
    query3 = engine.execute(sql3)
    songs = []
    for item in query3:
        sql4 = "SELECT * FROM get_album_by_id( {} )".format(item[3])
        query4 = engine.execute(sql4)

        datos4 = query4.first()

        sql5 = "SELECT * FROM get_author_name_by_id( {} )".format(datos4[3])
        query5 = engine.execute(sql5)

        datos5 = query5.first()
        genero = []
        genero.append(item[4])
        song = SongItem(item[0], item[1], item[2], datos4[3], datos5[0], item[3], datos4[1], genero)
        songs.append(song)

    return PlaylistItem(datos[0], datos[1], datos[2], datos2[2], datos[3], datos[4], songs)
예제 #7
0
def search_playlist(name='', owner='', skip=0, limit=10):  # noqa: E501
    """busca listas de reproducción con ciertos parámetros

    Al pasarle ciertos parámetros devuelve listas de reproducción que se ajusten a ellos  # noqa: E501

    :param name: nombre de la lista
    :type name: str
    :param owner: propietario de la lista
    :type owner: str
    :param skip: number of records to skip for pagination
    :type skip: int
    :param limit: maximum number of records to return
    :type limit: int

    :rtype: List[PlaylistItem]
    """

    sql = "SELECT * FROM search_listsAnd( '{}' , '{}' , {} , {} )".format(
        name, owner, limit, skip)
    query = engine.execute(sql)
    lists = []
    for item in query:
        sql2 = "SELECT * FROM get_userinfo_by_id( {} )".format(item[2])
        query2 = engine.execute(sql2)
        datos2 = query2.first()

        sql4 = "SELECT * FROM get_songs_of_list( {} )".format(item[0])
        query4 = engine.execute(sql4)
        songs = []
        for item3 in query4:
            sql5 = "SELECT * FROM get_album_by_id( {} )".format(item3[3])
            query5 = engine.execute(sql5)
            datos5 = query5.first()

            sql6 = "SELECT * FROM get_author_name_by_id( {} )".format(
                datos5[3])
            query6 = engine.execute(sql6)
            datos6 = query6.first()

            genero = []
            genero.append(item3[4])
            song = SongItem(item3[0], item3[1], item3[2], datos5[3], datos6[0],
                            item3[3], datos5[1], genero)
            songs.append(song)

        playlist = PlaylistItem(item[0], item[1], item[2], datos2[2], item[3],
                                item[4], songs)
        lists.append(playlist)
    return lists
예제 #8
0
def get_account():  # noqa: E501
    """devuelve la información de la cuenta del usuario

    Devuelve la información de la cuenta del usuario.  # noqa: E501


    :rtype: AccountItem
    """
    sql = "SELECT * FROM get_user_by_id( {} )".format(auth.get_userid())
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_followed_by_user( {} , 10000, 0)".format(auth.get_userid())
    query2 = engine.execute(sql2)
    friends = []
    for item in query2:
        friend = FriendItem(item[0], item[1], item[2], item[3])
        friends.append(friend)

    sql3 = "SELECT * FROM get_list_by_ownerid( {} , 10000, 0)".format(auth.get_userid())
    query3 = engine.execute(sql3)
    lists = []
    for item in query3:
        sql4 = "SELECT * FROM get_songs_of_list( {} )".format(item[0])
        query4 = engine.execute(sql4)
        songs = []
        for item2 in query4:
            sql5 = "SELECT * FROM get_album_by_id( {} )".format(item2[3])
            query5 = engine.execute(sql5)

            datos5 = query5.first()

            sql6 = "SELECT * FROM get_author_name_by_id( {} )".format(datos5[3])
            query6 = engine.execute(sql6)

            datos6 = query6.first()
            genero = []
            genero.append(item2[4])
            song = SongItem(item2[0], item2[1], item2[2], datos5[3], datos6[0], item2[3], datos5[1], genero)
            songs.append(song)
        list = PlaylistItem(item[0], item[1], item[2], datos[3], item[3], item[4], songs)
        lists.append(list)
    return AccountItem(datos[0], datos[1], datos[3], datos[4], datos[2], friends, lists)
예제 #9
0
def get_playlist(playlistID):  # noqa: E501
    """obtiene una playlist

    Obtiene los datos de la playlist identificada por playlistID  # noqa: E501

    :param playlistID: ID de la playlist
    :type playlistID: str

    :rtype: PlaylistItem
    """

    sql = "SELECT * FROM get_list_by_id( {} )".format(playlistID)
    query = engine.execute(sql)
    datos = query.first()
    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_userinfo_by_id( {} )".format(datos[2])
    query2 = engine.execute(sql2)
    datos2 = query2.first()

    sql3 = "SELECT * FROM get_songs_of_list( {} )".format(playlistID)
    query3 = engine.execute(sql3)
    songs = []
    for item in query3:
        sql4 = "SELECT * FROM get_album_by_id( {} )".format(item[3])
        query4 = engine.execute(sql4)

        datos4 = query4.first()

        sql5 = "SELECT * FROM get_author_name_by_id( {} )".format(datos4[3])
        query5 = engine.execute(sql5)

        datos5 = query5.first()

        genero = []
        genero.append(item[4])

        song = SongItem(item[0], item[1], item[2], datos4[3], datos5[0],
                        item[3], datos4[1], genero)
        songs.append(song)

    return PlaylistItem(datos[0], datos[1], datos[2], datos2[2], datos[3],
                        datos[4], songs)
예제 #10
0
def search_song(name='', author='', genre='', skip=0, limit=10):  # noqa: E501
    """busca canciones con ciertos parámetros

    Al pasarle ciertos parámetros devuelve cancionese que se ajusten a ellos  # noqa: E501

    :param name: nombre de la canción
    :type name: str
    :param author: autor de la canción
    :type author: str
    :param genre: genero de la canción
    :type genre: str
    :param skip: number of records to skip for pagination
    :type skip: int
    :param limit: maximum number of records to return
    :type limit: int

    :rtype: List[SongItem]
    """

    sql = "SELECT * FROM search_songsAnd( '{}' , '{}' , '{}' , {} , {} )".format(
        name, author, genre, limit, skip)
    query = engine.execute(sql)
    songs = []

    for item in query:
        sql2 = "SELECT * FROM get_album_by_id( {} )".format(item[3])
        query2 = engine.execute(sql2)

        datos2 = query2.first()

        sql3 = "SELECT * FROM get_author_name_by_id( {} )".format(datos2[3])
        query3 = engine.execute(sql3)

        datos3 = query3.first()

        genero = []
        genero.append(item[4])
        song = SongItem(item[0], item[1], item[2], datos2[3], datos3[0],
                        item[3], datos2[1], genero)
        songs.append(song)
    return songs
예제 #11
0
def get_author(authorID):  # noqa: E501
    """obtiene un perfil de autor identificado por authorID

    Obtiene un perfil de autor identificado por authorID  # noqa: E501

    :param authorID: ID del autor
    :type authorID: str

    :rtype: AuthorItem
    """
    sql = "SELECT * FROM get_author_by_id( {} )".format(authorID)
    query = engine.execute(sql)
    datos = query.first()

    if datos['id'] is None:
        return 'Not found', 404

    sql2 = "SELECT * FROM get_album_by_authorid( {} , 10000, 0)".format(
        authorID)
    query2 = engine.execute(sql2)

    albums = []

    for item in query2:
        sql3 = "SELECT * FROM get_songs_of_album( {} )".format(item[0])
        query3 = engine.execute(sql3)

        songs = []

        for item2 in query3:
            genero = []
            genero.append(item2[4])
            song = SongItem(item2[0], item2[1], item2[2], authorID,
                            datos['name'], item[0], item[1], genero)
            songs.append(song)

        album = AlbumItem(item[0], item[1], authorID, datos['name'], item[2],
                          item[4], songs)
        albums.append(album)

    return AuthorItem(datos['id'], datos['name'], datos['bio'], albums)
예제 #12
0
def search_authors(name='', skip=0, limit=10):  # noqa: E501
    """busca autores con ciertos parámetros

    Al pasarle ciertos parámetros devuelve autores que se ajusten a ellos  # noqa: E501

    :param name: nombre del autor
    :type name: str
    :param skip: number of records to skip for pagination
    :type skip: int
    :param limit: maximum number of records to return
    :type limit: int

    :rtype: List[AuthorItem]
    """

    sql = "SELECT * FROM search_author( '{}' , {} , {} )".format(
        name, limit, skip)
    query = engine.execute(sql)
    authors = []
    for item in query:
        sql2 = "SELECT * FROM get_album_by_authorid( {} ,10000, 0)".format(
            item[0])
        query2 = engine.execute(sql2)
        albums = []
        for item2 in query2:
            sql3 = "SELECT * FROM get_songs_of_album( {} )".format(item2[0])
            query3 = engine.execute(sql3)
            songs = []
            for item3 in query3:
                genero = []
                genero.append(item3[4])
                song = SongItem(item3[0], item3[1], item3[2], item[0], item[1],
                                item2[0], item2[1], genero)
                songs.append(song)
            album = AlbumItem(item2[0], item2[1], item[0], item[1], item2[2],
                              item2[4], songs)
            albums.append(album)
        author = AuthorItem(item[0], item[1], item[2], albums)
        authors.append(author)
    return authors
예제 #13
0
def search_album(name='', author='', skip=0, limit=10):  # noqa: E501
    """busca álbunes con ciertos parámetros

    Al pasarle ciertos parámetros devuelve álbunes que se ajusten a ellos  # noqa: E501

    :param name: nombre del álbum
    :type name: str
    :param author: autor del álbum
    :type author: str
    :param skip: number of records to skip for pagination
    :type skip: int
    :param limit: maximum number of records to return
    :type limit: int

    :rtype: List[AlbumItem]
    """

    sql = "SELECT * FROM search_albumAnd( '{}' , '{}' , {} , {} )".format(
        name, author, limit, skip)
    query = engine.execute(sql)
    albums = []
    for item in query:
        sql2 = "SELECT * FROM get_author_name_by_id( {} )".format(item[3])
        query2 = engine.execute(sql2)
        datos = query2.first()

        sql3 = "SELECT * FROM get_songs_of_album( {} )".format(item[0])
        query3 = engine.execute(sql3)
        songs = []
        for item2 in query3:
            genero = []
            genero.append(item2[4])
            song = SongItem(item2[0], item2[1], item2[2], item[3], datos[0],
                            item[0], item[1], genero)
            songs.append(song)
        album = AlbumItem(item[0], item[1], item[3], datos[0], item[2],
                          item[4], songs)
        albums.append(album)
    return albums
예제 #14
0
def search_profiles(name='', username='', skip=0, limit=10):  # noqa: E501
    """busca usuarios con ciertos parámetros

    Al pasarle ciertos parámetros devuelve usuarios que se ajusten a ellos.  # noqa: E501

    :param name: nombre del usuario
    :type name: str
    :param username: username del usuario
    :type username: str
    :param skip: number of records to skip for pagination
    :type skip: int
    :param limit: maximum number of records to return
    :type limit: int

    :rtype: List[ProfileItem]
    """

    sql = "SELECT * FROM search_usersAnd( '{}' , '{}' , {}, {} )".format(
        name, username, limit, skip)
    query = engine.execute(sql)
    users = []

    for item in query:
        sql2 = "SELECT * FROM get_followed_by_user( {} , 10000, 0)".format(
            item[0])
        query2 = engine.execute(sql2)
        friends = []
        for item2 in query2:
            friend = FriendItem(item2[0], item2[1], item2[2], item2[3])
            friends.append(friend)

        sql3 = "SELECT * FROM get_list_by_ownerid( {} , 10000, 0)".format(
            item[0])
        query3 = engine.execute(sql3)
        lists = []
        for item2 in query3:
            sql4 = "SELECT * FROM get_songs_of_list( {} )".format(item2[0])
            query4 = engine.execute(sql4)
            songs = []
            for item3 in query4:
                sql5 = "SELECT * FROM get_album_by_id( {} )".format(item3[3])
                query5 = engine.execute(sql5)
                datos5 = query5.first()

                sql6 = "SELECT * FROM get_author_name_by_id( {} )".format(
                    datos5[3])
                query6 = engine.execute(sql6)
                datos6 = query6.first()

                genero = []
                genero.append(item3[4])
                song = SongItem(item3[0], item3[1], item3[2], datos5[3],
                                datos6[0], item3[3], datos5[1], genero)
                songs.append(song)

            list = PlaylistItem(item2[0], item2[1], item2[2], item[2],
                                item2[3], item2[4], songs)
            lists.append(list)
        user = ProfileItem(item[0], item[1], item[2], item[3], friends, lists)
        users.append(user)

    return users