post.api.ts 1.06 KB
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
6
export const createImgAndPost = async (formdata: FormData) => {
  const { data } = await axios.post(`${baseUrl}/posts/`, formdata);
7
8
  return data;
};
Lee Soobeom's avatar
Lee Soobeom committed
9
10
11
12
13
14

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

Lee Soobeom's avatar
Lee Soobeom committed
15
16
17
18
19
export const getImgData = async (name: string) => {
  const { data } = await axios.get(`/images/${name}`);
  return data;
};

Lee Soobeom's avatar
Lee Soobeom committed
20
21
22
23
24
25
26
27
28
29
30
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
31
32
33
34
35
36
37
38
39
40

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