function calificar() {
    /**
     * elimina la calificación de un audio por usuario
     * @param idRating
     */
    function eliminarCalificacion(idRating) {
        $.ajax({
            type: "DELETE",
            url: "/api/rate-delete/" + idRating,
            dataType: "json",
            //data: JSON.stringify(item),
            contentType: "application/json; charset=utf-8",
            "beforeSend": function (xhr, settings) {
                $.ajaxSettings.beforeSend(xhr, settings);
            },
            success: function (msg) {
                console.log("Se elimina calificación");
            },
            error: function (err) {
                console.log(err.responseText);
            }
        });
    }

    /**
     * Obtiene las calificaciones de un audio por usuario
     * @param audioId
     * @param autorId
     * @param calificacion
     */
    function getRatingsByAudioAutor(audioId, autorId) {
        var calificacionAnterior;
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf8",
            url: "/api/ratebyuseraudio/" + audioId + "/" + autorId + "/?format=json",
            success: function (response) {
                for (var i = 0; i <= response.length - 1; i++) {
                    eliminarCalificacion(response[i].id);
                    calificacionAnterior = response[i].val_rating;
                }
            },
            async: false,
        });
        return calificacionAnterior;
    }

    var calificacion = $(".rating").val();
    var songId = $("#songId").val();
    var userId = $("#userId").val();

    var calificacionAnterior = getRatingsByAudioAutor(songId, userId);
    if(calificacionAnterior !== undefined && calificacion === calificacionAnterior.toString()){
        $(".rating-input").empty();
        getRatingsByAudio();
        getUltimaCalificacion();
        return;
    }

    var item = {}
    item ["val_rating"] = calificacion;
    item ["audio"] = songId;
    item ["fec_creacion_rating"] = new Date();

    if (userId !== null && userId !== undefined && userId !== "None") {
        item ["autor"] = userId;
    }

    $.ajax({
        type: "POST",
        url: "/api/rate/",
        dataType: "json",
        data: JSON.stringify(item),
        contentType: "application/json; charset=utf-8",
        "beforeSend": function (xhr, settings) {
            $.ajaxSettings.beforeSend(xhr, settings);
        },
        success: function (msg) {
            getRatingsByAudio();
        },
        error: function (err) {
            console.log(err.responseText);
        }
    });

}
/**
 * Consume api rate, para calificar un artista
 */
Consume api rate, para calificar un artista
Consume api rate para calificar un artista
function calificar() {
    function eliminarCalificacion(idRating) {
        $.ajax({
            type: "DELETE",
            url: "/api/rate-delete/" + idRating,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            "beforeSend": function (xhr, settings) {
                $.ajaxSettings.beforeSend(xhr, settings);
            },
            success: function (msg) {
                console.log("Se elimina calificación");
            },
            error: function (err) {
                console.log(err.responseText);
            }
        });
    }
    function getRatingsByAudioAutor(audioId, autorId) {
        var calificacionAnterior;
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf8",
            url: "/api/ratebyuseraudio/" + audioId + "/" + autorId + "/?format=json",
            success: function (response) {
                for (var i = 0; i <= response.length - 1; i++) {
                    eliminarCalificacion(response[i].id);
                    calificacionAnterior = response[i].val_rating;
                }
            },
            async: false,
        });
        return calificacionAnterior;
    }
    var calificacion = $(".rating").val();
    var songId = $("#songId").val();
    var userId = $("#userId").val();
    var calificacionAnterior = getRatingsByAudioAutor(songId, userId);
    if(calificacionAnterior !== undefined && calificacion === calificacionAnterior.toString()){
        $(".rating-input").empty();
        getRatingsByAudio();
        getUltimaCalificacion();
        return;
    }
    var item = {}
    item ["val_rating"] = calificacion;
    item ["audio"] = songId;
    item ["fec_creacion_rating"] = new Date();
    if (userId !== null && userId !== undefined && userId !== "None") {
        item ["autor"] = userId;
    }
    $.ajax({
        type: "POST",
        url: "/api/rate/",
        dataType: "json",
        data: JSON.stringify(item),
        contentType: "application/json; charset=utf-8",
        "beforeSend": function (xhr, settings) {
            $.ajaxSettings.beforeSend(xhr, settings);
        },
        success: function (msg) {
            getRatingsByAudio();
        },
        error: function (err) {
            console.log(err.responseText);
        }
    });
}
function calificar ( ) { function eliminarCalificacion ( idRating ) { $ . ajax ( { type : "DELETE" , url : "/api/rate-delete/" + idRating , dataType : "json" , contentType : "application/json; charset=utf-8" , "beforeSend" : function ( xhr , settings ) { $ . ajaxSettings . beforeSend ( xhr , settings ) ; } , success : function ( msg ) { console . log ( "Se elimina calificación") ; } , error : function ( err ) { console . log ( err . responseText ) ; } } ) ; } function getRatingsByAudioAutor ( audioId , autorId ) { var calificacionAnterior ; $ . ajax ( { type : "GET" , contentType : "application/json; charset=utf8" , url : "/api/ratebyuseraudio/" + audioId + "/" + autorId + "/?format=json" , success : function ( response ) { for ( var i = 0 ; i <= response . length - 1 ; i ++ ) { eliminarCalificacion ( response [ i ] . id ) ; calificacionAnterior = response [ i ] . val_rating ; } } , async : false , } ) ; return calificacionAnterior ; } var calificacion = $ ( ".rating" ) . val ( ) ; var songId = $ ( "#songId" ) . val ( ) ; var userId = $ ( "#userId" ) . val ( ) ; var calificacionAnterior = getRatingsByAudioAutor ( songId , userId ) ; if ( calificacionAnterior !== undefined && calificacion === calificacionAnterior . toString ( ) ) { $ ( ".rating-input" ) . empty ( ) ; getRatingsByAudio ( ) ; getUltimaCalificacion ( ) ; return ; } var item = { } item [ "val_rating" ] = calificacion ; item [ "audio" ] = songId ; item [ "fec_creacion_rating" ] = new Date ( ) ; if ( userId !== null && userId !== undefined && userId !== "None" ) { item [ "autor" ] = userId ; } $ . ajax ( { type : "POST" , url : "/api/rate/" , dataType : "json" , data : JSON . stringify ( item ) , contentType : "application/json; charset=utf-8" , "beforeSend" : function ( xhr , settings ) { $ . ajaxSettings . beforeSend ( xhr , settings ) ; } , success : function ( msg ) { getRatingsByAudio ( ) ; } , error : function ( err ) { console . log ( err . responseText ) ; } } ) ; }
Consume api rate, para calificar un artista
Consume api rate para calificar un artista
/**
     * elimina la calificación de un audio por usuario
     * @param idRating
     */ //data: JSON.stringify(item), /**
     * Obtiene las calificaciones de un audio por usuario
     * @param audioId
     * @param autorId
     * @param calificacion
     */