From 0c884fd2a63a6f89194eb68c5fd79c8b7ee96cc3 Mon Sep 17 00:00:00 2001 From: numex-admin Date: Thu, 10 Sep 2026 09:22:42 +0000 Subject: [PATCH] =?UTF-8?q?Numex=20yay=C4=B1n:=20public/js/api.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/api.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 public/js/api.js diff --git a/public/js/api.js b/public/js/api.js new file mode 100644 index 0000000..4665f3f --- /dev/null +++ b/public/js/api.js @@ -0,0 +1,65 @@ +// Ortak API yardımcıları + format fonksiyonları +const API = { + kategoriler: () => fetch('/api/kategoriler').then((r) => r.json()), + ilanlar: (params = '') => fetch(`/api/ilanlar${params}`).then((r) => r.json()), + ilan: (id) => fetch(`/api/ilanlar/${id}`).then((r) => (r.ok ? r.json() : null)), + ilanEkle: (veri) => + fetch('/api/ilanlar', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(veri), + }).then((r) => r.json()), + ilanGuncelle: (id, veri) => + fetch(`/api/ilanlar/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(veri), + }).then((r) => r.json()), + ilanSil: (id) => fetch(`/api/ilanlar/${id}`, { method: 'DELETE' }).then((r) => r.json()), + mesajlar: (ilanId) => fetch(`/api/mesajlar/${ilanId}`).then((r) => r.json()), + mesajGonder: (veri) => + fetch('/api/mesajlar', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(veri), + }).then((r) => r.json()), +}; + +function paraSayi(deger) { + const n = Number(deger); + if (isNaN(n)) return deger; + return n.toLocaleString('tr-TR') + ' ₺'; +} + +function fiyatOzet(deger) { + const n = Number(deger); + if (n >= 1000000) return (n / 1000000).toLocaleString('tr-TR', { maximumFractionDigits: 2 }) + ' M TL'; + return paraSayi(deger); +} + +// Üst barı tüm sayfalara gömer +function ustbariCiz(aktif) { + const aktifArama = new URLSearchParams(location.search).get('q') || ''; + document.body.insertAdjacentHTML( + 'afterbegin', + ` +
+
+ + + +
+
+ ` + ); + if (aktif) { + const el = document.querySelector(`[data-aktif="${aktif}"]`); + if (el) el.style.fontWeight = '700'; + } +}