Add pagination to article categories and video pages, and enhance home page with more content and ads
Implement paginated API endpoints for articles and videos, add pagination UI to category and video pages, and inject additional ads and content widgets into the home page. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c201f10b-bbd3-4402-9212-e0b79bfa670f Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/EtK2Sno Replit-Helium-Checkpoint-Created: true
This commit is contained in:
+10
-1
@@ -1,6 +1,6 @@
|
||||
import { type Article, type InsertArticle, articles } from "@shared/schema";
|
||||
import { db } from "./db";
|
||||
import { eq, desc, sql } from "drizzle-orm";
|
||||
import { eq, desc, sql, count } from "drizzle-orm";
|
||||
|
||||
export interface IStorage {
|
||||
getArticles(): Promise<Article[]>;
|
||||
@@ -9,6 +9,7 @@ export interface IStorage {
|
||||
getFeaturedArticles(): Promise<Article[]>;
|
||||
getPopularArticles(limit: number): Promise<Article[]>;
|
||||
getArticlesByCategory(category: string): Promise<Article[]>;
|
||||
getArticlesByCategoryPaginated(category: string, page: number, limit: number): Promise<{ articles: Article[]; total: number }>;
|
||||
createArticle(article: InsertArticle): Promise<Article>;
|
||||
updateArticle(id: number, article: Partial<InsertArticle>): Promise<Article | undefined>;
|
||||
incrementViews(id: number): Promise<void>;
|
||||
@@ -42,6 +43,14 @@ export class DatabaseStorage implements IStorage {
|
||||
return db.select().from(articles).where(eq(articles.category, category)).orderBy(desc(articles.publishedAt));
|
||||
}
|
||||
|
||||
async getArticlesByCategoryPaginated(category: string, page: number, limit: number): Promise<{ articles: Article[]; total: number }> {
|
||||
const offset = (page - 1) * limit;
|
||||
const [totalResult] = await db.select({ count: count() }).from(articles).where(eq(articles.category, category));
|
||||
const total = totalResult.count;
|
||||
const items = await db.select().from(articles).where(eq(articles.category, category)).orderBy(desc(articles.publishedAt)).limit(limit).offset(offset);
|
||||
return { articles: items, total };
|
||||
}
|
||||
|
||||
async createArticle(article: InsertArticle): Promise<Article> {
|
||||
const [created] = await db.insert(articles).values(article).returning();
|
||||
return created;
|
||||
|
||||
Reference in New Issue
Block a user