2024-06-01 19:53:28 +03:00
|
|
|
|
const router = require('express').Router();
|
2024-12-27 22:15:06 +03:00
|
|
|
|
|
2024-06-01 19:53:28 +03:00
|
|
|
|
|
2024-06-01 20:22:43 +03:00
|
|
|
|
// First page
|
|
|
|
|
router.get('/getInfoAboutKazan', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru'; // Получаем язык из параметров запроса
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require('./json/first/info-about-kazan/success.json'); // Загружаем весь JSON
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const translatedData = data[lang] || data['ru']; // Выбираем перевод по языку или дефолтный
|
|
|
|
|
response.send(translatedData); // Отправляем перевод клиенту
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(500).send({ message: 'Internal server error' }); // Ошибка в случае проблем с JSON
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-01 20:22:43 +03:00
|
|
|
|
|
|
|
|
|
router.get('/getNews', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/first/news/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 20:22:43 +03:00
|
|
|
|
})
|
|
|
|
|
|
2024-06-01 19:53:28 +03:00
|
|
|
|
// Sport page
|
2024-12-27 22:15:06 +03:00
|
|
|
|
router.get('/getFirstText', (request, response) => {
|
|
|
|
|
const lang = request.query.lang || 'ru'; // Получаем язык из параметров
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require('./json/sport/first-text/success.json'); // Загружаем JSON
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const translatedData = data[lang] || data['ru']; // Берём перевод или дефолтный
|
|
|
|
|
response.send(translatedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' }); // Обработка ошибки
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/getSecondText', (request, response) => {
|
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require('./json/sport/second-text/success.json');
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const translatedData = data[lang] || data['ru'];
|
|
|
|
|
response.send(translatedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-01 19:53:28 +03:00
|
|
|
|
router.get('/getSportData', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/sport/sport-list/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Places page
|
|
|
|
|
router.get('/getPlacesData', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/places/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Transport page
|
|
|
|
|
router.get('/getInfoAboutTransportPage', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require('./json/transport/info-about-page/success.json');
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const translatedData = data[lang] || data['ru'];
|
|
|
|
|
response.send(translatedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.get('/getBus', (request, response) => {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
response.send(require('./json/transport/bus-numbers/success.json'))
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.get('/getTral', (request, response) => {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
response.send(require('./json/transport/tral-numbers/success.json'))
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.get('/getEvents', (request, response) => {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
response.send(require('./json/transport/events-calendar/success.json'))
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.get('/getTripSchedule', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/transport/trip-schedule/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
2024-12-27 22:15:06 +03:00
|
|
|
|
// History page
|
|
|
|
|
router.get('/getHistoryText', (request, response) => {
|
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/history/text/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
router.get('/getHistoryList', (request, response) => {
|
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/history/list/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 20:22:43 +03:00
|
|
|
|
})
|
|
|
|
|
|
2024-06-01 19:53:28 +03:00
|
|
|
|
// Education page
|
2024-12-27 22:15:06 +03:00
|
|
|
|
router.get('/getInfoAboutEducation', (request, response) => {
|
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require('./json/education/text/success.json');
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const translatedData = data[lang] || data['ru'];
|
|
|
|
|
response.send(translatedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
router.get('/getEducationList', (request, response) => {
|
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require(`./json/education/cards/${lang}/success.json`);
|
2024-12-27 22:15:06 +03:00
|
|
|
|
response.send(data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-06-01 19:53:28 +03:00
|
|
|
|
router.get('/getInfoAboutKFU', (request, response) => {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const lang = request.query.lang || 'ru';
|
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const data = require('./json/education/kfu/success.json');
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const translatedData = data[lang] || data['ru'];
|
|
|
|
|
response.send(translatedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response.status(404).send({ message: 'Language not found' });
|
|
|
|
|
}
|
2024-06-01 19:53:28 +03:00
|
|
|
|
})
|
|
|
|
|
|
2024-12-27 22:15:06 +03:00
|
|
|
|
|
2024-06-01 19:53:28 +03:00
|
|
|
|
// Login
|
|
|
|
|
router.post('/entrance', (request, response) => {
|
|
|
|
|
const { email, password } = request.body.entranceData;
|
2024-12-27 22:15:06 +03:00
|
|
|
|
|
2024-06-01 19:53:28 +03:00
|
|
|
|
try {
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const users = require('./json/users-information/success.json');
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const user = users.data.find(user => user.email === email && user.password === password);
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return response.status(401).send('Неверные учетные данные');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const responseObject = {
|
|
|
|
|
email: user.email,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response.json(responseObject);
|
2024-06-01 19:53:28 +03:00
|
|
|
|
} catch (error) {
|
2024-12-27 22:15:06 +03:00
|
|
|
|
console.error('Ошибка чтения файла:', error);
|
|
|
|
|
response.status(500).send('Внутренняя ошибка сервера');
|
2024-06-01 19:53:28 +03:00
|
|
|
|
}
|
2024-12-27 22:15:06 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.post('/registration', async (request, response) => {
|
|
|
|
|
const { email, password, confirmPassword } = request.body.registerData;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (password !== confirmPassword) {
|
|
|
|
|
return response.status(400).send('Пароли не совпадают!');
|
|
|
|
|
}
|
2024-12-27 22:55:08 +03:00
|
|
|
|
const users = require('./json/users-information/success.json');
|
2024-06-01 19:53:28 +03:00
|
|
|
|
|
2024-12-27 22:15:06 +03:00
|
|
|
|
const existingUser = users.data.find(user => user.email === email);
|
2024-06-01 19:53:28 +03:00
|
|
|
|
|
2024-12-27 22:15:06 +03:00
|
|
|
|
if (existingUser) {
|
|
|
|
|
return response.status(400).send('Пользователь с такой почтой уже существует!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response.json({ email: email });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Ошибка регистрации пользователя:', error);
|
|
|
|
|
response.status(500).send('Внутренняя ошибка сервера');
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-01 19:53:28 +03:00
|
|
|
|
|
|
|
|
|
module.exports = router;
|