Restored to '3905f52571b4fa7e048e16d7a3b94ee66307d072'

Replit-Restored-To: 3905f52571
This commit is contained in:
sebastjanartic
2026-03-05 12:19:10 +00:00
parent 7434438c1e
commit c13a5150b8
41 changed files with 1706 additions and 667 deletions
+10 -1
View File
@@ -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;