f833d429fc
Backend altyapısı: - 4 yeni Appwrite tablosu: blog_posts, testimonials, seo_pages, seo_settings - Appwrite Storage bucket: kovak-yazilim-media (görsel yüklemeleri) - Appwrite Auth ile session cookie tabanlı koruma Admin paneli (/admin): - Login akışı (email/password) + protected layout - Dashboard: sayım kartları + hızlı aksiyonlar - Blog CRUD: markdown content, kapak görseli, draft/published, SEO alanları - Services CRUD: lucide ikon seçici - Projects CRUD: teknoloji etiketleri, live URL - Testimonials CRUD: puanlama - SEO yöneticisi: global ayarlar + sayfa bazlı override - Mesaj inbox: status filtreleme + güncelleme - Medya kütüphanesi: Appwrite Storage upload/delete Public: - /blog ve /blog/[slug] sayfaları (markdown render) - Anasayfaya Testimonials bölümü - Tüm public sayfalarda generateMetadata + seo_pages override - Header'a Blog linki Route yapısı: - app/(site)/ — public site, Header/Footer ortak - app/admin/login — auth dışı - app/admin/(protected)/ — requireUser() korumalı 23 route üretiliyor, public static, admin dynamic.
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
import "server-only";
|
|
import { Query } from "node-appwrite";
|
|
import { adminDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
|
|
import type {
|
|
BlogPostRow,
|
|
ContactMessageRow,
|
|
ProjectRow,
|
|
ServiceRow,
|
|
SeoPageRow,
|
|
SeoSettingsRow,
|
|
TestimonialRow,
|
|
} from "@/lib/types";
|
|
|
|
async function safeList<T>(
|
|
tableId: string,
|
|
queries: string[],
|
|
): Promise<T[]> {
|
|
try {
|
|
const res = await adminDB.listRows<T extends import("appwrite").Models.Row ? T : never>({
|
|
databaseId: DATABASE_ID,
|
|
tableId,
|
|
queries,
|
|
});
|
|
return res.rows as T[];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export async function listServices(opts?: { featured?: boolean }) {
|
|
const q = [Query.orderAsc("order"), Query.limit(50)];
|
|
if (opts?.featured) q.unshift(Query.equal("featured", true));
|
|
return safeList<ServiceRow>(TABLES.services, q);
|
|
}
|
|
|
|
export async function listProjects(opts?: { featured?: boolean; limit?: number }) {
|
|
const q = [Query.orderDesc("year"), Query.limit(opts?.limit ?? 50)];
|
|
if (opts?.featured) q.unshift(Query.equal("featured", true));
|
|
return safeList<ProjectRow>(TABLES.projects, q);
|
|
}
|
|
|
|
export async function listPublishedPosts(opts?: { limit?: number }) {
|
|
return safeList<BlogPostRow>(TABLES.blogPosts, [
|
|
Query.equal("status", "published"),
|
|
Query.orderDesc("published_at"),
|
|
Query.limit(opts?.limit ?? 50),
|
|
]);
|
|
}
|
|
|
|
export async function listAllPosts() {
|
|
return safeList<BlogPostRow>(TABLES.blogPosts, [
|
|
Query.orderDesc("$createdAt"),
|
|
Query.limit(200),
|
|
]);
|
|
}
|
|
|
|
export async function getPostBySlug(slug: string): Promise<BlogPostRow | null> {
|
|
const res = await safeList<BlogPostRow>(TABLES.blogPosts, [
|
|
Query.equal("slug", slug),
|
|
Query.limit(1),
|
|
]);
|
|
return res[0] ?? null;
|
|
}
|
|
|
|
export async function listTestimonials(opts?: { featured?: boolean }) {
|
|
const q = [Query.orderAsc("order"), Query.limit(50)];
|
|
if (opts?.featured) q.unshift(Query.equal("featured", true));
|
|
return safeList<TestimonialRow>(TABLES.testimonials, q);
|
|
}
|
|
|
|
export async function listMessages(status?: ContactMessageRow["status"]) {
|
|
const q = [Query.orderDesc("$createdAt"), Query.limit(200)];
|
|
if (status) q.unshift(Query.equal("status", status));
|
|
return safeList<ContactMessageRow>(TABLES.contactMessages, q);
|
|
}
|
|
|
|
export async function getSeoPage(path: string): Promise<SeoPageRow | null> {
|
|
const res = await safeList<SeoPageRow>(TABLES.seoPages, [
|
|
Query.equal("path", path),
|
|
Query.limit(1),
|
|
]);
|
|
return res[0] ?? null;
|
|
}
|
|
|
|
export async function listSeoPages() {
|
|
return safeList<SeoPageRow>(TABLES.seoPages, [
|
|
Query.orderAsc("path"),
|
|
Query.limit(200),
|
|
]);
|
|
}
|
|
|
|
export async function getSeoSettings(): Promise<SeoSettingsRow | null> {
|
|
try {
|
|
return await adminDB.getRow<SeoSettingsRow>({
|
|
databaseId: DATABASE_ID,
|
|
tableId: TABLES.seoSettings,
|
|
rowId: "global",
|
|
});
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function getRow<T>(tableId: string, rowId: string): Promise<T | null> {
|
|
try {
|
|
return (await adminDB.getRow({ databaseId: DATABASE_ID, tableId, rowId })) as T;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|