feat: Добавил постраничную загрузку отзывов
Frontend CI / build-and-check (push) Failing after 5m10s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 15s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 18s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 32s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 13s
Frontend CI / build-and-check (push) Failing after 5m10s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 15s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 18s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 32s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 13s
This commit is contained in:
@@ -10,6 +10,7 @@ import type {
|
||||
LocationDto,
|
||||
PagedResult,
|
||||
ReviewDto,
|
||||
ReviewQuery,
|
||||
SyncResultDto,
|
||||
SyncScheduleRequest,
|
||||
SyncStatusDto,
|
||||
@@ -115,19 +116,53 @@ export const notificationsApi = {
|
||||
markAllRead: () => apiRequest<void>('/notifications/read-all', { method: 'PATCH' }),
|
||||
}
|
||||
|
||||
function normalizePagedResult<T>(
|
||||
payload: PagedResult<T> | T[] | undefined,
|
||||
query: { Page?: number; PageSize?: number } = {},
|
||||
): PagedResult<T> {
|
||||
if (!Array.isArray(payload) && payload) return payload
|
||||
|
||||
const items = payload ?? []
|
||||
const page = query.Page ?? 1
|
||||
const pageSize = query.PageSize ?? items.length
|
||||
const totalPages = pageSize > 0 ? Math.ceil(items.length / pageSize) : 0
|
||||
|
||||
return {
|
||||
items,
|
||||
totalCount: items.length,
|
||||
page,
|
||||
pageSize,
|
||||
totalPages,
|
||||
}
|
||||
}
|
||||
|
||||
async function listReviewsPage(query: ReviewQuery = {}) {
|
||||
const payload = await apiRequest<PagedResult<ReviewDto> | ReviewDto[]>('/reviews', {
|
||||
query: query as Record<string, unknown>,
|
||||
})
|
||||
return normalizePagedResult(payload, query)
|
||||
}
|
||||
|
||||
async function listPendingReviewsPage(query: ReviewQuery = {}) {
|
||||
const payload = await apiRequest<PagedResult<ReviewDto> | ReviewDto[]>('/reviews/pending', {
|
||||
query: query as Record<string, unknown>,
|
||||
})
|
||||
return normalizePagedResult(payload, query)
|
||||
}
|
||||
|
||||
export const reviewsApi = {
|
||||
create: (lectureId: string | number, rating: 'Like' | 'Neutral' | 'Dislike', text: string) =>
|
||||
apiRequest<ReviewDto>('/reviews', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ lectureId: Number(lectureId), rating, text }),
|
||||
}),
|
||||
async list(query: Record<string, unknown> = { PageSize: 100 }) {
|
||||
const payload = await apiRequest<PagedResult<ReviewDto> | ReviewDto[]>('/reviews', { query })
|
||||
return extractItems(payload)
|
||||
listPage: listReviewsPage,
|
||||
async list(query: ReviewQuery = { PageSize: 100 }) {
|
||||
return (await listReviewsPage(query)).items
|
||||
},
|
||||
async pending() {
|
||||
const payload = await apiRequest<PagedResult<ReviewDto> | ReviewDto[]>('/reviews/pending')
|
||||
return extractItems(payload)
|
||||
pendingPage: listPendingReviewsPage,
|
||||
async pending(query: ReviewQuery = { PageSize: 100 }) {
|
||||
return (await listPendingReviewsPage(query)).items
|
||||
},
|
||||
reanalyze: (id: string | number) =>
|
||||
apiRequest<void>(`/reviews/${id}/reanalyze`, { method: 'POST' }),
|
||||
|
||||
Reference in New Issue
Block a user