post.api.ts 943 Bytes
Newer Older
1
2
import axios from "axios";
import baseUrl from "./baseUrl";
Lee Soobeom's avatar
Lee Soobeom committed
3
import { PostType } from "../types";
4

Lee Soobeom's avatar
Lee Soobeom committed
5
export const posting = async (post: PostType) => {
6
7
8
  const { data } = await axios.post(`${baseUrl}/posts/`, post);
  return data;
};
Lee Soobeom's avatar
Lee Soobeom committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

export const getData = async () => {
  const { data } = await axios.get(`${baseUrl}/posts/`);
  return data;
};

export const addCounts = async (_id: string, counts: number) => {
  const { data } = await axios.post(`${baseUrl}/posts/${_id}`, {
    counts: counts + 1,
  });
  return data;
};

export const getPostByPostId = async (_id: string) => {
  const { data } = await axios.get(`${baseUrl}/posts/${_id}`);
  return data;
};
Lee Soobeom's avatar
Lee Soobeom committed
26
27
28
29
30
31
32
33
34
35

export const deletePost = async (_id: string) => {
  const { data } = await axios.delete(`${baseUrl}/posts/${_id}`);
  return data;
};

export const updating = async (post: PostType) => {
  const { data } = await axios.put(`${baseUrl}/posts/${post._id}`, post);
  return data;
};