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

export const getData = async () => {
  const { data } = await axios.get(`${baseUrl}/posts/`);
  return data;
Lee Soobeom's avatar
Lee Soobeom committed
13
14
15
16
17
18
}; //board

export const getFileByPostId = async (postId: string) => {
  const { data } = await axios.get(`${baseUrl}/posts/files/${postId}`);
  return data;
}; //
Lee Soobeom's avatar
Lee Soobeom committed
19

Lee Soobeom's avatar
Lee Soobeom committed
20
21
22
23
24
export const getImgData = async (name: string) => {
  const { data } = await axios.get(`/images/${name}`);
  return data;
};

Lee Soobeom's avatar
Lee Soobeom committed
25
26
export const addCounts = async (postId: string, counts: number) => {
  const { data } = await axios.post(`${baseUrl}/posts/${postId}`, {
Lee Soobeom's avatar
Lee Soobeom committed
27
28
29
30
31
    counts: counts + 1,
  });
  return data;
};

Lee Soobeom's avatar
Lee Soobeom committed
32
33
export const deletePost = async (postId: string) => {
  const { data } = await axios.delete(`${baseUrl}/posts/${postId}`);
Lee Soobeom's avatar
Lee Soobeom committed
34
35
36
  return data;
};

Lee Soobeom's avatar
Lee Soobeom committed
37
38
export const updateImgAndPost = async (postId: string, formdata: FormData) => {
  const { data } = await axios.put(`${baseUrl}/posts/${postId}`, formdata);
Lee Soobeom's avatar
Lee Soobeom committed
39
40
  return data;
};