{"size": 1077, "ext": "js", "max_stars_repo_path": "resources/js/API/requests.js", "max_stars_repo_name": "santi1428/libros-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/js/API/requests.js", "max_issues_repo_name": "santi1428/libros-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "resources/js/API/requests.js", "max_forks_repo_name": "santi1428/libros-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.7714285714, "max_line_length": 207, "alphanum_fraction": 0.6935933148}
import axios from 'axios';
import { APP_ENDPOINT, API_ENDPOINT } from './conf';

const agregarLibro = async (usuarioId, libro) => {
    try{
        const request = await axios.post(`${APP_ENDPOINT}/api/agregarlibro`, {usuarioId, libroId: libro.id, nombre: libro.nombre, paginas: libro.paginas, descripcion: libro.descripcion, autor: libro.autor});
        return request.status;
    }catch(error){
        return error.response.status;
    }

}

const obtenerLibros = async () => {
    const request = await axios.get(`${API_ENDPOINT}/?num_items=50&lang=english`)
    return request.data;
}

const obtenerLibrosConFiltro = async (autor, year, lenguaje) => {
    const request = await axios.get(`${API_ENDPOINT}/?num_items=50&lang=${lenguaje}&publisher_date=${year}&book_author=${autor}`)
    return request.data;
}

const obtenerMisLibros = async (usuarioId) => {
    const request = await axios.get(`${APP_ENDPOINT}/api/obtenerlibros/${usuarioId}`);
    return request.data;
}

export {
    agregarLibro,
    obtenerLibros,
    obtenerMisLibros,
    obtenerLibrosConFiltro
}
