post.api.ts 663 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
  const { data } = await axios.post(`${baseUrl}/posts/`, post);
Lee Soobeom's avatar
Lee Soobeom committed
7

8
9
  return data;
};
Lee Soobeom's avatar
Lee Soobeom committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

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;
};