- Introduced `update` method for partial content updates. - Added `remove` method to handle content deletion.
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import api from "@/lib/api";
|
|
import type { Content, PaginatedResponse } from "@/types/content";
|
|
|
|
export const ContentService = {
|
|
async getExplore(params: {
|
|
limit?: number;
|
|
offset?: number;
|
|
sort?: "trend" | "recent";
|
|
tag?: string;
|
|
category?: string;
|
|
query?: string;
|
|
author?: string;
|
|
}): Promise<PaginatedResponse<Content>> {
|
|
const { data } = await api.get<PaginatedResponse<Content>>(
|
|
"/contents/explore",
|
|
{
|
|
params,
|
|
},
|
|
);
|
|
return data;
|
|
},
|
|
|
|
async getTrends(limit = 10, offset = 0): Promise<PaginatedResponse<Content>> {
|
|
const { data } = await api.get<PaginatedResponse<Content>>(
|
|
"/contents/trends",
|
|
{
|
|
params: { limit, offset },
|
|
},
|
|
);
|
|
return data;
|
|
},
|
|
|
|
async getRecent(limit = 10, offset = 0): Promise<PaginatedResponse<Content>> {
|
|
const { data } = await api.get<PaginatedResponse<Content>>(
|
|
"/contents/recent",
|
|
{
|
|
params: { limit, offset },
|
|
},
|
|
);
|
|
return data;
|
|
},
|
|
|
|
async getOne(idOrSlug: string): Promise<Content> {
|
|
const { data } = await api.get<Content>(`/contents/${idOrSlug}`);
|
|
return data;
|
|
},
|
|
|
|
async incrementViews(id: string): Promise<void> {
|
|
await api.post(`/contents/${id}/view`);
|
|
},
|
|
|
|
async incrementUsage(id: string): Promise<void> {
|
|
await api.post(`/contents/${id}/use`);
|
|
},
|
|
|
|
async upload(formData: FormData): Promise<Content> {
|
|
const { data } = await api.post<Content>("/contents/upload", formData, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
});
|
|
return data;
|
|
},
|
|
|
|
async removeAdmin(id: string): Promise<void> {
|
|
await api.delete(`/contents/${id}/admin`);
|
|
},
|
|
|
|
async update(id: string, update: Partial<Content>): Promise<Content> {
|
|
const { data } = await api.patch<Content>(`/contents/${id}`, update);
|
|
return data;
|
|
},
|
|
|
|
async remove(id: string): Promise<void> {
|
|
await api.delete(`/contents/${id}`);
|
|
},
|
|
|
|
async updateAdmin(id: string, update: Partial<Content>): Promise<Content> {
|
|
const { data } = await api.patch<Content>(`/contents/${id}/admin`, update);
|
|
return data;
|
|
},
|
|
};
|