import axios from "axios"; import { buildQuery } from "@/helpers/params"; const NewsService = axios.create({ withCredentials: true, baseURL: `https://api.amic.ru/api/v1/news`, headers: { key: "Accept", value: "application/json", description: "", type: "text", enabled: true } }); const CategoryService = axios.create({ withCredentials: false, baseURL: `https://api.amic.ru/api/v1/category/list`, headers: { key: "Accept", value: "application/json", description: "", type: "text", enabled: true } }); const api = axios.create({ withCredentials: false, baseURL: `https://api.amic.ru/api/v1`, headers: { key: "Accept", value: "application/json", description: "", type: "text", enabled: true } }); export default { getCategoriesList() { return CategoryService.get().then(list => { return list.data; }); }, getIndexNewsList() { return NewsService.get("/index") .then(newsList => { return newsList.data.data; }) .catch(error => { console.log(error); }); }, getCategoryNewsList(params) { let apiUrl = params.category ? "/news/category/" + params.category + "/page_" + params.pagination : "/news/page_" + params.pagination; if (params.filter) { apiUrl += "?" + buildQuery(params.filter); } return api .get(apiUrl) .then(categoryNewsList => { return categoryNewsList.data.data; }) .catch(error => { console.log(error.response); }); }, getNewsItem(params) { if (params.category) { return NewsService.get("/item/" + params.alias + "/" + params.category) .then(newsItem => { return newsItem.data.data; }) .catch(error => { console.log(error); }); } else if (!params.category) { return NewsService.get("/item/" + params.alias) .then(newsItem => { return newsItem.data.data; }) .catch(error => { console.log(error); }); } }, getStories() { return NewsService.get("/story").then(res => { return res.data.data; }); }, getNewsFeedList() { return NewsService.get("/feed") .then((newsFeedList) => { return newsFeedList.data.data }) .catch((error) => { console.log(error) }) }, };