fix(news): restore publication flow and deduplicate dashboard friends
This commit is contained in:
1 parent
ef94646d60
commit
9b0ea2fb16
22 files changed
+638
-195
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { and, eq, or, sql } from "drizzle-orm";
|
||||
import { apiJson } from "@/lib/api";
|
||||
import { db, WebsiteArticles } from "@/lib/db";
|
||||
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
|
||||
import { cacheNews } from "@/lib/services/news-cache";
|
||||
|
||||
/**
|
||||
* GET /api/articles/:slug — single website_article by slug, including the
|
||||
@@ -14,9 +16,9 @@ export async function GET(
|
||||
const { slug } = await params;
|
||||
|
||||
try {
|
||||
const data = await redisCache(
|
||||
const data = await cacheNews(
|
||||
apiCacheKey(`articles:${slug}`),
|
||||
60,
|
||||
60_000,
|
||||
async () => {
|
||||
const [article] = await db
|
||||
.select({
|
||||
@@ -55,7 +57,8 @@ export async function GET(
|
||||
}
|
||||
|
||||
return apiJson(data);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.error("Public news query failed", { module: "news", error });
|
||||
// DB unavailable — treat as not found rather than a 500.
|
||||
return apiJson({ error: "Article not found" }, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { and, count, desc, eq, or, sql } from "drizzle-orm";
|
||||
import { apiJson, pagination } from "@/lib/api";
|
||||
import { db, WebsiteArticles } from "@/lib/db";
|
||||
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
|
||||
import { cacheNews } from "@/lib/services/news-cache";
|
||||
|
||||
/**
|
||||
* GET /api/articles — paginated list of website_articles, newest first.
|
||||
@@ -13,9 +15,9 @@ export async function GET(req: Request) {
|
||||
const { page, perPage, skip, take } = pagination(sp);
|
||||
|
||||
try {
|
||||
const data = await redisCache(
|
||||
const data = await cacheNews(
|
||||
apiCacheKey(`articles:${page}:${perPage}`),
|
||||
60,
|
||||
60_000,
|
||||
async () => {
|
||||
const publishedFilter = and(
|
||||
eq(WebsiteArticles.status, "published"),
|
||||
@@ -60,7 +62,8 @@ export async function GET(req: Request) {
|
||||
);
|
||||
|
||||
return apiJson(data);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.error("Public news query failed", { module: "news", error });
|
||||
// DB unavailable — return an empty payload instead of a 500.
|
||||
return apiJson(
|
||||
{ data: [], meta: { page, perPage, total: 0, lastPage: 1 } },
|
||||
|
||||
Reference in new issue
Block a user