pagination and api blog metadata all page
This commit is contained in:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user