Kezdeti commit
This commit is contained in:
BIN
backend/autoszalon.db
Normal file
BIN
backend/autoszalon.db
Normal file
Binary file not shown.
64
backend/index.js
Normal file
64
backend/index.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const { Sequelize, Model, DataTypes } = require('sequelize');
|
||||
const e = require('express');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: './autoszalon.db'
|
||||
});
|
||||
|
||||
//Auto model
|
||||
|
||||
class Auto extends Model { }
|
||||
Auto.init({
|
||||
marka: { type: DataTypes.STRING, allowNull: false },
|
||||
tipus: { type: DataTypes.STRING, allowNull: false },
|
||||
evjarat: { type: DataTypes.INTEGER, allowNull: false },
|
||||
szin: { type: DataTypes.STRING, allowNull: true },
|
||||
ar: { type: DataTypes.INTEGER, allowNull: false },
|
||||
uzemanyag: { type: DataTypes.STRING, allowNull: true }
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'auto'
|
||||
});
|
||||
|
||||
sequelize.sync().then(() => {
|
||||
console.log('Adatbázis kapcsolódás sikeres');
|
||||
}).catch((err) => {
|
||||
console.log('Adatbázis kapcsolódás sikertelen');
|
||||
});
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Autoszalon backend')
|
||||
})
|
||||
|
||||
app.get('/api/autok', async (req, res) => {
|
||||
const autos = await Auto.findAll();
|
||||
res.json(autos);
|
||||
});
|
||||
|
||||
app.post('/api/autok', async (req, res) => {
|
||||
const auto = await Auto.create(req.body);
|
||||
res.json(auto);
|
||||
});
|
||||
|
||||
app.delete('/api/autok/:id', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
const auto = await Auto.findByPk(id);
|
||||
if (auto) {
|
||||
await auto.destroy();
|
||||
res.json({ message: 'Autó törölve!' + id + 'id' });
|
||||
} else {
|
||||
res.status(404).json({ message: 'Autó nincs az adatbázisban' + id + 'id' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Autoszalon app listening on port ${port}`)
|
||||
})
|
||||
2436
backend/package-lock.json
generated
Normal file
2436
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
backend/package.json
Normal file
19
backend/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "autoszalonbackend",
|
||||
"version": "1.0.0",
|
||||
"description": "backend api az autoszalon frontendhez",
|
||||
"license": "ISC",
|
||||
"author": "pp",
|
||||
"type": "commonjs",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.6",
|
||||
"express": "^5.2.1",
|
||||
"sequelize": "^6.37.7",
|
||||
"sqlite3": "^5.1.7"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user