From a0eb089d1c16dcbbc954067eb6f69a6e37a10886 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 29 Apr 2023 14:20:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D1=83=20=D0=B2=D1=80=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=B0=D0=BA=20=D0=B2=D1=81=D0=B5=20=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=20=D0=9D=D0=9E=20=D0=9A=D0=A2=D0=9E=20=D0=97?= =?UTF-8?q?=D0=9D=D0=90=D0=95=D0=A2=20=D0=A7=D0=A2=D0=9E=20=D0=A2=D0=90?= =?UTF-8?q?=D0=9C=20=D0=95=D0=A9=D0=95=20=D0=9F=D0=A0=D0=98=D0=94=D0=95?= =?UTF-8?q?=D0=A2=20=D0=92=20=D0=93=D0=9E=D0=9B=D0=9E=D0=92=D0=A3=20=D0=9F?= =?UTF-8?q?=D0=A0=D0=9E=D0=92=D0=95=D0=A0=D0=AF=D0=AE=D0=A9=D0=95=D0=9C?= =?UTF-8?q?=D0=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/abitur.controller.js | 28 ++- .../controllers/examresult.controller.js | 10 + .../controllers/request.controller.js | 10 + abitur_list_client/package.json | 2 +- abitur_list_client/routes/abitur.routes.js | 3 + .../routes/examresult.routes.js | 2 + abitur_list_client/routes/request.routes.js | 4 +- abitur_list_client/src/App.vue | 2 + .../src/components/AbiturMain.vue | 21 +- abitur_list_client/src/components/Auth.vue | 65 ++++-- abitur_list_client/src/components/Enter.vue | 74 +++++++ abitur_list_client/src/components/Request.vue | 67 ++++-- .../src/components/TestPage.vue | 195 ++++++++++++++++++ abitur_list_client/src/main.js | 12 ++ 14 files changed, 446 insertions(+), 49 deletions(-) create mode 100644 abitur_list_client/src/components/Enter.vue create mode 100644 abitur_list_client/src/components/TestPage.vue diff --git a/abitur_list_client/controllers/abitur.controller.js b/abitur_list_client/controllers/abitur.controller.js index 90351d8..033365c 100644 --- a/abitur_list_client/controllers/abitur.controller.js +++ b/abitur_list_client/controllers/abitur.controller.js @@ -1,11 +1,24 @@ const db = require('../db') +const crypto = require('crypto'); const AbiturControllerInterface = require('./interfaces/abitur.controller.interface') class AbiturController extends AbiturControllerInterface{ + async createAbitur(req, res) { - const {first_name, last_name, middle_name} = req.body - const newAbitur = await db.query('INSERT INTO abitur (first_name, last_name, middle_name) VALUES ($1, $2, $3) RETURNING *', [first_name, last_name, middle_name]) + const {first_name, last_name, middle_name, email, password} = req.body + + var hash = crypto.createHash('md5').update(password).digest('hex'); + + const newAbitur = await db.query('INSERT INTO abitur (first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5) RETURNING *', [first_name, last_name, middle_name, email, hash]) + res.json(newAbitur.rows[0]) + } + async createAbiturWithId(req, res) { + const {id, first_name, last_name, middle_name, email, password} = req.body + + var hash = crypto.createHash('md5').update(password).digest('hex'); + + const newAbitur = await db.query('INSERT INTO abitur (id, first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *', [id, first_name, last_name, middle_name, email, hash]) res.json(newAbitur.rows[0]) } async getAbiturs(req, res) { @@ -17,6 +30,13 @@ class AbiturController extends AbiturControllerInterface{ const abiturs = await db.query('SELECT * FROM abitur WHERE id=$1', [id]) res.json(abiturs.rows[0]) } + async authAbitur(req, res) { + const {email, password} = req.body + + var hash = crypto.createHash('md5').update(password).digest('hex'); + const abitur = await db.query('SELECT * FROM abitur WHERE email = $1 AND password = $2', [email, hash]) + res.json(abitur.rows[0]) + } async updateAbitur(req, res) { const {id, first_name, last_name, middle_name} = req.body const newAbitur = await db.query('UPDATE abitur SET first_name=$1, last_name=$2, middle_name=$3 WHERE id=$4 RETURNING *', [first_name, last_name, middle_name, id]) @@ -27,6 +47,10 @@ class AbiturController extends AbiturControllerInterface{ const abiturs = await db.query('DELETE FROM abitur WHERE id=$1', [id]) res.json(abiturs.rows[0]) } + async deleteAll(req, res) { + const abiturs = await db.query('DELETE FROM abitur') + res.json(abiturs.rows) + } } module.exports = new AbiturController() \ No newline at end of file diff --git a/abitur_list_client/controllers/examresult.controller.js b/abitur_list_client/controllers/examresult.controller.js index c60a6ca..c4f0ad1 100644 --- a/abitur_list_client/controllers/examresult.controller.js +++ b/abitur_list_client/controllers/examresult.controller.js @@ -8,6 +8,11 @@ class ExamResultController extends ExamResultControllerInterface { const newExamResult = await db.query('INSERT INTO exam_result (title, result, abitur_id) VALUES ($1, $2, $3) RETURNING *', [title, result, abitur_id]) res.json(newExamResult.rows[0]) } + async createExamResultWithId(req, res) { + const {id, title, result, abitur_id} = req.body + const newExamResult = await db.query('INSERT INTO exam_result (id, title, result, abitur_id) VALUES ($1, $2, $3, $4) RETURNING *', [id, title, result, abitur_id]) + res.json(newExamResult.rows[0]) + } async getExamResults(req, res) { const results = await db.query('SELECT * FROM exam_result') res.json(results.rows) @@ -32,6 +37,11 @@ class ExamResultController extends ExamResultControllerInterface { const results = await db.query('SELECT * FROM exam_result WHERE abitur_id=$1', [id]) res.json(results.rows) } + async getAverageResultBySpecialization(req, res) { + const id = req.params.id + const result = await db.query('select avg(result) from exam_result where id in (select exam_result_id from request_exam_result where request_id in (select id from request where specialization_id = $1))', [id]) + res.json(result.rows[0]) + } } module.exports = new ExamResultController() \ No newline at end of file diff --git a/abitur_list_client/controllers/request.controller.js b/abitur_list_client/controllers/request.controller.js index c3b353a..0685adb 100644 --- a/abitur_list_client/controllers/request.controller.js +++ b/abitur_list_client/controllers/request.controller.js @@ -8,6 +8,11 @@ class RequestController extends RequestControllerInterface { const newRequest = await db.query('INSERT INTO request (abitur_id, education_form_id, specialization_id, date) VALUES ($1, $2, $3, $4) RETURNING *', [abitur_id, education_form_id, specialization_id, new Date()]) res.json(newRequest.rows[0]) } + async createRequestWithId(req, res) { + const {id, abitur_id, education_form_id, specialization_id} = req.body + const newRequest = await db.query('INSERT INTO request (id, abitur_id, education_form_id, specialization_id, date) VALUES ($1, $2, $3, $4, $5) RETURNING *', [id, abitur_id, education_form_id, specialization_id, new Date()]) + res.json(newRequest.rows[0]) + } async getRequests(req, res) { const requests = await db.query('SELECT * FROM request') res.json(requests.rows) @@ -32,6 +37,11 @@ class RequestController extends RequestControllerInterface { const requests = await db.query('SELECT * FROM request WHERE abitur_id=$1', [id]) res.json(requests.rows) } + async getCountBySpec(req, res) { + const id = req.params.id + const requests = await db.query('SELECT COUNT(*) FROM request WHERE specialization_id=$1', [id]) + res.json(requests.rows[0]) + } } module.exports = new RequestController() \ No newline at end of file diff --git a/abitur_list_client/package.json b/abitur_list_client/package.json index 1a4cafd..dd6f247 100644 --- a/abitur_list_client/package.json +++ b/abitur_list_client/package.json @@ -5,7 +5,7 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "start": "pm2 start index.js --watch" + "start": "pm2 start index.js" }, "dependencies": { "axios": "^1.3.4", diff --git a/abitur_list_client/routes/abitur.routes.js b/abitur_list_client/routes/abitur.routes.js index 1788d82..8ca3955 100644 --- a/abitur_list_client/routes/abitur.routes.js +++ b/abitur_list_client/routes/abitur.routes.js @@ -4,9 +4,12 @@ const router = new Router() const abiturController = require('../controllers/abitur.controller') router.post('/abitur', abiturController.createAbitur) +router.post('/abitur/manual', abiturController.createAbiturWithId) router.get('/abitur', abiturController.getAbiturs) router.get('/abitur/:id', abiturController.getOneAbitur) +router.post('/abitur/auth/', abiturController.authAbitur) router.put('/abitur', abiturController.updateAbitur) router.delete('/abitur/:id', abiturController.deleteAbitur) +router.delete('/abitur', abiturController.deleteAll) module.exports = router \ No newline at end of file diff --git a/abitur_list_client/routes/examresult.routes.js b/abitur_list_client/routes/examresult.routes.js index 73fc103..9d0bb3a 100644 --- a/abitur_list_client/routes/examresult.routes.js +++ b/abitur_list_client/routes/examresult.routes.js @@ -4,10 +4,12 @@ const router = new Router() const examResultController = require('../controllers/examresult.controller') router.post('/examresult', examResultController.createExamResult) +router.post('/examresult/manual', examResultController.createExamResultWithId) router.get('/examresult', examResultController.getExamResults) router.get('/examresult/:id', examResultController.getOneExamResult) router.put('/examresult', examResultController.updateExamResult) router.delete('/examresult/:id', examResultController.deleteExamResult) router.get('/examresult/abitur/:id', examResultController.getAbiturExamResults) +router.get('/examresult/avgBySpec/:id', examResultController.getAverageResultBySpecialization) module.exports = router \ No newline at end of file diff --git a/abitur_list_client/routes/request.routes.js b/abitur_list_client/routes/request.routes.js index f3473b3..9178ea6 100644 --- a/abitur_list_client/routes/request.routes.js +++ b/abitur_list_client/routes/request.routes.js @@ -4,10 +4,12 @@ const router = new Router() const requestController = require('../controllers/request.controller') router.post('/request', requestController.createRequest) +router.post('/request/manual', requestController.createRequestWithId) router.get('/request', requestController.getRequests) -router.get('/request/:id', requestController.getRequests) +router.get('/request/:id', requestController.getOneRequest) router.put('/request', requestController.updateRequest) router.delete('/request/:id', requestController.deleteRequest) router.get('/request/abitur/:id', requestController.getAbiturRequests) +router.get('/request/spec/:id', requestController.getCountBySpec) module.exports = router \ No newline at end of file diff --git a/abitur_list_client/src/App.vue b/abitur_list_client/src/App.vue index 48aa158..73ad261 100644 --- a/abitur_list_client/src/App.vue +++ b/abitur_list_client/src/App.vue @@ -1,4 +1,6 @@ diff --git a/abitur_list_client/src/components/AbiturMain.vue b/abitur_list_client/src/components/AbiturMain.vue index 2481551..b2068a8 100644 --- a/abitur_list_client/src/components/AbiturMain.vue +++ b/abitur_list_client/src/components/AbiturMain.vue @@ -1,9 +1,21 @@