Restored to 'eede1dca5c3b2cb640881195fc428ec171b5dce3'
Replit-Restored-To: eede1dca5c
This commit is contained in:
+1
-10
@@ -1,6 +1,6 @@
|
||||
import { type Article, type InsertArticle, articles } from "@shared/schema";
|
||||
import { db } from "./db";
|
||||
import { eq, desc, sql, count } from "drizzle-orm";
|
||||
import { eq, desc, sql } from "drizzle-orm";
|
||||
|
||||
export interface IStorage {
|
||||
getArticles(): Promise<Article[]>;
|
||||
@@ -9,7 +9,6 @@ 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>;
|
||||
@@ -43,14 +42,6 @@ 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