Merge pull request 'school-stage stubs' (#22) from school-stage-branch into master

Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/22
This commit is contained in:
prdcsi 2024-06-02 20:16:40 +03:00
commit eb6da8aa1b
2 changed files with 69 additions and 32 deletions

View File

@ -1,14 +1,49 @@
const router = require('express').Router(); /*const router = require('express').Router();
module.exports = router;
router.get('/teachers', (request, response) => { router.get('/teachers', (request, response) => {
response.send(require('./json/teachers/success.json')) response.send(require('../json/teachers/success.json'))
}) })
router.get('/account', (request, response) => { router.get('/account', (request, response) => {
response.send(require('./json/account/account.json')) response.send(require('../json/account/account.json'))
})
router.post('/login', (request, response) => {
response.send(require('./json/login/success.json'))
}) })
module.exports = router; router.post('/login', (request, response) => {
response.send(require('../json/login/success.json'))
})*/
const router = require('express').Router();
router.get('/teachers', (request, response) => {
response.send(require('../json/teachers/success.json'))
})
router.get('/account', (request, response) => {
response.send(require('../json/account/account.json'))
})
router.post('/login', (request, response) => {
const login = request.body.login;
const password = request.body.password;
try {
const users = require('../json/account/account.json');
const user = users.data.find(user => user.login === login && user.password === password);
if (!user) {
return response.status(401).send('Неверные данные');
}
const responseObject = {
login: user.login,
}
return response.json(responseObject);
} catch (error) {
console.error('Error reading file:', error);
response.status(400).send('Internal server error');
}
})
module.exports = router;

View File

@ -1,26 +1,28 @@
{ {
"data": [ "data": [
{ {
"login": "user1", "login": "user1",
"photo": "boy", "password":"1234",
"surname": "Иванов", "photo": "boy",
"name": "Иван", "surname": "Иванов",
"class": "2", "name": "Иван",
"group": "1", "class": "2",
"number": "+7 927 030 13 00", "group": "1",
"teacher": "Иванова Валерия Константиновна", "number": "+7 927 030 13 00",
"lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"] "teacher": "Иванова Валерия Константиновна",
}, "lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"]
{ },
"login": "user2", {
"photo": "boy", "login": "user2",
"surname": "Александров", "password":"123",
"name": "Александр", "photo": "boy",
"class": "3", "surname": "Иванов",
"group": "2", "name": "Иван",
"number": "+7 927 030 13 00", "class": "2",
"teacher": "Иванова Валерия Константиновна", "group": "1",
"lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"] "number": "+7 927 030 13 00",
} "teacher": "Иванова Валерия Константиновна",
] "lessons": ["02.05", "07.05", "14.05", "17.05", "21.05", "24.05", "28.05"]
} }
]
}