123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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)
- })
- },
- };
|