init of mongodb

This commit is contained in:
Калышев Ян 2023-05-13 23:56:36 +04:00
parent ee551ec545
commit bdc8ec8871
31 changed files with 136 additions and 134 deletions

View File

@ -19,11 +19,13 @@ repositories {
} }
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mongodb:mongodb-driver-sync:4.9.0'
implementation 'org.mongodb:mongodb-driver-core:4.9.0'
implementation 'org.mongodb:mongodb-jdbc:2.0.1'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:3.0.4'
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools' developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
} }

View File

@ -14,7 +14,7 @@ public class CarController {
this.CarService = CarService; this.CarService = CarService;
} }
@GetMapping("/car/{id}") @GetMapping("/car/{id}")
public Car getCar(@PathVariable Long id) { public Car getCar(@PathVariable String id) {
return CarService.findCar(id); return CarService.findCar(id);
} }
@GetMapping("/car") @GetMapping("/car")
@ -26,11 +26,11 @@ public class CarController {
return CarService.addCar(carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId()); return CarService.addCar(carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
} }
@PutMapping("/car/{id}") @PutMapping("/car/{id}")
public Car updateCar(@PathVariable Long id, @RequestBody CarDto carDto) { public Car updateCar(@PathVariable String id, @RequestBody CarDto carDto) {
return CarService.updateCar(id, carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId()); return CarService.updateCar(id, carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
} }
@DeleteMapping("/car/{id}") @DeleteMapping("/car/{id}")
public Car deleteCar(@PathVariable Long id) { public Car deleteCar(@PathVariable String id) {
return CarService.deleteCar(id); return CarService.deleteCar(id);
} }
} }

View File

@ -13,7 +13,7 @@ public class ClientController {
this.ClientService = ClientService; this.ClientService = ClientService;
} }
@GetMapping("/client/{id}") @GetMapping("/client/{id}")
public Client getClient(@PathVariable Long id) { public Client getClient(@PathVariable String id) {
return ClientService.findClient(id); return ClientService.findClient(id);
} }
@GetMapping("/client") @GetMapping("/client")
@ -25,11 +25,11 @@ public class ClientController {
return ClientService.addClient(client.getName(), client.getPhone(), client.getEmail()); return ClientService.addClient(client.getName(), client.getPhone(), client.getEmail());
} }
@PutMapping("/client/{id}") @PutMapping("/client/{id}")
public Client updateClient(@PathVariable Long id, @RequestBody Client client) { public Client updateClient(@PathVariable String id, @RequestBody Client client) {
return ClientService.updateClient(id, client.getName(), client.getPhone(), client.getEmail()); return ClientService.updateClient(id, client.getName(), client.getPhone(), client.getEmail());
} }
@DeleteMapping("/client/{id}") @DeleteMapping("/client/{id}")
public Client deleteClient(@PathVariable Long id) { public Client deleteClient(@PathVariable String id) {
return ClientService.deleteClient(id); return ClientService.deleteClient(id);
} }
} }

View File

@ -1,12 +1,9 @@
package com.subd.subd.Controllers; package com.subd.subd.Controllers;
import com.subd.subd.Models.Order;
import com.subd.subd.Repositories.OrderRepository; import com.subd.subd.Repositories.OrderRepository;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController @RestController
public class CustomRequest { public class CustomRequest {
private final OrderRepository orderRepository; private final OrderRepository orderRepository;

View File

@ -13,7 +13,7 @@ public class DriverController {
this.DriverService = DriverService; this.DriverService = DriverService;
} }
@GetMapping("/driver/{id}") @GetMapping("/driver/{id}")
public Driver getDriver(@PathVariable Long id) { public Driver getDriver(@PathVariable String id) {
return DriverService.findDriver(id); return DriverService.findDriver(id);
} }
@GetMapping("/driver") @GetMapping("/driver")
@ -25,11 +25,11 @@ public class DriverController {
return DriverService.addDriver(driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail()); return DriverService.addDriver(driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
} }
@PutMapping("/driver/{id}") @PutMapping("/driver/{id}")
public Driver updateDriver(@PathVariable Long id, @RequestBody Driver driver) { public Driver updateDriver(@PathVariable String id, @RequestBody Driver driver) {
return DriverService.updateDriver(id, driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail()); return DriverService.updateDriver(id, driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
} }
@DeleteMapping("/driver/{id}") @DeleteMapping("/driver/{id}")
public Driver deleteDriver(@PathVariable Long id) { public Driver deleteDriver(@PathVariable String id) {
return DriverService.deleteDriver(id); return DriverService.deleteDriver(id);
} }
} }

View File

@ -15,7 +15,7 @@ public class OrderController {
this.OrderService = OrderService; this.OrderService = OrderService;
} }
@GetMapping("/order/{id}") @GetMapping("/order/{id}")
public Order getOrder(@PathVariable Long id) { public Order getOrder(@PathVariable String id) {
return OrderService.findOrder(id); return OrderService.findOrder(id);
} }
@GetMapping("/order") @GetMapping("/order")
@ -23,14 +23,14 @@ public class OrderController {
return OrderService.findAllOrders(); return OrderService.findAllOrders();
} }
@GetMapping("/order/filter") @GetMapping("/order/filter")
public List<Order> getFilteredOrders(@RequestParam(value = "id", required = false) Long id, public List<Order> getFilteredOrders(@RequestParam(value = "id", required = false) String id,
@RequestParam(value = "value", required = false) Double value, @RequestParam(value = "value", required = false) Double value,
@RequestParam(value = "status", required = false) String status, @RequestParam(value = "status", required = false) String status,
@RequestParam(value = "date", required = false) Date date, @RequestParam(value = "date", required = false) Date date,
@RequestParam(value = "clientId", required = false) Long clientId, @RequestParam(value = "clientId", required = false) String clientId,
@RequestParam(value = "sourcePickUpPointId", required = false) Long sourcePickUpPointId, @RequestParam(value = "sourcePickUpPointId", required = false) String sourcePickUpPointId,
@RequestParam(value = "destPickUpPointId", required = false) Long destPickUpPointId, @RequestParam(value = "destPickUpPointId", required = false) String destPickUpPointId,
@RequestParam(value = "carId", required = false) Long carId) { @RequestParam(value = "carId", required = false) String carId) {
return OrderService.findfilteredOrders(id, value, status, date, clientId, sourcePickUpPointId, destPickUpPointId, carId); return OrderService.findfilteredOrders(id, value, status, date, clientId, sourcePickUpPointId, destPickUpPointId, carId);
} }
@PostMapping("/order") @PostMapping("/order")
@ -38,11 +38,11 @@ public class OrderController {
return OrderService.addOrder(orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId()); return OrderService.addOrder(orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId());
} }
@PutMapping("/order/{id}") @PutMapping("/order/{id}")
public Order updateOrder(@PathVariable Long id, @RequestBody OrderDto orderDto) { public Order updateOrder(@PathVariable String id, @RequestBody OrderDto orderDto) {
return OrderService.updateOrder(id, orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId()); return OrderService.updateOrder(id, orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId());
} }
@DeleteMapping("/order/{id}") @DeleteMapping("/order/{id}")
public Order deleteOrder(@PathVariable Long id) { public Order deleteOrder(@PathVariable String id) {
return OrderService.deleteOrder(id); return OrderService.deleteOrder(id);
} }
} }

View File

@ -13,7 +13,7 @@ public class PickUpPointController {
this.PickUpPointService = PickUpPointService; this.PickUpPointService = PickUpPointService;
} }
@GetMapping("/pickUpPoint/{id}") @GetMapping("/pickUpPoint/{id}")
public PickUpPoint getPickUpPoint(@PathVariable Long id) { public PickUpPoint getPickUpPoint(@PathVariable String id) {
return PickUpPointService.findPickUpPoint(id); return PickUpPointService.findPickUpPoint(id);
} }
@GetMapping("/pickUpPoint") @GetMapping("/pickUpPoint")
@ -25,11 +25,11 @@ public class PickUpPointController {
return PickUpPointService.addPickUpPoint(pickUpPoint.getAddress()); return PickUpPointService.addPickUpPoint(pickUpPoint.getAddress());
} }
@PutMapping("/pickUpPoint/{id}") @PutMapping("/pickUpPoint/{id}")
public PickUpPoint updatePickUpPoint(@PathVariable Long id, @RequestBody PickUpPoint pickUpPoint) { public PickUpPoint updatePickUpPoint(@PathVariable String id, @RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.updatePickUpPoint(id, pickUpPoint.getAddress()); return PickUpPointService.updatePickUpPoint(id, pickUpPoint.getAddress());
} }
@DeleteMapping("/pickUpPoint/{id}") @DeleteMapping("/pickUpPoint/{id}")
public PickUpPoint deletePickUpPoint(@PathVariable Long id) { public PickUpPoint deletePickUpPoint(@PathVariable String id) {
return PickUpPointService.deletePickUpPoint(id); return PickUpPointService.deletePickUpPoint(id);
} }
} }

View File

@ -3,9 +3,9 @@ package com.subd.subd.Dtos;
public class CarDto { public class CarDto {
private String gosNumber; private String gosNumber;
private String vin; private String vin;
private Long driverId; private String driverId;
public CarDto() {} public CarDto() {}
public CarDto(String gosNumber, String vin, Long driverId) { public CarDto(String gosNumber, String vin, String driverId) {
this.gosNumber = gosNumber; this.gosNumber = gosNumber;
this.vin = vin; this.vin = vin;
this.driverId = driverId; this.driverId = driverId;
@ -16,7 +16,7 @@ public class CarDto {
public String getVin() { public String getVin() {
return this.vin; return this.vin;
} }
public Long getDriverId() { public String getDriverId() {
return this.driverId; return this.driverId;
} }
} }

View File

@ -1,6 +1,5 @@
package com.subd.subd.Dtos; package com.subd.subd.Dtos;
import com.subd.subd.Models.PickUpPoint;
import jakarta.annotation.Nullable; import jakarta.annotation.Nullable;
import java.util.Date; import java.util.Date;
@ -9,13 +8,13 @@ public class OrderDto {
private Double value; private Double value;
private String status; private String status;
private Date date; private Date date;
private Long clientId; private String clientId;
private Long sourcePickUpPointId; private String sourcePickUpPointId;
@Nullable @Nullable
private Long destPickUpPointId; private String destPickUpPointId;
private Long carId; private String carId;
public OrderDto() {} public OrderDto() {}
public OrderDto(Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, @Nullable Long destPickUpPointId, Long carId) { public OrderDto(Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
this.value = value; this.value = value;
this.status = status; this.status = status;
this.date = date; this.date = date;
@ -33,17 +32,17 @@ public class OrderDto {
public Date getDate() { public Date getDate() {
return this.date; return this.date;
} }
public Long getClientId() { public String getClientId() {
return this.clientId; return this.clientId;
} }
public Long getSourcePickUpPointId() { public String getSourcePickUpPointId() {
return this.sourcePickUpPointId; return this.sourcePickUpPointId;
} }
@Nullable @Nullable
public Long getDestPickUpPointId() { public String getDestPickUpPointId() {
return this.destPickUpPointId; return this.destPickUpPointId;
} }
public Long getCarId() { public String getCarId() {
return this.carId; return this.carId;
} }
} }

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions; package com.subd.subd.Exceptions;
public class CarNotFoundException extends RuntimeException{ public class CarNotFoundException extends RuntimeException{
public CarNotFoundException(Long id) { public CarNotFoundException(String id) {
super(String.format("Not found car with id: %s", id)); super(String.format("Not found car with id: %s", id));
} }
} }

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions; package com.subd.subd.Exceptions;
public class ClientNotFoundException extends RuntimeException{ public class ClientNotFoundException extends RuntimeException{
public ClientNotFoundException(Long id) { public ClientNotFoundException(String id) {
super(String.format("Not found client with id: %s", id)); super(String.format("Not found client with id: %s", id));
} }
} }

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions; package com.subd.subd.Exceptions;
public class DriverNotFoundException extends RuntimeException{ public class DriverNotFoundException extends RuntimeException{
public DriverNotFoundException(Long id) { public DriverNotFoundException(String id) {
super(String.format("Not found driver with id: %s", id)); super(String.format("Not found driver with id: %s", id));
} }
} }

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions; package com.subd.subd.Exceptions;
public class OrderNotFoundException extends RuntimeException{ public class OrderNotFoundException extends RuntimeException{
public OrderNotFoundException(Long id) { public OrderNotFoundException(String id) {
super(String.format("Not found order with id: %s", id)); super(String.format("Not found order with id: %s", id));
} }
} }

View File

@ -1,7 +1,7 @@
package com.subd.subd.Exceptions; package com.subd.subd.Exceptions;
public class PickUpPointNotFoundException extends RuntimeException{ public class PickUpPointNotFoundException extends RuntimeException{
public PickUpPointNotFoundException(Long id) { public PickUpPointNotFoundException(String id) {
super(String.format("Not found pickUpPoint with id: %s", id)); super(String.format("Not found pickUpPoint with id: %s", id));
} }
} }

View File

@ -1,22 +1,21 @@
package com.subd.subd.Models; package com.subd.subd.Models;
import com.subd.subd.Dtos.CarDto; import com.subd.subd.Dtos.CarDto;
import jakarta.persistence.*; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Objects; import java.util.Objects;
@Entity @Document("Car")
@Table(name = "Car")
public class Car { public class Car {
@Id @Id
@GeneratedValue private String id;
private Long id;
private String gosNumber; private String gosNumber;
private String vin; private String vin;
@OneToOne() @OneToOne()
@JoinColumn(name = "Driver_id", referencedColumnName = "id") @JoinColumn(name = "Driver_id", referencedColumnName = "id")
private Driver driver; private Driver driver;
Car() {} public Car() {}
public Car(String gosNumber, String vin, Driver driver) { public Car(String gosNumber, String vin, Driver driver) {
this.gosNumber = gosNumber; this.gosNumber = gosNumber;
this.vin = vin; this.vin = vin;
@ -26,10 +25,10 @@ public class Car {
this.gosNumber = carDto.getGosNumber(); this.gosNumber = carDto.getGosNumber();
this.vin = carDto.getVin(); this.vin = carDto.getVin();
} }
public Long getId() { public String getId() {
return this.id; return this.id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public String getGosNumber() { public String getGosNumber() {

View File

@ -1,32 +1,31 @@
package com.subd.subd.Models; package com.subd.subd.Models;
import jakarta.annotation.Nullable; import jakarta.annotation.Nullable;
import jakarta.persistence.*; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@Entity @Document("Client")
@Table(name = "Client")
public class Client { public class Client {
@Id @Id
@GeneratedValue private String id;
private Long id;
private String name; private String name;
private String phone; private String phone;
@Nullable @Nullable
private String email; private String email;
@OneToMany(cascade = {CascadeType.MERGE}) @OneToMany(cascade = {CascadeType.MERGE})
private List<Order> orders; private List<Order> orders;
Client() {} public Client() {}
public Client(String name, String phone, @Nullable String email) { public Client(String name, String phone, @Nullable String email) {
this.name = name; this.name = name;
this.phone = phone; this.phone = phone;
this.email = email; this.email = email;
} }
public Long getId() { return this.id; } public String getId() { return this.id; }
public void setId(Long id) { this.id = id; } public void setId(String id) { this.id = id; }
public String getName() { return this.name; } public String getName() { return this.name; }
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public String getPhone() { return this.phone; } public String getPhone() { return this.phone; }

View File

@ -1,32 +1,29 @@
package com.subd.subd.Models; package com.subd.subd.Models;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import org.springframework.data.annotation.Id;
import jakarta.persistence.Id; import org.springframework.data.mongodb.core.mapping.Document;
import jakarta.persistence.Table;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@Entity @Document("Driver")
@Table(name = "Driver")
public class Driver { public class Driver {
@Id @Id
@GeneratedValue private String id;
private Long id;
private String name; private String name;
private Date birthday; private Date birthday;
private String phone; private String phone;
private String email; private String email;
Driver() {} public Driver() {}
public Driver(String name, Date birthday, String phone, String email) { public Driver(String name, Date birthday, String phone, String email) {
this.name = name; this.name = name;
this.birthday = birthday; this.birthday = birthday;
this.phone = phone; this.phone = phone;
this.email = email; this.email = email;
} }
public Long getId() { return this.id; } public String getId() { return this.id; }
public void setId(Long id) { this.id = id; } public void setId(String id) { this.id = id; }
public String getName() { return this.name; } public String getName() { return this.name; }
public void setName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
public Date getBirthday() { return this.birthday; } public Date getBirthday() { return this.birthday; }

View File

@ -1,17 +1,16 @@
package com.subd.subd.Models; package com.subd.subd.Models;
import jakarta.annotation.Nullable; import jakarta.annotation.Nullable;
import jakarta.persistence.*; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@Entity @Document("Order")
@Table(name = "\"Order\"")
public class Order { public class Order {
@Id @Id
@GeneratedValue private String id;
private Long id;
private Double value; private Double value;
private String status; private String status;
private Date date; private Date date;
@ -28,7 +27,7 @@ public class Order {
@OneToOne() @OneToOne()
@JoinColumn(name = "Car_id", referencedColumnName = "id") @JoinColumn(name = "Car_id", referencedColumnName = "id")
private Car car; private Car car;
Order() {} public Order() {}
public Order(Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) { public Order(Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) {
this.value = value; this.value = value;
this.status = status; this.status = status;
@ -38,10 +37,10 @@ public class Order {
this.destPickUpPoint = destPickUpPoint; this.destPickUpPoint = destPickUpPoint;
this.car = car; this.car = car;
} }
public Long getId() { public String getId() {
return this.id; return this.id;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public Double getValue() { public Double getValue() {

View File

@ -1,28 +1,27 @@
package com.subd.subd.Models; package com.subd.subd.Models;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Objects; import java.util.Objects;
import jakarta.persistence.*; @Document("PickUpPoint")
@Entity
@Table(name = "PickUpPoint")
public class PickUpPoint { public class PickUpPoint {
@Id @Id
@GeneratedValue private String id;
private Long id;
@Column(unique=true)
private String address; private String address;
PickUpPoint() {} public PickUpPoint() {}
public PickUpPoint(String address) { public PickUpPoint(String address) {
this.address = address; this.address = address;
} }
public Long getId() { public String getId() {
return this.id; return this.id;
} }
public String getAddress() { public String getAddress() {
return this.address; return this.address;
} }
public void setId(Long id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public void setAddress(String address) { public void setAddress(String address) {

View File

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

View File

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

View File

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

View File

@ -1,19 +1,12 @@
package com.subd.subd.Repositories; package com.subd.subd.Repositories;
import com.subd.subd.Models.Order; import com.subd.subd.Models.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
public interface OrderRepository extends JpaRepository<Order, Long> { public interface OrderRepository extends MongoRepository<Order, String> {
@Query(value = "SELECT \"order\".ID, \"order\".DATE, \"order\".STATUS, \"car\".GOS_NUMBER, \"driver\".NAME as driver_name, \"client\".NAME as client_name\n" + @Query("{value: 25}")
"FROM \"order\"\n" + List<Order> customAction();
"JOIN CAR ON CAR.ID = \"order\".CAR_ID\n" +
"JOIN DRIVER ON CAR.DRIVER_ID = DRIVER.ID\n" +
"JOIN CLIENT ON CLIENT.ID = \"order\".CLIENT_ID\n" +
"WHERE \"order\".DATE > '2000-01-01' AND \"order\".VALUE > 10000 AND \"order\".STATUS like 'delivered'\n" +
"ORDER BY date;", nativeQuery = true)
// @Query(value = "SELECT * FROM \"order\"", nativeQuery = true)
List<Object> customAction();
} }

View File

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

View File

@ -21,14 +21,14 @@ public class CarService {
this.driverRepository = driverRepository; this.driverRepository = driverRepository;
} }
@Transactional @Transactional
public Car addCar(String gosNumber, String vin, Long driverId) { public Car addCar(String gosNumber, String vin, String driverId) {
final Driver driver = driverRepository.findById(driverId) final Driver driver = driverRepository.findById(driverId)
.orElseThrow(() -> new DriverNotFoundException(driverId)); .orElseThrow(() -> new DriverNotFoundException(driverId));
final Car car = new Car(gosNumber, vin, driver); final Car car = new Car(gosNumber, vin, driver);
return carRepository.save(car); return carRepository.save(car);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Car findCar(Long id) { public Car findCar(String id) {
final Optional<Car> car = carRepository.findById(id); final Optional<Car> car = carRepository.findById(id);
return car.orElseThrow(() -> new CarNotFoundException(id)); return car.orElseThrow(() -> new CarNotFoundException(id));
} }
@ -37,7 +37,7 @@ public class CarService {
return carRepository.findAll(); return carRepository.findAll();
} }
@Transactional @Transactional
public Car updateCar(Long id, String gosNumber, String vin, Long driverId) { public Car updateCar(String id, String gosNumber, String vin, String driverId) {
final Car currentCar = findCar(id); final Car currentCar = findCar(id);
if (gosNumber != null) { if (gosNumber != null) {
currentCar.setGosNumber(gosNumber); currentCar.setGosNumber(gosNumber);
@ -53,13 +53,13 @@ public class CarService {
return carRepository.save(currentCar); return carRepository.save(currentCar);
} }
@Transactional @Transactional
public Driver getDriver(Long carId) { public Driver getDriver(String carId) {
Car currentCar = carRepository.findById(carId) Car currentCar = carRepository.findById(carId)
.orElseThrow(() -> new CarNotFoundException(carId)); .orElseThrow(() -> new CarNotFoundException(carId));
return currentCar.getDriver(); return currentCar.getDriver();
} }
@Transactional @Transactional
public void setDriver(Long carId, Long driverId) { public void setDriver(String carId, String driverId) {
Car currentCar = carRepository.findById(carId) Car currentCar = carRepository.findById(carId)
.orElseThrow(() -> new CarNotFoundException(carId)); .orElseThrow(() -> new CarNotFoundException(carId));
Driver driver = driverRepository.findById(driverId) Driver driver = driverRepository.findById(driverId)
@ -67,7 +67,7 @@ public class CarService {
currentCar.setDriver(driver); currentCar.setDriver(driver);
} }
@Transactional @Transactional
public Car deleteCar(Long id) { public Car deleteCar(String id) {
final Car currentCar = findCar(id); final Car currentCar = findCar(id);
carRepository.delete(currentCar); carRepository.delete(currentCar);
return currentCar; return currentCar;

View File

@ -21,7 +21,7 @@ public class ClientService {
return clientRepository.save(client); return clientRepository.save(client);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Client findClient(Long id) { public Client findClient(String id) {
final Optional<Client> client = clientRepository.findById(id); final Optional<Client> client = clientRepository.findById(id);
return client.orElseThrow(() -> new ClientNotFoundException(id)); return client.orElseThrow(() -> new ClientNotFoundException(id));
} }
@ -30,7 +30,7 @@ public class ClientService {
return clientRepository.findAll(); return clientRepository.findAll();
} }
@Transactional @Transactional
public Client updateClient(Long id, String name, String phone, String email) { public Client updateClient(String id, String name, String phone, String email) {
final Client currentClient = findClient(id); final Client currentClient = findClient(id);
if (name != null) { if (name != null) {
currentClient.setName(name); currentClient.setName(name);
@ -44,7 +44,7 @@ public class ClientService {
return clientRepository.save(currentClient); return clientRepository.save(currentClient);
} }
@Transactional @Transactional
public Client deleteClient(Long id) { public Client deleteClient(String id) {
final Client currentClient = findClient(id); final Client currentClient = findClient(id);
clientRepository.delete(currentClient); clientRepository.delete(currentClient);
return currentClient; return currentClient;

View File

@ -22,7 +22,7 @@ public class DriverService {
return driverRepository.save(driver); return driverRepository.save(driver);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Driver findDriver(Long id) { public Driver findDriver(String id) {
final Optional<Driver> driver = driverRepository.findById(id); final Optional<Driver> driver = driverRepository.findById(id);
return driver.orElseThrow(() -> new DriverNotFoundException(id)); return driver.orElseThrow(() -> new DriverNotFoundException(id));
} }
@ -31,7 +31,7 @@ public class DriverService {
return driverRepository.findAll(); return driverRepository.findAll();
} }
@Transactional @Transactional
public Driver updateDriver(Long id, String name, Date birthday, String phone, String email) { public Driver updateDriver(String id, String name, Date birthday, String phone, String email) {
final Driver currentDriver = findDriver(id); final Driver currentDriver = findDriver(id);
if (name != null) { if (name != null) {
currentDriver.setName(name); currentDriver.setName(name);
@ -48,7 +48,7 @@ public class DriverService {
return driverRepository.save(currentDriver); return driverRepository.save(currentDriver);
} }
@Transactional @Transactional
public Driver deleteDriver(Long id) { public Driver deleteDriver(String id) {
final Driver currentDriver = findDriver(id); final Driver currentDriver = findDriver(id);
driverRepository.delete(currentDriver); driverRepository.delete(currentDriver);
return currentDriver; return currentDriver;

View File

@ -31,7 +31,7 @@ public class OrderService {
this.carRepository = carRepository; this.carRepository = carRepository;
} }
@Transactional @Transactional
public Order addOrder(Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, @Nullable Long destPickUpPointId, Long carId) { public Order addOrder(Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
final Client client = clientRepository.findById(clientId) final Client client = clientRepository.findById(clientId)
.orElseThrow(() -> new ClientNotFoundException(clientId)); .orElseThrow(() -> new ClientNotFoundException(clientId));
final PickUpPoint sourcePickUpPoint = pickUpPointRepository.findById(sourcePickUpPointId) final PickUpPoint sourcePickUpPoint = pickUpPointRepository.findById(sourcePickUpPointId)
@ -49,7 +49,7 @@ public class OrderService {
return orderRepository.save(order); return orderRepository.save(order);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Order findOrder(Long id) { public Order findOrder(String id) {
final Optional<Order> order = orderRepository.findById(id); final Optional<Order> order = orderRepository.findById(id);
return order.orElseThrow(() -> new OrderNotFoundException(id)); return order.orElseThrow(() -> new OrderNotFoundException(id));
} }
@ -58,7 +58,7 @@ public class OrderService {
return orderRepository.findAll(); return orderRepository.findAll();
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<Order> findfilteredOrders(Long id, Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { public List<Order> findfilteredOrders(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, String destPickUpPointId, String carId) {
List<Order> allOrders = orderRepository.findAll(); List<Order> allOrders = orderRepository.findAll();
List<Order> result = new ArrayList<>(); List<Order> result = new ArrayList<>();
for (Order order : allOrders) { for (Order order : allOrders) {
@ -95,7 +95,7 @@ public class OrderService {
return result; return result;
} }
@Transactional @Transactional
public Order updateOrder(Long id, Double value, String status, Date date, Long clientId, Long sourcePickUpPointId, Long destPickUpPointId, Long carId) { public Order updateOrder(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, String destPickUpPointId, String carId) {
final Order currentOrder = findOrder(id); final Order currentOrder = findOrder(id);
if (value != null) { if (value != null) {
currentOrder.setValue(value); currentOrder.setValue(value);
@ -129,7 +129,7 @@ public class OrderService {
return orderRepository.save(currentOrder); return orderRepository.save(currentOrder);
} }
@Transactional @Transactional
public Order deleteOrder(Long id) { public Order deleteOrder(String id) {
final Order currentOrder = findOrder(id); final Order currentOrder = findOrder(id);
orderRepository.delete(currentOrder); orderRepository.delete(currentOrder);
return currentOrder; return currentOrder;

View File

@ -21,7 +21,7 @@ public class PickUpPointService {
return pickUpPointRepository.save(pickUpPoint); return pickUpPointRepository.save(pickUpPoint);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public PickUpPoint findPickUpPoint(Long id) { public PickUpPoint findPickUpPoint(String id) {
final Optional<PickUpPoint> pickUpPoint = pickUpPointRepository.findById(id); final Optional<PickUpPoint> pickUpPoint = pickUpPointRepository.findById(id);
return pickUpPoint.orElseThrow(() -> new PickUpPointNotFoundException(id)); return pickUpPoint.orElseThrow(() -> new PickUpPointNotFoundException(id));
} }
@ -30,7 +30,7 @@ public class PickUpPointService {
return pickUpPointRepository.findAll(); return pickUpPointRepository.findAll();
} }
@Transactional @Transactional
public PickUpPoint updatePickUpPoint(Long id, String address) { public PickUpPoint updatePickUpPoint(String id, String address) {
final PickUpPoint currentPickUpPoint = findPickUpPoint(id); final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
if (address != null) { if (address != null) {
currentPickUpPoint.setAddress(address); currentPickUpPoint.setAddress(address);
@ -38,7 +38,7 @@ public class PickUpPointService {
return pickUpPointRepository.save(currentPickUpPoint); return pickUpPointRepository.save(currentPickUpPoint);
} }
@Transactional @Transactional
public PickUpPoint deletePickUpPoint(Long id) { public PickUpPoint deletePickUpPoint(String id) {
final PickUpPoint currentPickUpPoint = findPickUpPoint(id); final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
pickUpPointRepository.delete(currentPickUpPoint); pickUpPointRepository.delete(currentPickUpPoint);
return currentPickUpPoint; return currentPickUpPoint;

View File

@ -1,10 +1,24 @@
package com.subd.subd; package com.subd.subd;
import com.subd.subd.Repositories.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
@SpringBootApplication @SpringBootApplication
@EnableMongoRepositories
public class SubdApplication { public class SubdApplication {
@Autowired
CarRepository carRepository;
@Autowired
ClientRepository clientRepository;
@Autowired
DriverRepository driverRepository;
@Autowired
OrderRepository orderRepository;
@Autowired
PickUpPointRepository pickUpPointRepository;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(SubdApplication.class, args); SpringApplication.run(SubdApplication.class, args);
} }

View File

@ -1,7 +1,11 @@
spring.jpa.hibernate.ddl-auto=create #spring.jpa.hibernate.ddl-auto=create
spring.sql.init.mode=always #spring.sql.init.mode=always
spring.sql.init.platform=postgres #spring.sql.init.platform=postgres
spring.datasource.url=jdbc:postgresql://109.197.199.134:5432/subd #spring.datasource.url=jdbc:postgresql://109.197.199.134:5432/subd
spring.datasource.username=postgres #spring.datasource.username=postgres
spring.datasource.password=250303Zyzf-d-grad #spring.datasource.password=250303Zyzf-d-grad
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true #spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
#spring.datasource.url=jdbc:mongodb://192.168.0.118:27017/yan
#spring.datasource.driver-class-name=com.mongodb.jdbc.MongoDriver
spring.data.mongodb.uri=mongodb://192.168.0.118:27017/yan
spring.data.mongodb.database=yan