Tech4biz-channel/Channel-Frontend/src/services/blog-api.ts

41 lines
1.1 KiB
TypeScript

import { axiosInstance } from './axios';
import type { BlogPost } from '../types';
export const getBlogPosts = async (params?: {
status?: string;
tag?: string;
search?: string;
}): Promise<BlogPost[]> => {
const response = await axiosInstance.get<BlogPost[]>('/blog', { params });
return response.data;
};
export const getBlogPostById = async (id: string): Promise<BlogPost> => {
const response = await axiosInstance.get<BlogPost>(`/blog/${id}`);
return response.data;
};
export const createBlogPost = async (payload: {
title: string;
content: string;
tags?: string[];
thumbnailUrl?: string;
status: 'draft' | 'published';
author?: string;
}): Promise<BlogPost> => {
const response = await axiosInstance.post<BlogPost>('/blog/new', payload);
return response.data;
};
export const updateBlogPost = async (
id: string,
payload: Partial<BlogPost>
): Promise<BlogPost> => {
const response = await axiosInstance.patch<BlogPost>(`/blog/${id}`, payload);
return response.data;
};
export const deleteBlogPost = async (id: string): Promise<void> => {
await axiosInstance.delete(`/blog/${id}`);
};