back switch to spring boot

This commit is contained in:
root 2023-04-19 21:45:07 +04:00
parent f889ccc84f
commit 425b8ffc97
45 changed files with 1148 additions and 1361 deletions

View File

@ -1,6 +0,0 @@
DB_USER = postgres
DB_PASSWORD = 250303zyzf
DB_HOST = 109.197.199.134
DATABASE = postgres
DB_PORT = 5432
PORT = 3000

37
SUBD-back/.gitignore vendored Normal file
View File

@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/

View File

@ -1,222 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class carController {
async update(req, res, next) {
const {changeColumn} = req.query;
const {changeValue} = req.query;
const {id} = req.query;
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
if (!((id || gosNumber || vin || Driverid) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Car\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (gosNumber){
updateCond.push(gosNumber);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"gosNumber\" = $${updateCond.length} `;
}
if (vin){
updateCond.push(vin);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"vin\" = $${updateCond.length} `;
i++
}
if (Driverid){
updateCond.push(Driverid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"Driverid\" = $${updateCond.length} `;
i++
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
if (!(id || gosNumber || vin || Driverid))
var deleteQuery = "DELETE FROM public.\"Car\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (gosNumber) {
deleteCond.push(gosNumber);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"gosNumber\" = $${deleteCond.length} `;
}
if (vin) {
deleteCond.push(vin);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"vin\" = $${deleteCond.length} `;
}
if (Driverid) {
deleteCond.push(Driverid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Driverid\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
if (!(gosNumber && vin && Driverid)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Car\" (\"gosNumber\", \"vin\", \"Driverid\") Values($1, $2, $3)"
var insertCond = [gosNumber, vin, Driverid]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Car"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {operatorid} = req.query;
const {id} = req.query;
const {gosNumber} = req.query;
const {vin} = req.query;
const {Driverid} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Car\" `;
} else {
selectQuery += "* FROM public.\"Car\" ";
}
if (!(id || gosNumber || vin || Driverid)) {
return next(ApiError.badRequest('need more args'))
}
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (gosNumber) {
selectCond.push(gosNumber);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"gosNumber\" = $${selectCond.length} `;
}
if (vin) {
selectCond.push(vin);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"vin\" = $${selectCond.length} `;
}
if (Driverid) {
selectCond.push(Driverid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Driverid\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new carController()

View File

@ -1,230 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class clientController {
async update(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
const {changeColumn} = req.query;
const {changeValue} = req.query;
if (!((id || name || phone || email) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Client\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (name){
updateCond.push(name);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"name\" = $${updateCond.length} `;
}
if (phone){
updateCond.push(phone);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"phone\" = $${updateCond.length} `;
}
if (email){
updateCond.push(email);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"email\" = $${updateCond.length} `;
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (!(id || name || phone || email)) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Client\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (name) {
deleteCond.push(name);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"name\" = $${deleteCond.length} `;
}
if (phone) {
deleteCond.push(phone);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"phone\" = $${deleteCond.length} `;
}
if (email) {
deleteCond.push(email);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"email\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (!((name && phone) || email)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Client\" (\"name\", \"phone\""
var insertCond = []
if (email) {
insertQuery += ", \"email\") Values($1, $2, $3)"
insertCond = [name, phone, email]
} else {
insertQuery += ") Values($1, $2)"
insertCond = [name, phone]
}
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Client"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {operatorid} = req.query;
const {id} = req.query;
const {name} = req.query;
const {phone} = req.query;
const {email} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Client\" WHERE `;
} else {
selectQuery += "* FROM public.\"Client\" WHERE ";
}
if (!(id || name || phone || email)) {
return next(ApiError.badRequest('need more args'))
}
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (name) {
selectCond.push(name);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"name\" = $${selectCond.length} `;
}
if (phone) {
selectCond.push(phone);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"phone\" = $${selectCond.length} `;
}
if (email) {
selectCond.push(email);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"email\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new clientController()

View File

@ -1,277 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class driverController {
async update(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {age} = req.query;
const {phone} = req.query;
const {email} = req.query;
const {changeColumn} = req.query;
const {changeValue} = req.query;
if (!((id || name || age || phone || email) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Driver\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (name){
updateCond.push(name);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"name\" = $${updateCond.length} `;
}
if (age){
updateCond.push(age);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"age\" = $${updateCond.length} `;
}
if (phone){
updateCond.push(phone);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"phone\" = $${updateCond.length} `;
}
if (email){
updateCond.push(email);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"email\" = $${updateCond.length} `;
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {name} = req.query;
const {age} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (id || name || age || phone || email) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Driver\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (id) {
deleteCond.push(id);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (name) {
deleteCond.push(name);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"name\" = $${deleteCond.length} `;
}
if (age) {
deleteCond.push(age);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"age\" = $${deleteCond.length} `;
}
if (phone) {
deleteCond.push(phone);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"phone\" = $${deleteCond.length} `;
}
if (email) {
deleteCond.push(email);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"email\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {name} = req.query;
const {age} = req.query;
const {phone} = req.query;
const {email} = req.query;
if (!(name && age && phone && email)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Driver\" (\"name\", \"age\", \"phone\", \"email\") Values($1, $2, $3, $4)"
var insertCond = [name, age, phone, email]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Driver"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {id} = req.query;
const {operatorid} = req.query;
const {name} = req.query;
const {age} = req.query;
const {operatorage} = req.query;
const {phone} = req.query;
const {email} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Driver\" `;
} else {
selectQuery += "* FROM public.\"Driver\" ";
}
if (id || name || age || phone || email) {
selectQuery += "WHERE ";
} else {
return next(ApiError.badRequest('need more args'))
}
var i = 0
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (name) {
selectCond.push(name);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"name\" = $${selectCond.length} `;
}
if (age) {
selectCond.push(age);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
if (!operatorage) {
selectQuery += `\"age\" = $${selectCond.length} `;
} else {
switch (operatorage) {
case ">":
selectQuery += `\"age\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"age\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"age\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"age\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (phone) {
selectCond.push(phone);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"phone\" = $${selectCond.length} `;
}
if (email) {
selectCond.push(email);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"email\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new driverController()

View File

@ -1,301 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js");
class orderController {
async update(req, res, next) {
const {id} = req.query;
const {value} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
const {changeColumn} = req.query;
const {changeValue} = req.query;
if (!((id || value || Clientid || sourcePickUpPointid || destPickUpPointid || Carid) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"Order\" SET \"${changeColumn}\" = '${changeValue}' WHERE `;
var updateCond = []
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (value){
updateCond.push(value);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"value\" = $${updateCond.length} `;
}
if (Clientid){
updateCond.push(Clientid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"Clientid\" = $${updateCond.length} `;
}
if (sourcePickUpPointid){
updateCond.push(sourcePickUpPointid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"sourcePickUpPointid\" = $${updateCond.length} `;
}
if (destPickUpPointid){
updateCond.push(destPickUpPointid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"destPickUpPointids\" = $${updateCond.length} `;
}
if (Carid){
updateCond.push(Carid);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"Carid\" = $${updateCond.length} `;
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {value} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
if (id || value || Clientid || sourcePickUpPointid || destPickUpPointid || Carid) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"Order\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (id) {
deleteCond.push(id);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"id\" = $${deleteCond.length} `;
}
if (value) {
deleteCond.push(value);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"value\" = $${deleteCond.length} `;
}
if (Clientid) {
deleteCond.push(Clientid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Clientid\" = $${deleteCond.length} `;
}
if (sourcePickUpPointid) {
deleteCond.push(sourcePickUpPointid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"sourcePickUpPointid\" = $${deleteCond.length} `;
}
if (destPickUpPointid) {
deleteCond.push(destPickUpPointid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"destPickUpPointid\" = $${deleteCond.length} `;
}
if (Carid) {
deleteCond.push(Carid);
if (deleteCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"Carid\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {value} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
if (!(value && Clientid && sourcePickUpPointid && destPickUpPointid && Carid)) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"Order\" (\"value\", \"Clientid\", \"sourcePickUpPointid\", \"destPickUpPointid\", \"Carid\") Values($1, $2, $3, $4, $5)"
var insertCond = [value, Clientid, sourcePickUpPointid, destPickUpPointid, Carid]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."Order"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {id} = req.query;
const {operatorid} = req.query;
const {value} = req.query;
const {operatorvalue} = req.query;
const {Clientid} = req.query;
const {sourcePickUpPointid} = req.query;
const {destPickUpPointid} = req.query;
const {Carid} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"Order\" `;
} else {
selectQuery += "* FROM public.\"Driver\" ";
}
if (id || value || Clientid || sourcePickUpPointid || destPickUpPointid || Carid) {
selectQuery += "WHERE ";
} else {
return next(ApiError.badRequest('need more args'))
}
if (id) {
selectCond.push(id);
if (!operatorid) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (value) {
selectCond.push(value);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
if (!operatorvalue) {
selectQuery += `\"value\" = $${selectCond.length} `;
} else {
switch (operatorvalue) {
case ">":
selectQuery += `\"value\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"value\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"value\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"value\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (Clientid) {
selectCond.push(Clientid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Clientid\" = $${selectCond.length} `;
}
if (sourcePickUpPointid) {
selectCond.push(sourcePickUpPointid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"sourcePickUpPointid\" = $${selectCond.length} `;
}
if (destPickUpPointid) {
selectCond.push(destPickUpPointid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"destPickUpPointid\" = $${selectCond.length} `;
}
if (Carid) {
selectCond.push(Carid);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"Carid\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new orderController()

View File

@ -1,177 +0,0 @@
const ApiError = require("../Error/ApiError")
const DB = require("../db.js")
class pickUpPointController {
async update(req, res, next) {
const {changeColumn} = req.query;
const {changeValue} = req.query;
const {id} = req.query;
const {address} = req.query;
if (!((id || address) && changeColumn && changeValue)) {
return next(ApiError.badRequest('need more args'))
}
var updateQuery = `UPDATE \"PickUpPoint\" SET \"${changeColumn}\" = '${changeValue}' `;
var updateCond = []
if (id || address) {
updateQuery += "WHERE ";
}
if (id) {
updateCond.push(id)
updateQuery += `\"id\" = $${updateCond.length} `;
}
if (address){
updateCond.push(address);
if (updateCond.length > 1) {
updateQuery += "AND ";
}
updateQuery += `\"address\" = $${updateCond.length} `;
}
try {
var result
if (updateCond.length != 0) {
result = await DB.query(updateQuery, updateCond);
} else {
result = await DB.query(updateQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async delete(req, res, next) {
const {id} = req.query;
const {address} = req.query;
if (!(id || address)) {
return next(ApiError.badRequest('need more args'))
}
var deleteQuery = "DELETE FROM public.\"PickUpPoint\" WHERE "
var deleteCond = []
if (id) {
deleteCond.push(id);
deleteQuery += `\"ID\" = $${deleteCond.length} `;
}
if (address) {
deleteCond.push(address);
if (updateCond.length > 1) {
deleteQuery += "AND ";
}
deleteQuery += `\"address\" = $${deleteCond.length} `;
}
deleteQuery += "RETURNING *"
try {
var result
if (deleteCond.length != 0) {
result = await DB.query(deleteQuery, deleteCond);
} else {
result = await DB.query(deleteQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async add(req, res, next) {
const {address} = req.query;
if (!address) {
return next(ApiError.badRequest('need more args'))
}
var insertQuery = "INSERT INTO public.\"PickUpPoint\" (\"address\") Values($1)"
var insertCond = [address]
try {
var result
if (insertCond.length != 0) {
result = await DB.query(insertQuery, insertCond);
} else {
result = await DB.query(insertQuery);
}
} catch (error) {
return next(ApiError.badRequest('error'))
}
res.json(result.rows)
}
async getAll(req, res, next) {
var selectQuery = 'SELECT * FROM public."PickUpPoint"'
try {
var result
result = await DB.query(selectQuery);
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
async get(req, res, next) {
const {column} = req.query;
const {operatorid} = req.query;
const {id} = req.query;
const {address} = req.query;
var selectQuery = "SELECT "
var selectCond = []
if (column) {
selectQuery += `\"${column}\" FROM public.\"PickUpPoint\" `;
} else {
selectQuery += "* FROM public.\"PickUpPoint\" ";
}
if (!(id || address)) {
return next(ApiError.badRequest('need more args'))
}
selectQuery += "WHERE ";
if (id) {
selectCond.push(id);
if (!OpeoperatoridratorID) {
selectQuery += `\"id\" = $${selectCond.length} `;
} else {
switch (operatorid) {
case ">":
selectQuery += `\"id\" > $${selectCond.length} `;
break;
case "<":
selectQuery += `\"id\" < $${selectCond.length} `;
break;
case "=":
selectQuery += `\"id\" = $${selectCond.length} `;
break;
case "!=":
selectQuery += `\"id\" != $${selectCond.length} `;
break;
default:
break;
}
}
}
if (address) {
selectCond.push(address);
if (selectCond.length > 1) {
selectQuery += "AND ";
}
selectQuery += `\"address\" = $${selectCond.length} `;
}
try {
var result
if (selectCond.length != 0) {
result = await DB.query(selectQuery, selectCond);
} else {
result = await DB.query(selectQuery);
}
} catch (error) {
return next(ApiError.badRequest('not found'))
}
if (!result.rowCount) {
return next(ApiError.badRequest('not found'))
}
res.json(result.rows)
}
}
module.exports = new pickUpPointController()

View File

@ -1,20 +0,0 @@
class ApiError extends Error {
constructor (status, message) {
super();
this.status = status
this.message = message
}
static badRequest(message) {
return new ApiError(404 ,message)
}
static internal(message) {
return new ApiError(500 ,message)
}
static forbidden(message) {
return new ApiError(403 ,message)
}
}
module.exports = ApiError

View File

@ -1,8 +0,0 @@
const ApiError = require('../Error/ApiError');
module.exports = function(err, req, res, next) {
if (err instanceof ApiError) {
return res.status(err.status).json({message: err.message})
}
return res.status(500).json({message: "Непредвиденная ошибка"})
}

View File

@ -1,10 +0,0 @@
const Router = require('express')
const router = new Router()
const carController = require('../Controllers/carController')
router.get('/add', carController.add)
router.get('/get', carController.get)
router.get('/delete', carController.delete)
router.get('/update', carController.update)
module.exports = router

View File

@ -1,10 +0,0 @@
const Router = require('express')
const router = new Router()
const clientController = require('../Controllers/clientController')
router.get('/add', clientController.add)
router.get('/get', clientController.get)
router.get('/delete', clientController.delete)
router.get('/update', clientController.update)
module.exports = router

View File

@ -1,10 +0,0 @@
const Router = require('express')
const router = new Router()
const driverController = require('../Controllers/driverController')
router.get('/add', driverController.add)
router.get('/get', driverController.get)
router.get('/delete', driverController.delete)
router.get('/update', driverController.update)
module.exports = router

View File

@ -1,15 +0,0 @@
const Router = require('express')
const router = new Router()
const orderRouter = require('./order')
const clientRouter = require('./client')
const carRouter = require('./car')
const driverRouter = require('./driver')
const pickUpPointRouter = require('./pickUpPoint')
router.use('/Order', orderRouter)
router.use('/Client', clientRouter)
router.use('/Car', carRouter)
router.use('/Driver', driverRouter)
router.use('/PickUpPoint', pickUpPointRouter)
module.exports = router

View File

@ -1,10 +0,0 @@
const Router = require('express')
const router = new Router()
const orderController = require('../Controllers/orderController')
router.get('/add', orderController.add)
router.get('/get', orderController.get)
router.get('/delete', orderController.delete)
router.get('/update', orderController.update)
module.exports = router

View File

@ -1,10 +0,0 @@
const Router = require('express')
const router = new Router()
const pickUpPointController = require('../Controllers/pickUpPointController')
router.get('/add', pickUpPointController.add)
router.get('/get', pickUpPointController.get)
router.get('/delete', pickUpPointController.delete)
router.get('/update', pickUpPointController.update)
module.exports = router

33
SUBD-back/build.gradle Normal file
View File

@ -0,0 +1,33 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.5'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.subd'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}

View File

@ -1,11 +0,0 @@
require("dotenv").config;
const pg = require("pg");
const pool = new pg.Pool({
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
host: process.env.DB_HOST,
database: process.env.DATABASE,
port: process.env.DB_PORT
});
module.exports = pool

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

240
SUBD-back/gradlew vendored Executable file
View File

@ -0,0 +1,240 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

91
SUBD-back/gradlew.bat vendored Normal file
View File

@ -0,0 +1,91 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -1,21 +0,0 @@
require("dotenv").config;
const express = require("express")
const router = require('./Routes/index.js')
const app = express()
const corse = require('cors')
const errorHandler = require('./MiddleWare/ErrorHandlingMiddleware')
app.use(corse())
app.use(express.json())
app.use('/api', router)
app.use(errorHandler)
const start = async () => {
try {
app.listen(process.env.PORT, () => console.log("ok"))
} catch (error) {
console.log(error)
}
}
start()

View File

@ -1,23 +0,0 @@
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev" : "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "2.8.5",
"dotenv": "16.0.3",
"express": "4.18.2",
"pg": "8.10.0",
"pg-hstore": "2.3.4",
"sequelize": "6.30.0"
},
"devDependencies": {
"nodemon": "2.0.22"
}
}

View File

@ -0,0 +1 @@
rootProject.name = 'subd'

View File

@ -0,0 +1,51 @@
package com.subd.subd.Controllers;
import com.subd.subd.Exceptions.IdNotFoundException;
import com.subd.subd.Models.Car;
import com.subd.subd.Repositories.CarRepository;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class CarController {
private final CarRepository repository;
CarController(CarRepository repository) {
this.repository = repository;
}
// Aggregate root
// tag::get-aggregate-root[]
@GetMapping("/car")
List<Car> all() {
return repository.findAll();
}
// end::get-aggregate-root[]
@PostMapping("/car")
Car newCar(@RequestBody Car newCar) {
return repository.save(newCar);
}
// Single item
@GetMapping("/car/{id}")
Car one(@PathVariable Long id) {
return repository.findById(id)
.orElseThrow(() -> new IdNotFoundException(id));
}
@PutMapping("/car/{id}")
Car replaceCar(@RequestBody Car newCar, @PathVariable Long id) {
return repository.findById(id)
.map(car -> {
car.setGosNumber(newCar.getGosNumber());
car.setVin(newCar.getVin());
car.setDriver(newCar.getDriver());
return repository.save(car);
})
.orElseGet(() -> {
newCar.setId(id);
return repository.save(newCar);
});
}
@DeleteMapping("/car/{id}")
void deleteCar(@PathVariable Long id) {
repository.deleteById(id);
}
}

View File

@ -0,0 +1,51 @@
package com.subd.subd.Controllers;
import com.subd.subd.Exceptions.IdNotFoundException;
import com.subd.subd.Models.Client;
import com.subd.subd.Repositories.ClientRepository;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class ClientController {
private final ClientRepository repository;
ClientController(ClientRepository repository) {
this.repository = repository;
}
// Aggregate root
// tag::get-aggregate-root[]
@GetMapping("/client")
List<Client> all() {
return repository.findAll();
}
// end::get-aggregate-root[]
@PostMapping("/client")
Client newClient(@RequestBody Client newClient) {
return repository.save(newClient);
}
// Single item
@GetMapping("/client/{id}")
Client one(@PathVariable Long id) {
return repository.findById(id)
.orElseThrow(() -> new IdNotFoundException(id));
}
@PutMapping("/client/{id}")
Client replaceClient(@RequestBody Client newClient, @PathVariable Long id) {
return repository.findById(id)
.map(client -> {
client.setName(newClient.getName());
client.setPhone(newClient.getPhone());
client.setEmail(newClient.getEmail());
return repository.save(client);
})
.orElseGet(() -> {
newClient.setId(id);
return repository.save(newClient);
});
}
@DeleteMapping("/client/{id}")
void deleteClient(@PathVariable Long id) {
repository.deleteById(id);
}
}

View File

@ -0,0 +1,52 @@
package com.subd.subd.Controllers;
import com.subd.subd.Exceptions.IdNotFoundException;
import com.subd.subd.Models.Driver;
import com.subd.subd.Repositories.DriverRepository;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class DriverController {
private final DriverRepository repository;
DriverController(DriverRepository repository) {
this.repository = repository;
}
// Aggregate root
// tag::get-aggregate-root[]
@GetMapping("/driver")
List<Driver> all() {
return repository.findAll();
}
// end::get-aggregate-root[]
@PostMapping("/driver")
Driver newDriver(@RequestBody Driver newDriver) {
return repository.save(newDriver);
}
// Single item
@GetMapping("/driver/{id}")
Driver one(@PathVariable Long id) {
return repository.findById(id)
.orElseThrow(() -> new IdNotFoundException(id));
}
@PutMapping("/driver/{id}")
Driver replaceDriver(@RequestBody Driver newDriver, @PathVariable Long id) {
return repository.findById(id)
.map(driver -> {
driver.setName(newDriver.getName());
driver.setAge(newDriver.getAge());
driver.setPhone(newDriver.getPhone());
driver.setEmail(newDriver.getEmail());
return repository.save(driver);
})
.orElseGet(() -> {
newDriver.setId(id);
return repository.save(newDriver);
});
}
@DeleteMapping("/driver/{id}")
void deleteClient(@PathVariable Long id) {
repository.deleteById(id);
}
}

View File

@ -0,0 +1,53 @@
package com.subd.subd.Controllers;
import com.subd.subd.Exceptions.IdNotFoundException;
import com.subd.subd.Models.Order;
import com.subd.subd.Repositories.OrderRepository;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class OrderController {
private final OrderRepository repository;
OrderController(OrderRepository repository) {
this.repository = repository;
}
// Aggregate root
// tag::get-aggregate-root[]
@GetMapping("/order")
List<Order> all() {
return repository.findAll();
}
// end::get-aggregate-root[]
@PostMapping("/order")
Order newOrder(@RequestBody Order newOrder) {
return repository.save(newOrder);
}
// Single item
@GetMapping("/order/{id}")
Order one(@PathVariable Long id) {
return repository.findById(id)
.orElseThrow(() -> new IdNotFoundException(id));
}
@PutMapping("/order/{id}")
Order replaceOrder(@RequestBody Order newOrder, @PathVariable Long id) {
return repository.findById(id)
.map(order -> {
order.setValue(newOrder.getValue());
order.setClient(newOrder.getClient());
order.setSourcePickUpPoint(newOrder.getSourcePickUpPoint());
order.setDestPickUpPoint(newOrder.getDestPickUpPoint());
order.setCar(newOrder.getCar());
return repository.save(order);
})
.orElseGet(() -> {
newOrder.setId(id);
return repository.save(newOrder);
});
}
@DeleteMapping("/order/{id}")
void deleteOrder(@PathVariable Long id) {
repository.deleteById(id);
}
}

View File

@ -0,0 +1,35 @@
package com.subd.subd.Controllers;
import com.subd.subd.Models.PickUpPoint;
import com.subd.subd.Services.PickUpPointService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class PickUpPointController {
private final PickUpPointService PickUpPointService;
public PickUpPointController(PickUpPointService PickUpPointService) {
this.PickUpPointService = PickUpPointService;
}
@GetMapping("/{id}")
public PickUpPoint getPickUpPoint(@PathVariable Long id) {
return PickUpPointService.findPickUpPoint(id);
}
@GetMapping
public List<PickUpPoint> getPickUpPoints() {
return PickUpPointService.findAllPickUpPoints();
}
@PostMapping
public PickUpPoint createPickUpPoint(@RequestBody PickUpPoint PickUpPoint) {
return PickUpPointService.addPickUpPoint(PickUpPoint.getAddress());
}
@PutMapping("/{id}")
public PickUpPoint updatePickUpPoint(@PathVariable Long id, @RequestBody PickUpPoint PickUpPoint) {
return PickUpPointService.updatePickUpPoint(id, PickUpPoint.getAddress());
}
@DeleteMapping("/{id}")
public PickUpPoint deletePickUpPoint(@PathVariable Long id) {
return PickUpPointService.deletePickUpPoint(id);
}
}

View File

@ -0,0 +1,17 @@
package com.subd.subd.Exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
@ControllerAdvice
class IdNotFoundAdvice {
@ResponseBody
@ExceptionHandler(IdNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
String IdNotFoundHandler(IdNotFoundException ex) {
return ex.getMessage();
}
}

View File

@ -0,0 +1,7 @@
package com.subd.subd.Exceptions;
public class IdNotFoundException extends RuntimeException {
public IdNotFoundException(Long id) {
super("Could not find: " + id);
}
}

View File

@ -0,0 +1,72 @@
package com.subd.subd.Models;
import jakarta.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "Car")
public class Car {
@Id
@GeneratedValue
private Long id;
private String gosNumber;
private String vin;
@OneToOne()
@JoinColumn(name = "Driver_id", referencedColumnName = "id")
private Driver driver;
Car() {}
Car(String gosNumber, String vin, Driver driver) {
this.gosNumber = gosNumber;
this.vin = vin;
this.driver = driver;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getGosNumber() {
return this.gosNumber;
}
public void setGosNumber(String gosNumber) {
this.gosNumber = gosNumber;
}
public String getVin() {
return this.vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public Driver getDriver() {
return this.driver;
}
public void setDriver(Driver driver) {
this.driver = driver;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Car))
return false;
Car car = (Car) o;
return Objects.equals(this.id, car.id) &&
Objects.equals(this.gosNumber, car.gosNumber) &&
Objects.equals(this.vin, car.vin) &&
Objects.equals(this.driver, car.driver);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.gosNumber, this.vin, this.driver);
}
@Override
public String toString() {
return "Car{" + "id=" + this.id +
", gosNumber='" + this.gosNumber + '\'' +
", vin='" + this.vin + '\'' +
", driver='" + this.driver + '\'' +
'}';
}
}

View File

@ -0,0 +1,77 @@
package com.subd.subd.Models;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "Client")
public class Client {
@Id
@GeneratedValue
private Long id;
private String name;
private String phone;
@Nullable
private String email;
@OneToMany(cascade = {CascadeType.MERGE})
private List<Order> orders;
Client() {}
Client(String name, String phone, @Nullable String email) {
this.name = name;
this.phone = phone;
this.email = email;
}
public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
public String getPhone() { return this.phone; }
public void setPhone(String phone) { this.phone = phone; }
@Nullable
public String getEmail() { return this.email; }
public void setEmail(@Nullable String email) { this.email = email; }
public List<Order> getOrders() {
return orders;
}
public void addOrder(Order order){
if (orders == null){
this.orders = new ArrayList<>();
}
if (!orders.contains(order)) {
this.orders.add(order);
order.setClient(this);
}
}
public void removeOrder(Order order){
if (orders.contains(order))
this.orders.remove(order);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Client))
return false;
Client client = (Client) o;
return Objects.equals(this.id, client.id) &&
Objects.equals(this.name, client.name) &&
Objects.equals(this.phone, client.phone) &&
Objects.equals(this.email, client.email);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.name, this.phone, this.email);
}
@Override
public String toString() {
return "Client{" + "id=" + this.id +
", name='" + this.name + '\'' +
", phone='" + this.phone + '\'' +
", email='" + this.email + '\'' +
'}';
}
}

View File

@ -0,0 +1,63 @@
package com.subd.subd.Models;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.Objects;
@Entity
@Table(name = "Driver")
public class Driver {
@Id
@GeneratedValue
private Long id;
private String name;
private Integer age;
private String phone;
private String email;
Driver() {}
Driver(String name, Integer age, String phone, String email) {
this.name = name;
this.age = age;
this.phone = phone;
this.email = email;
}
public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
public Integer getAge() { return this.age; }
public void setAge(Integer age) { this.age = age; }
public String getPhone() { return this.phone; }
public void setPhone(String phone) { this.phone = phone; }
public String getEmail() { return this.email; }
public void setEmail(String email) { this.email = email; }
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Driver))
return false;
Driver driver = (Driver) o;
return Objects.equals(this.id, driver.id) &&
Objects.equals(this.name, driver.name) &&
Objects.equals(this.age, driver.age) &&
Objects.equals(this.phone, driver.phone) &&
Objects.equals(this.email, driver.email);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.name, this.age, this.phone, this.email);
}
@Override
public String toString() {
return "Client{" + "id=" + this.id +
", name='" + this.name + '\'' +
", age='" + this.age + '\'' +
", phone='" + this.phone + '\'' +
", email='" + this.email + '\'' +
'}';
}
}

View File

@ -0,0 +1,103 @@
package com.subd.subd.Models;
import jakarta.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "\"Order\"")
public class Order {
@Id
@GeneratedValue
private Long id;
private Double value;
@ManyToOne( cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinColumn(name = "Client_id", nullable = true)
private Client client;
@OneToOne()
@JoinColumn(name = "sourcePickUpPoint_id", referencedColumnName = "id")
private PickUpPoint sourcePickUpPoint;
@OneToOne()
@JoinColumn(name = "destPickUpPoint_id", referencedColumnName = "id")
private PickUpPoint destPickUpPoint;
@OneToOne()
@JoinColumn(name = "Car_id", referencedColumnName = "id")
private Car car;
Order() {}
Order(Double value, Client client, PickUpPoint sourcePickUpPoint, PickUpPoint destPickUpPoint, Car car) {
this.value = value;
this.client = client;
this.sourcePickUpPoint = sourcePickUpPoint;
this.destPickUpPoint = destPickUpPoint;
this.car = car;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Double getValue() {
return this.value;
}
public void setValue(Double value) {
this.value = value;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public Client removeClient() {
Client temp = this.client;
this.client = null;
return temp;
}
public PickUpPoint getSourcePickUpPoint() {
return this.sourcePickUpPoint;
}
public void setSourcePickUpPoint(PickUpPoint sourcePickUpPoint) {
this.sourcePickUpPoint = sourcePickUpPoint;
}
public PickUpPoint getDestPickUpPoint() {
return this.destPickUpPoint;
}
public void setDestPickUpPoint(PickUpPoint destPickUpPoint) {
this.destPickUpPoint = destPickUpPoint;
}
public Car getCar() {
return this.car;
}
public void setCar(Car car) {
this.car = car;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Client))
return false;
Order order = (Order) o;
return Objects.equals(this.id, order.id) &&
Objects.equals(this.value, order.value) &&
Objects.equals(this.client, order.client) &&
Objects.equals(this.sourcePickUpPoint, order.sourcePickUpPoint) &&
Objects.equals(this.destPickUpPoint, order.destPickUpPoint) &&
Objects.equals(this.car, order.car);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.value, this.client, this.sourcePickUpPoint, destPickUpPoint, car);
}
@Override
public String toString() {
return "Client{" + "id=" + this.id +
", value='" + this.value + '\'' +
", client='" + this.client + '\'' +
", sourcePickUpPoint='" + this.sourcePickUpPoint + '\'' +
", destPickUpPoint='" + this.destPickUpPoint + '\'' +
", car='" + this.car + '\'' +
'}';
}
}

View File

@ -0,0 +1,48 @@
package com.subd.subd.Models;
import java.util.Objects;
import jakarta.persistence.*;
@Entity
@Table(name = "PickUpPoint")
public class PickUpPoint {
@Id
@GeneratedValue
private Long id;
@Column(unique=true)
private String address;
PickUpPoint() {}
public PickUpPoint(String address) {
this.address = address;
}
public Long getId() {
return this.id;
}
public String getAddress() {
return this.address;
}
public void setId(Long id) {
this.id = id;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof PickUpPoint))
return false;
PickUpPoint pickUpPoint = (PickUpPoint) o;
return Objects.equals(this.id, pickUpPoint.id) && Objects.equals(this.address, pickUpPoint.address);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.address);
}
@Override
public String toString() {
return "PickUpPoint{" + "id=" + this.id + ", address='" + this.address + '\'' + '}';
}
}

View File

@ -0,0 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Car;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CarRepository extends JpaRepository<Car, Long> {
}

View File

@ -0,0 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Client;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ClientRepository extends JpaRepository<Client, Long> {
}

View File

@ -0,0 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Driver;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DriverRepository extends JpaRepository<Driver, Long> {
}

View File

@ -0,0 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.Order;
import org.springframework.data.jpa.repository.JpaRepository;
public interface OrderRepository extends JpaRepository<Order, Long> {
}

View File

@ -0,0 +1,7 @@
package com.subd.subd.Repositories;
import com.subd.subd.Models.PickUpPoint;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PickUpPointRepository extends JpaRepository<PickUpPoint, Long> {
}

View File

@ -0,0 +1,46 @@
package com.subd.subd.Services;
import com.subd.subd.Exceptions.IdNotFoundException;
import com.subd.subd.Models.PickUpPoint;
import com.subd.subd.Repositories.PickUpPointRepository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
public class PickUpPointService {
private final PickUpPointRepository pickUpPointRepository;
public PickUpPointService(PickUpPointRepository pickUpPointRepository) {
this.pickUpPointRepository = pickUpPointRepository;
}
@Transactional
public PickUpPoint addPickUpPoint(String address) {
final PickUpPoint pickUpPoint = new PickUpPoint(address);
return pickUpPointRepository.save(pickUpPoint);
}
@Transactional(readOnly = true)
public PickUpPoint findPickUpPoint(Long id) {
final Optional<PickUpPoint> pickUpPoint = pickUpPointRepository.findById(id);
return pickUpPoint.orElseThrow(() -> new IdNotFoundException(id));
}
@Transactional(readOnly = true)
public List<PickUpPoint> findAllPickUpPoints() {
return pickUpPointRepository.findAll();
}
@Transactional
public PickUpPoint updatePickUpPoint(Long id, String address) {
final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
currentPickUpPoint.setAddress(address);
return pickUpPointRepository.save(currentPickUpPoint);
}
@Transactional
public PickUpPoint deletePickUpPoint(Long id) {
final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
pickUpPointRepository.delete(currentPickUpPoint);
return currentPickUpPoint;
}
@Transactional
public void deleteAllPickUpPoints() {
pickUpPointRepository.deleteAll();
}
}

View File

@ -0,0 +1,11 @@
package com.subd.subd;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SubdApplication {
public static void main(String[] args) {
SpringApplication.run(SubdApplication.class, args);
}
}

View File

@ -0,0 +1,7 @@
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://109.197.199.134:5432/subd
spring.datasource.username=postgres
spring.datasource.password=250303Zyzf-d-grad
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

View File

@ -0,0 +1,13 @@
package com.subd.subd;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SubdApplicationTests {
@Test
void contextLoads() {
}
}