İlk sürüm: hDiyanetProxy v1.0.0
- Backend: Node.js + Express + MySQL + JWT auth - 8 MySQL tablosu (users, countries, states, cities, prayer_times, ramadan_times, eid_times, fetch_logs) - Diyanet API entegrasyonu (auth + token yönetimi) - Tüm API endpointleri (places, prayer-times, ramadan, eid, admin) - Rate limiting, CORS, input validation - Cron job (gece 02:00 otomatik veri çekme) - Frontend: Login, Dashboard, Fetch Panel, Namaz Vakitleri, Ramazan, Admin, Profil - Admin kullanıcı: admin/admin123
This commit is contained in:
80
backend/src/models/Place.js
Normal file
80
backend/src/models/Place.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// hDiyanetProxy - Yer Bilgisi Modeli
|
||||
const pool = require('../utils/db');
|
||||
|
||||
const PlaceModel = {
|
||||
// --- Ülkeler ---
|
||||
async upsertCountry(id, name) {
|
||||
await pool.execute(
|
||||
'INSERT INTO countries (id, name) VALUES (?, ?) ON DUPLICATE KEY UPDATE name = VALUES(name)',
|
||||
[id, name]
|
||||
);
|
||||
},
|
||||
|
||||
async getAllCountries() {
|
||||
const [rows] = await pool.execute('SELECT * FROM countries ORDER BY name');
|
||||
return rows;
|
||||
},
|
||||
|
||||
// --- Eyaletler / İller ---
|
||||
async upsertState(id, name, countryId) {
|
||||
await pool.execute(
|
||||
'INSERT INTO states (id, name, country_id) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE name = VALUES(name)',
|
||||
[id, name, countryId]
|
||||
);
|
||||
},
|
||||
|
||||
async getStatesByCountry(countryId) {
|
||||
const [rows] = await pool.execute('SELECT * FROM states WHERE country_id = ? ORDER BY name', [countryId]);
|
||||
return rows;
|
||||
},
|
||||
|
||||
async getAllStates() {
|
||||
const [rows] = await pool.execute('SELECT * FROM states ORDER BY name');
|
||||
return rows;
|
||||
},
|
||||
|
||||
// --- Şehirler / İlçeler ---
|
||||
async upsertCity(id, name, stateId, lat = null, lng = null) {
|
||||
await pool.execute(
|
||||
'INSERT INTO cities (id, name, state_id, latitude, longitude) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE name = VALUES(name), latitude = VALUES(latitude), longitude = VALUES(longitude)',
|
||||
[id, name, stateId, lat, lng]
|
||||
);
|
||||
},
|
||||
|
||||
async getCitiesByState(stateId) {
|
||||
const [rows] = await pool.execute('SELECT * FROM cities WHERE state_id = ? ORDER BY name', [stateId]);
|
||||
return rows;
|
||||
},
|
||||
|
||||
async getCityDetail(cityId) {
|
||||
const [rows] = await pool.execute(
|
||||
`SELECT c.*, s.name as state_name, co.name as country_name
|
||||
FROM cities c
|
||||
JOIN states s ON c.state_id = s.id
|
||||
JOIN countries co ON s.country_id = co.id
|
||||
WHERE c.id = ?`,
|
||||
[cityId]
|
||||
);
|
||||
return rows[0] || null;
|
||||
},
|
||||
|
||||
// İstatistikler
|
||||
async getStats() {
|
||||
const [[countries]] = await pool.execute('SELECT COUNT(*) as count FROM countries');
|
||||
const [[states]] = await pool.execute('SELECT COUNT(*) as count FROM states');
|
||||
const [[cities]] = await pool.execute('SELECT COUNT(*) as count FROM cities');
|
||||
const [[prayerTimes]] = await pool.execute('SELECT COUNT(*) as count FROM prayer_times');
|
||||
const [[ramadanTimes]] = await pool.execute('SELECT COUNT(*) as count FROM ramadan_times');
|
||||
const [[eidTimes]] = await pool.execute('SELECT COUNT(*) as count FROM eid_times');
|
||||
return {
|
||||
countries: countries.count,
|
||||
states: states.count,
|
||||
cities: cities.count,
|
||||
prayerTimes: prayerTimes.count,
|
||||
ramadanTimes: ramadanTimes.count,
|
||||
eidTimes: eidTimes.count
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = PlaceModel;
|
||||
Reference in New Issue
Block a user