이번 프로젝트에서 맡은 역할:
DataService.js:
import axios from 'axios';
import { getLoginUser, setLoginUser } from '../component/commons/utils/lib';
const http = axios.create({
baseURL: 'http://localhost:4000/',
headers: {
'Content-type': 'application/json',
},
});
class FeedDataService {
getFeeds() {
return http.get('http://localhost:4000/posts');
}
getFeed(id) {
return http.get(`http://localhost:4000/posts/${id}`);
}
postFeed(data) {
return http.post('http://localhost:4000/posts', data);
}
async updateFeed(prevFeed, newComment) {
const commentId =
prevFeed.reply.sort((a, b) => b.id - a.id)[0]?.id + 1 ?? 1;
const reply = [{ id: commentId, ...newComment }, ...prevFeed.reply];
const data = {
...prevFeed,
reply,
};
return http.put(`http://localhost:4000/posts/${data.id}`, data);
}
}
export default new FeedDataService();