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

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

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

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

Lee Soobeom's avatar
Lee Soobeom committed
30
31
export const updateImgAndPost = async (postId: string, formdata: FormData) => {
  const { data } = await axios.put(`${baseUrl}/posts/${postId}`, formdata);
Lee Soobeom's avatar
Lee Soobeom committed
32
33
34
  return data;
};

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