live blog implemented

This commit is contained in:
dimitar committed 2026-01-29 04:01:55 +01:00
1 parent e8893c1aae
commit 0351726eeb
36 files changed
+7759 -253

No files matched your search

+190
View File
@@ -92,3 +92,193 @@ export async function fetchArticleById(id: string): Promise<Article> {
}
return response.json();
}
// Live Blog Types
export interface LiveBlogUpdate {
id: string;
content: string;
isPinned: boolean;
authorId: string | null;
scheduledAt: string | null;
strapiId: string | null;
author?: {
id: string;
name: string;
slug: string;
bio: string | null;
avatar: string | null;
};
createdAt: string;
updatedAt: string;
}
export interface LiveBlog {
id: string;
title: string;
slug: string;
description: string | null;
status: 'draft' | 'live' | 'ended' | 'archived';
strapiId: string | null;
authorId: string | null;
categoryId: string | null;
viewCount: number;
author?: {
id: string;
name: string;
slug: string;
bio: string | null;
avatar: string | null;
};
category?: {
id: string;
name: string;
slug: string;
description: string | null;
};
updates?: LiveBlogUpdate[];
createdAt: string;
updatedAt: string;
}
export interface LiveBlogsResponse {
data: LiveBlog[];
total: number;
page?: number;
limit?: number;
}
export interface LiveBlogUpdatesResponse {
data: LiveBlogUpdate[];
total: number;
page?: number;
limit?: number;
}
export interface FindLiveBlogsParams {
category?: string;
author?: string;
status?: 'draft' | 'live' | 'ended' | 'archived';
search?: string;
page?: number;
limit?: number;
}
export interface CreateLiveBlogUpdateDto {
content: string;
isPinned?: boolean;
authorId?: string;
scheduledAt?: string;
strapiId?: string;
}
export interface UpdateLiveBlogUpdateDto {
content?: string;
isPinned?: boolean;
authorId?: string;
scheduledAt?: string;
strapiId?: string;
}
// Live Blog API Functions
export async function fetchLiveBlogs(params: FindLiveBlogsParams = {}): Promise<LiveBlogsResponse> {
const searchParams = new URLSearchParams();
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined && value !== null) {
if (typeof value === 'number') {
searchParams.append(key, value.toString());
} else {
searchParams.append(key, String(value));
}
}
});
const response = await fetch(`${API_BASE_URL}/live-blogs?${searchParams}`);
if (!response.ok) {
throw new Error('Failed to fetch live blogs');
}
return response.json();
}
export async function fetchLiveBlogBySlug(slug: string): Promise<LiveBlog> {
const response = await fetch(`${API_BASE_URL}/live-blogs/slug/${slug}`);
if (!response.ok) {
throw new Error('Failed to fetch live blog');
}
return response.json();
}
export async function fetchLiveBlogById(id: string): Promise<LiveBlog> {
const response = await fetch(`${API_BASE_URL}/live-blogs/${id}`);
if (!response.ok) {
throw new Error('Failed to fetch live blog');
}
return response.json();
}
export async function fetchLiveBlogUpdates(
liveBlogId: string,
page = 1,
limit = 50
): Promise<LiveBlogUpdatesResponse> {
const response = await fetch(
`${API_BASE_URL}/live-blogs/${liveBlogId}/updates?page=${page}&limit=${limit}`
);
if (!response.ok) {
throw new Error('Failed to fetch live blog updates');
}
return response.json();
}
export async function fetchRecentLiveBlogs(): Promise<LiveBlog[]> {
const response = await fetch(`${API_BASE_URL}/live-blogs/recent`);
if (!response.ok) {
throw new Error('Failed to fetch recent live blogs');
}
return response.json();
}
// Admin functions
export async function createLiveBlogUpdate(
liveBlogId: string,
dto: CreateLiveBlogUpdateDto
): Promise<LiveBlogUpdate> {
const response = await fetch(`${API_BASE_URL}/live-blogs/${liveBlogId}/updates`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(dto),
});
if (!response.ok) {
throw new Error('Failed to create live blog update');
}
return response.json();
}
export async function updateLiveBlogUpdate(
liveBlogId: string,
updateId: string,
dto: UpdateLiveBlogUpdateDto
): Promise<LiveBlogUpdate> {
const response = await fetch(`${API_BASE_URL}/live-blogs/${liveBlogId}/updates/${updateId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(dto),
});
if (!response.ok) {
throw new Error('Failed to update live blog update');
}
return response.json();
}
export async function deleteLiveBlogUpdate(liveBlogId: string, updateId: string): Promise<void> {
const response = await fetch(`${API_BASE_URL}/live-blogs/${liveBlogId}/updates/${updateId}`, {
method: 'DELETE',
});
if (!response.ok) {
throw new Error('Failed to delete live blog update');
}
}