Создан контроллер для абитуриента
This commit is contained in:
parent
efa1fb8bb2
commit
c8f0d209ab
@ -0,0 +1,13 @@
|
||||
module.exports = class AbiturControllerInterface {
|
||||
async createAbitur(req, res) {
|
||||
}
|
||||
async getAbiturs(req, res) {
|
||||
}
|
||||
async getOneAbitur(req, res) {
|
||||
}
|
||||
async updateAbitur(req, res) {
|
||||
}
|
||||
async deleteAbitur(req, res) {
|
||||
|
||||
}
|
||||
}
|
32
abitur_list_client/controllers/abitur.controllers.js
Normal file
32
abitur_list_client/controllers/abitur.controllers.js
Normal file
@ -0,0 +1,32 @@
|
||||
const db = require('../db')
|
||||
|
||||
const AbiturControllerInterface = require('../controllers/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])
|
||||
res.json(newAbitur.rows[0])
|
||||
}
|
||||
async getAbiturs(req, res) {
|
||||
const abiturs = await db.query('SELECT * FROM abitur')
|
||||
res.json(abiturs.rows)
|
||||
}
|
||||
async getOneAbitur(req, res) {
|
||||
const id = req.params.id
|
||||
const abiturs = await db.query('SELECT * FROM abitur WHERE id=$1', [id])
|
||||
res.json(abiturs.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])
|
||||
res.json(newAbitur.rows[0])
|
||||
}
|
||||
async deleteAbitur(req, res) {
|
||||
const id = req.params.id
|
||||
const abiturs = await db.query('DELETE FROM abitur WHERE id=$1', [id])
|
||||
res.json(abiturs.rows[0])
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new AbiturController()
|
11
abitur_list_client/db.js
Normal file
11
abitur_list_client/db.js
Normal file
@ -0,0 +1,11 @@
|
||||
const Pool = require('pg').Pool
|
||||
const pool = new Pool({
|
||||
user: 'postgres',
|
||||
password: '123',
|
||||
host: '192.168.56.101',
|
||||
port: 5432,
|
||||
database: 'labwork'
|
||||
})
|
||||
|
||||
module.exports = pool
|
||||
|
12
abitur_list_client/index.js
Normal file
12
abitur_list_client/index.js
Normal file
@ -0,0 +1,12 @@
|
||||
const express = require('express')
|
||||
|
||||
const abiturRouter = require('./routes/abitur.routes')
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use(express.json())
|
||||
app.use('/api', abiturRouter)
|
||||
|
||||
app.listen(PORT, () => console.log('server started on port ' + PORT))
|
743
abitur_list_client/package-lock.json
generated
743
abitur_list_client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,10 +4,13 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build"
|
||||
"build": "vue-cli-service build",
|
||||
"start": "nodemon index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^3.8.3",
|
||||
"express": "^4.18.2",
|
||||
"pg": "^8.10.0",
|
||||
"vue": "^3.2.13",
|
||||
"vue-router": "^4.0.3",
|
||||
"vuex": "^4.0.0"
|
||||
@ -16,7 +19,8 @@
|
||||
"@vue/cli-plugin-babel": "~5.0.0",
|
||||
"@vue/cli-plugin-router": "~5.0.0",
|
||||
"@vue/cli-plugin-vuex": "~5.0.0",
|
||||
"@vue/cli-service": "~5.0.0"
|
||||
"@vue/cli-service": "~5.0.0",
|
||||
"nodemon": "^2.0.22"
|
||||
},
|
||||
"browserslist": [
|
||||
"> 1%",
|
||||
|
@ -4,14 +4,11 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<title>Список абитуриентов</title>
|
||||
</head>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
||||
|
12
abitur_list_client/routes/abitur.routes.js
Normal file
12
abitur_list_client/routes/abitur.routes.js
Normal file
@ -0,0 +1,12 @@
|
||||
const Router = require('express')
|
||||
const router = new Router()
|
||||
|
||||
const abiturController = require('../controllers/abitur.controllers')
|
||||
|
||||
router.post('/abitur', abiturController.createAbitur)
|
||||
router.get('/abitur', abiturController.getAbiturs)
|
||||
router.get('/abitur/:id', abiturController.getOneAbitur)
|
||||
router.put('/abitur', abiturController.updateAbitur)
|
||||
router.delete('/abitur/:id', abiturController.deleteAbitur)
|
||||
|
||||
module.exports = router
|
Loading…
Reference in New Issue
Block a user