pagination and api blog metadata all page

This commit is contained in:
Zahra Vaziri
2025-06-15 20:54:48 +03:30
parent 594643816a
commit 804e3af3ba
20 changed files with 548 additions and 241 deletions
+33
View File
@@ -0,0 +1,33 @@
'use server';
import { IPostCardProps } from '@/app/api/blog/data';
import api from '@/lib/axios';
import { cookies } from 'next/headers';
export interface IResponse<T> {
data: T;
pagination: {
currentPage: number;
totalPages: number;
totalItems: number;
limit: number;
};
}
export async function getPosts(
page = 1,
limit = 6,
): Promise<IResponse<IPostCardProps[]>> {
const cookiesStore = await cookies();
return api
.get('/blog', {
headers: {
Cookie: cookiesStore.toString(),
},
params: { page, limit },
})
.then(({ data }) => {
return Promise.resolve(data);
})
.catch((error) => Promise.reject(error));
}