init of mongodb
This commit is contained in:
parent
410cacaf6d
commit
3ad6e77a70
@ -19,11 +19,13 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
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'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
runtimeOnly 'org.postgresql:postgresql'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class CarController {
|
||||
this.CarService = CarService;
|
||||
}
|
||||
@GetMapping("/car/{id}")
|
||||
public Car getCar(@PathVariable Long id) {
|
||||
public Car getCar(@PathVariable String id) {
|
||||
return CarService.findCar(id);
|
||||
}
|
||||
@GetMapping("/car")
|
||||
@ -26,11 +26,11 @@ public class CarController {
|
||||
return CarService.addCar(carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@DeleteMapping("/car/{id}")
|
||||
public Car deleteCar(@PathVariable Long id) {
|
||||
public Car deleteCar(@PathVariable String id) {
|
||||
return CarService.deleteCar(id);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class ClientController {
|
||||
this.ClientService = ClientService;
|
||||
}
|
||||
@GetMapping("/client/{id}")
|
||||
public Client getClient(@PathVariable Long id) {
|
||||
public Client getClient(@PathVariable String id) {
|
||||
return ClientService.findClient(id);
|
||||
}
|
||||
@GetMapping("/client")
|
||||
@ -25,11 +25,11 @@ public class ClientController {
|
||||
return ClientService.addClient(client.getName(), client.getPhone(), client.getEmail());
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@DeleteMapping("/client/{id}")
|
||||
public Client deleteClient(@PathVariable Long id) {
|
||||
public Client deleteClient(@PathVariable String id) {
|
||||
return ClientService.deleteClient(id);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class DriverController {
|
||||
this.DriverService = DriverService;
|
||||
}
|
||||
@GetMapping("/driver/{id}")
|
||||
public Driver getDriver(@PathVariable Long id) {
|
||||
public Driver getDriver(@PathVariable String id) {
|
||||
return DriverService.findDriver(id);
|
||||
}
|
||||
@GetMapping("/driver")
|
||||
@ -25,11 +25,11 @@ public class DriverController {
|
||||
return DriverService.addDriver(driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@DeleteMapping("/driver/{id}")
|
||||
public Driver deleteDriver(@PathVariable Long id) {
|
||||
public Driver deleteDriver(@PathVariable String id) {
|
||||
return DriverService.deleteDriver(id);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class OrderController {
|
||||
this.OrderService = OrderService;
|
||||
}
|
||||
@GetMapping("/order/{id}")
|
||||
public Order getOrder(@PathVariable Long id) {
|
||||
public Order getOrder(@PathVariable String id) {
|
||||
return OrderService.findOrder(id);
|
||||
}
|
||||
@GetMapping("/order")
|
||||
@ -23,14 +23,14 @@ public class OrderController {
|
||||
return OrderService.findAllOrders();
|
||||
}
|
||||
@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 = "status", required = false) String status,
|
||||
@RequestParam(value = "date", required = false) Date date,
|
||||
@RequestParam(value = "clientId", required = false) Long clientId,
|
||||
@RequestParam(value = "sourcePickUpPointId", required = false) Long sourcePickUpPointId,
|
||||
@RequestParam(value = "destPickUpPointId", required = false) Long destPickUpPointId,
|
||||
@RequestParam(value = "carId", required = false) Long carId) {
|
||||
@RequestParam(value = "clientId", required = false) String clientId,
|
||||
@RequestParam(value = "sourcePickUpPointId", required = false) String sourcePickUpPointId,
|
||||
@RequestParam(value = "destPickUpPointId", required = false) String destPickUpPointId,
|
||||
@RequestParam(value = "carId", required = false) String carId) {
|
||||
return OrderService.findfilteredOrders(id, value, status, date, clientId, sourcePickUpPointId, destPickUpPointId, carId);
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@DeleteMapping("/order/{id}")
|
||||
public Order deleteOrder(@PathVariable Long id) {
|
||||
public Order deleteOrder(@PathVariable String id) {
|
||||
return OrderService.deleteOrder(id);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class PickUpPointController {
|
||||
this.PickUpPointService = PickUpPointService;
|
||||
}
|
||||
@GetMapping("/pickUpPoint/{id}")
|
||||
public PickUpPoint getPickUpPoint(@PathVariable Long id) {
|
||||
public PickUpPoint getPickUpPoint(@PathVariable String id) {
|
||||
return PickUpPointService.findPickUpPoint(id);
|
||||
}
|
||||
@GetMapping("/pickUpPoint")
|
||||
@ -25,11 +25,11 @@ public class PickUpPointController {
|
||||
return PickUpPointService.addPickUpPoint(pickUpPoint.getAddress());
|
||||
}
|
||||
@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());
|
||||
}
|
||||
@DeleteMapping("/pickUpPoint/{id}")
|
||||
public PickUpPoint deletePickUpPoint(@PathVariable Long id) {
|
||||
public PickUpPoint deletePickUpPoint(@PathVariable String id) {
|
||||
return PickUpPointService.deletePickUpPoint(id);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package com.subd.subd.Dtos;
|
||||
public class CarDto {
|
||||
private String gosNumber;
|
||||
private String vin;
|
||||
private Long driverId;
|
||||
private String driverId;
|
||||
public CarDto() {}
|
||||
public CarDto(String gosNumber, String vin, Long driverId) {
|
||||
public CarDto(String gosNumber, String vin, String driverId) {
|
||||
this.gosNumber = gosNumber;
|
||||
this.vin = vin;
|
||||
this.driverId = driverId;
|
||||
@ -16,7 +16,7 @@ public class CarDto {
|
||||
public String getVin() {
|
||||
return this.vin;
|
||||
}
|
||||
public Long getDriverId() {
|
||||
public String getDriverId() {
|
||||
return this.driverId;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.subd.subd.Dtos;
|
||||
|
||||
import com.subd.subd.Models.PickUpPoint;
|
||||
import jakarta.annotation.Nullable;
|
||||
|
||||
import java.util.Date;
|
||||
@ -9,13 +8,13 @@ public class OrderDto {
|
||||
private Double value;
|
||||
private String status;
|
||||
private Date date;
|
||||
private Long clientId;
|
||||
private Long sourcePickUpPointId;
|
||||
private String clientId;
|
||||
private String sourcePickUpPointId;
|
||||
@Nullable
|
||||
private Long destPickUpPointId;
|
||||
private Long carId;
|
||||
private String destPickUpPointId;
|
||||
private String carId;
|
||||
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.status = status;
|
||||
this.date = date;
|
||||
@ -33,17 +32,17 @@ public class OrderDto {
|
||||
public Date getDate() {
|
||||
return this.date;
|
||||
}
|
||||
public Long getClientId() {
|
||||
public String getClientId() {
|
||||
return this.clientId;
|
||||
}
|
||||
public Long getSourcePickUpPointId() {
|
||||
public String getSourcePickUpPointId() {
|
||||
return this.sourcePickUpPointId;
|
||||
}
|
||||
@Nullable
|
||||
public Long getDestPickUpPointId() {
|
||||
public String getDestPickUpPointId() {
|
||||
return this.destPickUpPointId;
|
||||
}
|
||||
public Long getCarId() {
|
||||
public String getCarId() {
|
||||
return this.carId;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Exceptions;
|
||||
|
||||
public class CarNotFoundException extends RuntimeException{
|
||||
public CarNotFoundException(Long id) {
|
||||
public CarNotFoundException(String id) {
|
||||
super(String.format("Not found car with id: %s", id));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Exceptions;
|
||||
|
||||
public class ClientNotFoundException extends RuntimeException{
|
||||
public ClientNotFoundException(Long id) {
|
||||
public ClientNotFoundException(String id) {
|
||||
super(String.format("Not found client with id: %s", id));
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Exceptions;
|
||||
|
||||
public class DriverNotFoundException extends RuntimeException{
|
||||
public DriverNotFoundException(Long id) {
|
||||
public DriverNotFoundException(String id) {
|
||||
super(String.format("Not found driver with id: %s", id));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Exceptions;
|
||||
|
||||
public class OrderNotFoundException extends RuntimeException{
|
||||
public OrderNotFoundException(Long id) {
|
||||
public OrderNotFoundException(String id) {
|
||||
super(String.format("Not found order with id: %s", id));
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Exceptions;
|
||||
|
||||
public class PickUpPointNotFoundException extends RuntimeException{
|
||||
public PickUpPointNotFoundException(Long id) {
|
||||
public PickUpPointNotFoundException(String id) {
|
||||
super(String.format("Not found pickUpPoint with id: %s", id));
|
||||
}
|
||||
}
|
@ -1,22 +1,21 @@
|
||||
package com.subd.subd.Models;
|
||||
|
||||
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;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Car")
|
||||
@Document("Car")
|
||||
public class Car {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private String id;
|
||||
private String gosNumber;
|
||||
private String vin;
|
||||
@OneToOne()
|
||||
@JoinColumn(name = "Driver_id", referencedColumnName = "id")
|
||||
private Driver driver;
|
||||
Car() {}
|
||||
public Car() {}
|
||||
public Car(String gosNumber, String vin, Driver driver) {
|
||||
this.gosNumber = gosNumber;
|
||||
this.vin = vin;
|
||||
@ -26,10 +25,10 @@ public class Car {
|
||||
this.gosNumber = carDto.getGosNumber();
|
||||
this.vin = carDto.getVin();
|
||||
}
|
||||
public Long getId() {
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getGosNumber() {
|
||||
|
@ -1,32 +1,31 @@
|
||||
package com.subd.subd.Models;
|
||||
|
||||
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.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Client")
|
||||
@Document("Client")
|
||||
public class Client {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private String id;
|
||||
private String name;
|
||||
private String phone;
|
||||
@Nullable
|
||||
private String email;
|
||||
@OneToMany(cascade = {CascadeType.MERGE})
|
||||
private List<Order> orders;
|
||||
Client() {}
|
||||
public Client() {}
|
||||
public 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 getId() { return this.id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
public String getName() { return this.name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getPhone() { return this.phone; }
|
||||
|
@ -1,32 +1,29 @@
|
||||
package com.subd.subd.Models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Driver")
|
||||
@Document("Driver")
|
||||
public class Driver {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private String id;
|
||||
private String name;
|
||||
private Date birthday;
|
||||
private String phone;
|
||||
private String email;
|
||||
Driver() {}
|
||||
public Driver() {}
|
||||
public Driver(String name, Date birthday, String phone, String email) {
|
||||
this.name = name;
|
||||
this.birthday = birthday;
|
||||
this.phone = phone;
|
||||
this.email = email;
|
||||
}
|
||||
public Long getId() { return this.id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
public String getId() { return this.id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
public String getName() { return this.name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public Date getBirthday() { return this.birthday; }
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.subd.subd.Models;
|
||||
|
||||
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.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "\"Order\"")
|
||||
@Document("Order")
|
||||
public class Order {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private String id;
|
||||
private Double value;
|
||||
private String status;
|
||||
private Date date;
|
||||
@ -28,7 +27,7 @@ public class Order {
|
||||
@OneToOne()
|
||||
@JoinColumn(name = "Car_id", referencedColumnName = "id")
|
||||
private Car car;
|
||||
Order() {}
|
||||
public Order() {}
|
||||
public Order(Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) {
|
||||
this.value = value;
|
||||
this.status = status;
|
||||
@ -38,10 +37,10 @@ public class Order {
|
||||
this.destPickUpPoint = destPickUpPoint;
|
||||
this.car = car;
|
||||
}
|
||||
public Long getId() {
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Double getValue() {
|
||||
|
@ -1,28 +1,27 @@
|
||||
package com.subd.subd.Models;
|
||||
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "PickUpPoint")
|
||||
@Document("PickUpPoint")
|
||||
public class PickUpPoint {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
@Column(unique=true)
|
||||
private String id;
|
||||
private String address;
|
||||
PickUpPoint() {}
|
||||
public PickUpPoint() {}
|
||||
public PickUpPoint(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
public Long getId() {
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setAddress(String address) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Repositories;
|
||||
|
||||
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> {
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Repositories;
|
||||
|
||||
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> {
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Repositories;
|
||||
|
||||
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> {
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.subd.subd.Repositories;
|
||||
|
||||
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> {
|
||||
}
|
||||
|
@ -21,14 +21,14 @@ public class CarService {
|
||||
this.driverRepository = driverRepository;
|
||||
}
|
||||
@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)
|
||||
.orElseThrow(() -> new DriverNotFoundException(driverId));
|
||||
final Car car = new Car(gosNumber, vin, driver);
|
||||
return carRepository.save(car);
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public Car findCar(Long id) {
|
||||
public Car findCar(String id) {
|
||||
final Optional<Car> car = carRepository.findById(id);
|
||||
return car.orElseThrow(() -> new CarNotFoundException(id));
|
||||
}
|
||||
@ -37,7 +37,7 @@ public class CarService {
|
||||
return carRepository.findAll();
|
||||
}
|
||||
@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);
|
||||
if (gosNumber != null) {
|
||||
currentCar.setGosNumber(gosNumber);
|
||||
@ -53,13 +53,13 @@ public class CarService {
|
||||
return carRepository.save(currentCar);
|
||||
}
|
||||
@Transactional
|
||||
public Driver getDriver(Long carId) {
|
||||
public Driver getDriver(String carId) {
|
||||
Car currentCar = carRepository.findById(carId)
|
||||
.orElseThrow(() -> new CarNotFoundException(carId));
|
||||
return currentCar.getDriver();
|
||||
}
|
||||
@Transactional
|
||||
public void setDriver(Long carId, Long driverId) {
|
||||
public void setDriver(String carId, String driverId) {
|
||||
Car currentCar = carRepository.findById(carId)
|
||||
.orElseThrow(() -> new CarNotFoundException(carId));
|
||||
Driver driver = driverRepository.findById(driverId)
|
||||
@ -67,7 +67,7 @@ public class CarService {
|
||||
currentCar.setDriver(driver);
|
||||
}
|
||||
@Transactional
|
||||
public Car deleteCar(Long id) {
|
||||
public Car deleteCar(String id) {
|
||||
final Car currentCar = findCar(id);
|
||||
carRepository.delete(currentCar);
|
||||
return currentCar;
|
||||
|
@ -21,7 +21,7 @@ public class ClientService {
|
||||
return clientRepository.save(client);
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public Client findClient(Long id) {
|
||||
public Client findClient(String id) {
|
||||
final Optional<Client> client = clientRepository.findById(id);
|
||||
return client.orElseThrow(() -> new ClientNotFoundException(id));
|
||||
}
|
||||
@ -30,7 +30,7 @@ public class ClientService {
|
||||
return clientRepository.findAll();
|
||||
}
|
||||
@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);
|
||||
if (name != null) {
|
||||
currentClient.setName(name);
|
||||
@ -44,7 +44,7 @@ public class ClientService {
|
||||
return clientRepository.save(currentClient);
|
||||
}
|
||||
@Transactional
|
||||
public Client deleteClient(Long id) {
|
||||
public Client deleteClient(String id) {
|
||||
final Client currentClient = findClient(id);
|
||||
clientRepository.delete(currentClient);
|
||||
return currentClient;
|
||||
|
@ -22,7 +22,7 @@ public class DriverService {
|
||||
return driverRepository.save(driver);
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public Driver findDriver(Long id) {
|
||||
public Driver findDriver(String id) {
|
||||
final Optional<Driver> driver = driverRepository.findById(id);
|
||||
return driver.orElseThrow(() -> new DriverNotFoundException(id));
|
||||
}
|
||||
@ -31,7 +31,7 @@ public class DriverService {
|
||||
return driverRepository.findAll();
|
||||
}
|
||||
@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);
|
||||
if (name != null) {
|
||||
currentDriver.setName(name);
|
||||
@ -48,7 +48,7 @@ public class DriverService {
|
||||
return driverRepository.save(currentDriver);
|
||||
}
|
||||
@Transactional
|
||||
public Driver deleteDriver(Long id) {
|
||||
public Driver deleteDriver(String id) {
|
||||
final Driver currentDriver = findDriver(id);
|
||||
driverRepository.delete(currentDriver);
|
||||
return currentDriver;
|
||||
|
@ -31,7 +31,7 @@ public class OrderService {
|
||||
this.carRepository = carRepository;
|
||||
}
|
||||
@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)
|
||||
.orElseThrow(() -> new ClientNotFoundException(clientId));
|
||||
final PickUpPoint sourcePickUpPoint = pickUpPointRepository.findById(sourcePickUpPointId)
|
||||
@ -49,7 +49,7 @@ public class OrderService {
|
||||
return orderRepository.save(order);
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public Order findOrder(Long id) {
|
||||
public Order findOrder(String id) {
|
||||
final Optional<Order> order = orderRepository.findById(id);
|
||||
return order.orElseThrow(() -> new OrderNotFoundException(id));
|
||||
}
|
||||
@ -58,7 +58,7 @@ public class OrderService {
|
||||
return orderRepository.findAll();
|
||||
}
|
||||
@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> result = new ArrayList<>();
|
||||
for (Order order : allOrders) {
|
||||
@ -95,7 +95,7 @@ public class OrderService {
|
||||
return result;
|
||||
}
|
||||
@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);
|
||||
if (value != null) {
|
||||
currentOrder.setValue(value);
|
||||
@ -129,7 +129,7 @@ public class OrderService {
|
||||
return orderRepository.save(currentOrder);
|
||||
}
|
||||
@Transactional
|
||||
public Order deleteOrder(Long id) {
|
||||
public Order deleteOrder(String id) {
|
||||
final Order currentOrder = findOrder(id);
|
||||
orderRepository.delete(currentOrder);
|
||||
return currentOrder;
|
||||
|
@ -21,7 +21,7 @@ public class PickUpPointService {
|
||||
return pickUpPointRepository.save(pickUpPoint);
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public PickUpPoint findPickUpPoint(Long id) {
|
||||
public PickUpPoint findPickUpPoint(String id) {
|
||||
final Optional<PickUpPoint> pickUpPoint = pickUpPointRepository.findById(id);
|
||||
return pickUpPoint.orElseThrow(() -> new PickUpPointNotFoundException(id));
|
||||
}
|
||||
@ -30,7 +30,7 @@ public class PickUpPointService {
|
||||
return pickUpPointRepository.findAll();
|
||||
}
|
||||
@Transactional
|
||||
public PickUpPoint updatePickUpPoint(Long id, String address) {
|
||||
public PickUpPoint updatePickUpPoint(String id, String address) {
|
||||
final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
|
||||
if (address != null) {
|
||||
currentPickUpPoint.setAddress(address);
|
||||
@ -38,7 +38,7 @@ public class PickUpPointService {
|
||||
return pickUpPointRepository.save(currentPickUpPoint);
|
||||
}
|
||||
@Transactional
|
||||
public PickUpPoint deletePickUpPoint(Long id) {
|
||||
public PickUpPoint deletePickUpPoint(String id) {
|
||||
final PickUpPoint currentPickUpPoint = findPickUpPoint(id);
|
||||
pickUpPointRepository.delete(currentPickUpPoint);
|
||||
return currentPickUpPoint;
|
||||
|
@ -1,10 +1,24 @@
|
||||
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.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableMongoRepositories
|
||||
public class SubdApplication {
|
||||
@Autowired
|
||||
CarRepository carRepository;
|
||||
@Autowired
|
||||
ClientRepository clientRepository;
|
||||
@Autowired
|
||||
DriverRepository driverRepository;
|
||||
@Autowired
|
||||
OrderRepository orderRepository;
|
||||
@Autowired
|
||||
PickUpPointRepository pickUpPointRepository;
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SubdApplication.class, args);
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
spring.jpa.hibernate.ddl-auto=create
|
||||
spring.sql.init.mode=always
|
||||
spring.sql.init.platform=postgres
|
||||
spring.datasource.url=jdbc:postgresql://192.168.31.77:5432/yan
|
||||
spring.datasource.username=yan
|
||||
spring.datasource.password=250303zyzf
|
||||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
|
||||
#spring.jpa.hibernate.ddl-auto=create
|
||||
#spring.sql.init.mode=always
|
||||
#spring.sql.init.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
|
||||
#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
|
Loading…
Reference in New Issue
Block a user