import mobx, { observable, action } from 'mobx';
//import { Reviews } from '../agent';
import axios from 'axios';
const responseBody = res => res.data;
const API_ROOT = 'http://api.startgiven.ru:8080/stargiven-1.0/api';
const API = api => `${API_ROOT}${api}`;
const request = {
get: url =>
axios
.get(API(url))
.catch(err => console.log(err))
.then(responseBody)
};
const Reviews = {
all: () => request.get('/comments')
};
class SiteStore {
@observable reviews = [];
@action setReviews(payload) {
this.reviews = payload;
}
@action async fetchReviews() {
Reviews.all().then(reviews => this.setReviews(reviews));
}
}
export default SiteStore;
import axios from 'axios';
const API_ROOT = 'http://api.startgiven.ru:8080/stargiven-1.0/api';
const API = api => `${API_ROOT}${api}`;
const responseBody = res => res.body;
const handleError = err => {
if (err && err.response && err.response.status === 401) authStore.logout();
};
const request = {
get: url =>
axios
.get(API(url))
.catch(err => console.log(err))
.then(responseBody)
};
const Reviews = {
all: () => request.get('/comments')
};
export { Reviews };