NewsService.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import axios from "axios";
  2. import { buildQuery } from "@/helpers/params";
  3. const NewsService = axios.create({
  4. withCredentials: true,
  5. baseURL: `https://api.amic.ru/api/v1/news`,
  6. headers: {
  7. key: "Accept",
  8. value: "application/json",
  9. description: "",
  10. type: "text",
  11. enabled: true
  12. }
  13. });
  14. const CategoryService = axios.create({
  15. withCredentials: false,
  16. baseURL: `https://api.amic.ru/api/v1/category/list`,
  17. headers: {
  18. key: "Accept",
  19. value: "application/json",
  20. description: "",
  21. type: "text",
  22. enabled: true
  23. }
  24. });
  25. const api = axios.create({
  26. withCredentials: false,
  27. baseURL: `https://api.amic.ru/api/v1`,
  28. headers: {
  29. key: "Accept",
  30. value: "application/json",
  31. description: "",
  32. type: "text",
  33. enabled: true
  34. }
  35. });
  36. export default {
  37. getCategoriesList() {
  38. return CategoryService.get().then(list => {
  39. return list.data;
  40. });
  41. },
  42. getIndexNewsList() {
  43. return NewsService.get("/index")
  44. .then(newsList => {
  45. return newsList.data.data;
  46. })
  47. .catch(error => {
  48. console.log(error);
  49. });
  50. },
  51. getCategoryNewsList(params) {
  52. let apiUrl = params.category
  53. ? "/news/category/" + params.category + "/page_" + params.pagination
  54. : "/news/page_" + params.pagination;
  55. if (params.filter) {
  56. apiUrl += "?" + buildQuery(params.filter);
  57. }
  58. return api
  59. .get(apiUrl)
  60. .then(categoryNewsList => {
  61. return categoryNewsList.data.data;
  62. })
  63. .catch(error => {
  64. console.log(error.response);
  65. });
  66. },
  67. getNewsItem(params) {
  68. if (params.category) {
  69. return NewsService.get("/item/" + params.alias + "/" + params.category)
  70. .then(newsItem => {
  71. return newsItem.data.data;
  72. })
  73. .catch(error => {
  74. console.log(error);
  75. });
  76. } else if (!params.category) {
  77. return NewsService.get("/item/" + params.alias)
  78. .then(newsItem => {
  79. return newsItem.data.data;
  80. })
  81. .catch(error => {
  82. console.log(error);
  83. });
  84. }
  85. },
  86. getStories() {
  87. return NewsService.get("/story").then(res => {
  88. return res.data.data;
  89. });
  90. },
  91. getNewsFeedList() {
  92. return NewsService.get("/feed")
  93. .then((newsFeedList) => {
  94. return newsFeedList.data.data
  95. })
  96. .catch((error) => {
  97. console.log(error)
  98. })
  99. },
  100. };