webstar-project stubs api #3

Merged
Deolys merged 2 commits from webstar-branch into master 2024-05-22 22:47:02 +03:00
6 changed files with 522 additions and 0 deletions
Showing only changes of commit 7c3132c54b - Show all commits

View File

@ -57,6 +57,7 @@ app.use('/example', require('./routers/example'))
app.use('/zoom-bar', require('./routers/zoom-bar'))
app.use('/r-and-m', require('./routers/r-and-m'))
app.use('/edateam', require('./routers/edateam'))
app.use('/webstar-project', require('./routers/webstar-project'))
//app.use('/basket', require('./routers/basket'))
//app.use('/easy-project', require('./routers/easy-project'))
//app.use('/sugarbun', require('./routers/sugarbun'))

View File

@ -0,0 +1,136 @@
const router = require('express').Router();
const authMiddleware = require('./middleware/auth-middleware');
router.get('/cards-data', (request, response) => {
response.send(require('./json/cards-data/success.json'))
})
router.get('/messages', (request, response) => {
response.send(require('./json/messages/success.json'))
})
router.get('/user', authMiddleware, (request, response) => {
const email = request.userEmail;
try {
const usersData = require('./json/users-data/success.json');
const userData = usersData.data.find(user => user.email === email);
if (userData) {
return response.json(userData.favourites);
}
response.status(404).send('User not found');
} catch (error) {
console.error('Error reading file:', error);
response.status(500).send('Internal server error');
}
})
router.get('/cards-data/:id', (request, response) => {
const cardId = request.params.id;
try {
const cardsData = require('./json/cards-data/success.json');
const cardData = cardsData.data.find(card => card.id === cardId);
if (cardData) {
return response.json(cardData);
}
response.status(404).send('Card not found');
} catch (error) {
console.error('Error reading file:', error);
response.status(500).send('Internal server error');
}
})
router.get('/messages/:id', (request, response) => {
const cardId = request.params.id;
try {
const cardsData = require('./json/messages/success.json');
const cardData = cardsData.data.find(card => card.id === cardId);
if (cardData) {
return response.json(cardData);
}
response.status(404).send('Card not found');
} catch (error) {
console.error('Error reading file:', error);
response.status(500).send('Internal server error');
}
})
router.post('/login', (request, response) => {
const { email, password } = request.body.loginData;
try {
const users = require('./json/users-data/success.json');
const user = users.data.find(user => user.email === email && user.password === password);
if (!user) {
response.status(401).send('Invalid credentials');
}
const responseObject = {
email: user.email,
}
if (user.cardId){
responseObject.cardId = user.cardId || "";
}
return response.json(responseObject);
} catch (error) {
console.error('Error reading file:', error);
response.status(500).send('Internal server error');
}
})
router.post('/register', async (request, response) => {
const { _name, email, password, confirmPassword } = request.body.registerData;
try {
if (password !== confirmPassword) {
return response.status(400).send('Passwords do not match');
}
const users = require('./json/users-data/success.json');
const existingUser = users.data.find(user => user.email === email);
if (existingUser) {
return response.status(400).send('User with this email already exists');
}
return response.json({ email: email});
} catch (error) {
console.error('Error registering user:', error);
response.status(500).send('Internal server error');
}
});
router.post('/favourite', async (request, response) => {
const { cardId, email } = request.body;
try {
const users = require('./json/users-data/success.json');
const user = users.data.find(user => user.email === email);
if (!user) {
return response.status(404).send('User not found');
}
const index = user.favourites.indexOf(cardId);
if (index !== -1) {
return response.status(200).send('Card removed from favourites successfully');
}
response.status(200).send('Card added to favourites successfully');
} catch (error) {
console.error('Error adding card to favourites:', error);
response.status(500).send('Internal server error');
}
});
module.exports = router;

View File

@ -0,0 +1,172 @@
{
"data": [
{
"id": "1",
"ownerId": "user1@gmail.com",
"sliderImages": ["site1", "site2", "site3"],
"title": "Верстка сайтов любой сложности. Мобильная разработка",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Yuji Itadori",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site1",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "2",
"ownerId": "admin@admin.ru",
"sliderImages": ["site2", "site1", "site3"],
"title": "Дизайн сайтов. Разработка сайтов под ключ",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Admin",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site2",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "3",
"ownerId": "user2@gmail.com",
"sliderImages": ["site3", "site1", "site3"],
"title": "FullStack разработка приложений на React",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Secret Guest",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site3",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "4",
"ownerId": "super@star.ru",
"sliderImages": ["site1", "site1", "site3"],
"title": "Верстка сайтов любой сложности. Мобильная разработка",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Hatsune Miku",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site3",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "5",
"ownerId": "sb@sb.ru",
"sliderImages": ["site2", "site1", "site3"],
"title": "Дизайн сайтов. Разработка сайтов под ключ",
"tags": ["Дизайн", "Под ключ"],
"profileData": {
"name": "СберТян",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site3",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "6",
"ownerId": "tin@tin.ru",
"sliderImages": ["site3", "site1", "site3"],
"title": "FullStack разработка приложений на React",
"tags": ["Сайты", "Под ключ", "Мобильные устройства"],
"profileData": {
"name": "Помощник Олег",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site3",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
}
]
}

View File

@ -0,0 +1,149 @@
{
"data": [
{
"id": "1",
"ownerId": "user1@gmail.ru",
"onModerating": true,
"sliderImages": ["site1", "site2", "site3"],
"title": "Верстка сайтов любой сложности. Мобильная разработка",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Yuji Itadori",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "site2",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "2",
"ownerId": "admin@admin.ru",
"onModerating": true,
"sliderImages": ["site2", "site1", "site3"],
"title": "Дизайн сайтов. Разработка сайтов под ключ",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Admin",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "profilePicture1",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "3",
"ownerId": "user2@gmail.com",
"onModerating": true,
"sliderImages": ["site3", "site1", "site3"],
"title": "FullStack разработка приложений на React",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Secret Guest",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "profilePicture1",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "4",
"ownerId": "super@star.ru",
"onModerating": true,
"sliderImages": ["site1", "site1", "site3"],
"title": "Верстка сайтов любой сложности. Мобильная разработка",
"tags": ["Сайты", "Под ключ", "Десктоп"],
"profileData": {
"name": "Hatsune Miku",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "profilePicture1",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
},
{
"id": "5",
"ownerId": "sb@sb.ru",
"onModerating": false,
"sliderImages": ["site2", "site1", "site3"],
"title": "Дизайн сайтов. Разработка сайтов под ключ",
"tags": ["Дизайн", "Под ключ"],
"profileData": {
"name": "СберТян",
"geolocation": "г. Казань",
"description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Expedita nemo cumque, magni doloremque aspernatur illo nisi magnam! Perspiciatis, aspernatur excepturi dolores autem, ut sequi dolore vitae doloremque ratione expedita velit molestias quidem hic quod culpa corrupti vel ad.",
"profilePicture": "profilePicture1",
"backgroundImage": "backgroundImage1"
},
"articles": [
{
"id": "1",
"label": "Верстка статичного сайта",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site1"
},
{
"id": "2",
"label": "Разработка простого мобильного приложения",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"imageUrl": "site2"
}
]
}
]
}

View File

@ -0,0 +1,50 @@
{
"data": [
{
"name": "Yuji Itadori",
"email": "user1@gmail.com",
"password": "12345",
"cardId": "1",
"favourites": [
"1",
"2",
"6"
]
},
{
"name": "Admin",
"email": "admin@admin.ru",
"password": "*****",
"cardId": "2",
"favourites": []
},
{
"name": "Secret Guest",
"email": "user2@gmail.com",
"password": "qwer",
"cardId": "3",
"favourites": []
},
{
"name": "Hatsune Miku",
"email": "super@star.ru",
"password": "12345",
"cardId": "4",
"favourites": []
},
{
"name": "СберТян",
"email": "sb@sb.ru",
"password": "12345",
"cardId": "5",
"favourites": []
},
{
"name": "Помощник Олег",
"email": "tin@tin.ru",
"password": "12345",
"cardId": "6",
"favourites": []
}
]
}

View File

@ -0,0 +1,14 @@
const authMiddleware = (req, res, next) => {
const email = (req.headers.authorization || "").replace("Bearer ", "");
if (email) {
req.userEmail = email;
next();
} else {
return res.status(403).json({
message: "Access Denied",
});
}
};
module.exports = authMiddleware