added rejected posts for admin

This commit is contained in:
SlimusMinus
2026-10-06 02:06:44 +03:00
parent 9ccad319cd
commit 0074e51829
6 changed files with 76 additions and 29 deletions

View File

@@ -62,22 +62,40 @@ function extractPage(body, size) {
return { items, last, total: hasTotal ? body.totalElements : undefined };
}
/**
* GET /api/v1/admin/posts?page&size&search&type&status
*
* Постранично отдаёт ВСЕ объявления площадки вместе с данными автора.
* Возвращает { items, last, total } — items уже нормализованы.
*/
export async function getAdminPosts({ page = 0, size = 20, search = "", type = "", status = "" } = {}) {
const params = new URLSearchParams({ page, size });
if (search) params.set("search", search);
if (type) params.set("type", type);
if (status) params.set("status", status);
const res = await apiFetch(`${ADMIN_BASE}/posts?${params.toString()}`);
if (!res.ok) throw new AdminContentError(res.status, await readErrorMessage(res, "Failed to load posts"));
return extractPage(await res.json(), size);
}
/**
* GET /api/v1/admin/posts?page&size&search&type&status
*
* Постранично отдаёт ВСЕ объявления площадки вместе с данными автора.
* Возвращает { items, last, total } — items уже нормализованы.
*/
export async function getAdminPosts({ page = 0, size = 20, search = "", type = "", status = "" } = {}) {
const params = new URLSearchParams({ page, size });
if (search) params.set("search", search);
if (type) params.set("type", type);
if (status) params.set("status", status);
const res = await apiFetch(`${ADMIN_BASE}/posts?${params.toString()}`);
if (!res.ok) throw new AdminContentError(res.status, await readErrorMessage(res, "Failed to load posts"));
return extractPage(await res.json(), size);
}
/**
* GET /api/v1/admin/posts/rejected?page&size&search&type&status
*
* Постранично отдаёт объявления, не прошедшие модерацию (REJECTED),
* вместе с данными автора.
* Возвращает { items, last, total } — items уже нормализованы.
*/
export async function getAdminRejectedPosts({ page = 0, size = 20, search = "", type = "", status = "" } = {}) {
const params = new URLSearchParams({ page, size });
if (search) params.set("search", search);
if (type) params.set("type", type);
if (status) params.set("status", status);
const res = await apiFetch(`${ADMIN_BASE}/posts/rejected?${params.toString()}`);
if (!res.ok) throw new AdminContentError(res.status, await readErrorMessage(res, "Failed to load rejected posts"));
return extractPage(await res.json(), size);
}
/** DELETE /api/v1/admin/posts/{postId} — 204 и 200 одинаково допустимы. */
export async function deleteAdminPost(postId) {