This commit is contained in:
Калышев Ян 2023-05-19 15:21:42 +04:00
parent 4a469eb8ad
commit 1672a95835
18 changed files with 127 additions and 7 deletions

View File

@ -21,6 +21,10 @@ public class CarController {
public List<Car> getCars() {
return CarService.findAllCars();
}
@PostMapping("/carWithId")
public Car createCarWithId(@RequestBody CarDto carDto) {
return CarService.addCarWithId(carDto.getId(), carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());
}
@PostMapping("/car")
public Car createCar(@RequestBody CarDto carDto) {
return CarService.addCar(carDto.getGosNumber(), carDto.getVin(), carDto.getDriverId());

View File

@ -2,6 +2,7 @@ package com.subd.subd.Controllers;
import com.subd.subd.Models.Client;
import com.subd.subd.Services.ClientService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -24,6 +25,10 @@ public class ClientController {
public Client createClient(@RequestBody Client client) {
return ClientService.addClient(client.getName(), client.getPhone(), client.getEmail());
}
@PostMapping("/clientWithId")
public Client createClientWithId(@RequestBody Client client) {
return ClientService.addClientWithId(client.getId(), client.getName(), client.getPhone(), client.getEmail());
}
@PutMapping("/client/{id}")
public Client updateClient(@PathVariable String id, @RequestBody Client client) {
return ClientService.updateClient(id, client.getName(), client.getPhone(), client.getEmail());

View File

@ -24,6 +24,10 @@ public class DriverController {
public Driver createDriver(@RequestBody Driver driver) {
return DriverService.addDriver(driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
}
@PostMapping("/driverWithId")
public Driver createDriverWithId(@RequestBody Driver driver) {
return DriverService.addDriverWithId(driver.getId(), driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());
}
@PutMapping("/driver/{id}")
public Driver updateDriver(@PathVariable String id, @RequestBody Driver driver) {
return DriverService.updateDriver(id, driver.getName(), driver.getBirthday(), driver.getPhone(), driver.getEmail());

View File

@ -37,6 +37,10 @@ public class OrderController {
public Order createOrder(@RequestBody OrderDto orderDto) {
return OrderService.addOrder(orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId());
}
@PostMapping("/orderWithId")
public Order createOrderWithId(@RequestBody OrderDto orderDto) {
return OrderService.addOrderWithId(orderDto.getId(), orderDto.getValue(), orderDto.getStatus(), orderDto.getDate(), orderDto.getClientId(), orderDto.getSourcePickUpPointId(), orderDto.getDestPickUpPointId(), orderDto.getCarId());
}
@PutMapping("/order/{id}")
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());

View File

@ -24,6 +24,10 @@ public class PickUpPointController {
public PickUpPoint createPickUpPoint(@RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.addPickUpPoint(pickUpPoint.getAddress());
}
@PostMapping("/pickUpPointWithId")
public PickUpPoint createPickUpPointWithId(@RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.addPickUpPointWithId(pickUpPoint.getId(), pickUpPoint.getAddress());
}
@PutMapping("/pickUpPoint/{id}")
public PickUpPoint updatePickUpPoint(@PathVariable String id, @RequestBody PickUpPoint pickUpPoint) {
return PickUpPointService.updatePickUpPoint(id, pickUpPoint.getAddress());

View File

@ -1,6 +1,7 @@
package com.subd.subd.Dtos;
public class CarDto {
private String id;
private String gosNumber;
private String vin;
private String driverId;
@ -10,6 +11,15 @@ public class CarDto {
this.vin = vin;
this.driverId = driverId;
}
public CarDto(String id, String gosNumber, String vin, String driverId) {
this.id = id;
this.gosNumber = gosNumber;
this.vin = vin;
this.driverId = driverId;
}
public String getId() {
return this.id;
}
public String getGosNumber() {
return this.gosNumber;
}

View File

@ -5,6 +5,7 @@ import jakarta.annotation.Nullable;
import java.util.Date;
public class OrderDto {
private String id;
private Double value;
private String status;
private Date date;
@ -23,6 +24,19 @@ public class OrderDto {
this.destPickUpPointId = destPickUpPointId;
this.carId = carId;
}
public OrderDto(String id, Double value, String status, Date date, String clientId, String sourcePickUpPointId, @Nullable String destPickUpPointId, String carId) {
this.id = id;
this.value = value;
this.status = status;
this.date = date;
this.clientId = clientId;
this.sourcePickUpPointId = sourcePickUpPointId;
this.destPickUpPointId = destPickUpPointId;
this.carId = carId;
}
public String getId() {
return this.id;
}
public Double getValue() {
return this.value;
}

View File

@ -21,6 +21,12 @@ public class Car {
this.vin = vin;
this.driver = driver;
}
public Car(String id, String gosNumber, String vin, Driver driver) {
this.id = id;
this.gosNumber = gosNumber;
this.vin = vin;
this.driver = driver;
}
public Car(CarDto carDto) {
this.gosNumber = carDto.getGosNumber();
this.vin = carDto.getVin();

View File

@ -25,6 +25,12 @@ public class Client {
this.phone = phone;
this.email = email;
}
public Client(String id, String name, String phone, @Nullable String email) {
this.id = id;
this.name = name;
this.phone = phone;
this.email = email;
}
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }
public String getName() { return this.name; }

View File

@ -22,6 +22,13 @@ public class Driver {
this.phone = phone;
this.email = email;
}
public Driver(String id, String name, Date birthday, String phone, String email) {
this.id = id;
this.name = name;
this.birthday = birthday;
this.phone = phone;
this.email = email;
}
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }
public String getName() { return this.name; }

View File

@ -36,6 +36,16 @@ public class Order {
this.destPickUpPoint = destPickUpPoint;
this.car = car;
}
public Order(String id, Double value, String status, Date date, Client client, PickUpPoint sourcePickUpPoint, @Nullable PickUpPoint destPickUpPoint, Car car) {
this.id = id;
this.value = value;
this.status = status;
this.date = date;
this.client = client;
this.sourcePickUpPoint = sourcePickUpPoint;
this.destPickUpPoint = destPickUpPoint;
this.car = car;
}
public String getId() {
return this.id;
}

View File

@ -15,6 +15,10 @@ public class PickUpPoint {
public PickUpPoint(String address) {
this.address = address;
}
public PickUpPoint(String id, String address) {
this.id = id;
this.address = address;
}
public String getId() {
return this.id;
}

View File

@ -27,6 +27,13 @@ public class CarService {
final Car car = new Car(gosNumber, vin, driver);
return carRepository.save(car);
}
@Transactional
public Car addCarWithId(String id, String gosNumber, String vin, String driverId) {
final Driver driver = driverRepository.findById(driverId)
.orElseThrow(() -> new DriverNotFoundException(driverId));
final Car car = new Car(id, gosNumber, vin, driver);
return carRepository.save(car);
}
@Transactional(readOnly = true)
public Car findCar(String id) {
final Optional<Car> car = carRepository.findById(id);

View File

@ -20,6 +20,11 @@ public class ClientService {
final Client client = new Client(name, phone, email);
return clientRepository.save(client);
}
@Transactional
public Client addClientWithId(String id, String name, String phone, String email) {
final Client client = new Client(id, name, phone, email);
return clientRepository.save(client);
}
@Transactional(readOnly = true)
public Client findClient(String id) {
final Optional<Client> client = clientRepository.findById(id);

View File

@ -21,6 +21,11 @@ public class DriverService {
final Driver driver = new Driver(name, birthday, phone, email);
return driverRepository.save(driver);
}
@Transactional
public Driver addDriverWithId(String id, String name, Date birthday, String phone, String email) {
final Driver driver = new Driver(id, name, birthday, phone, email);
return driverRepository.save(driver);
}
@Transactional(readOnly = true)
public Driver findDriver(String id) {
final Optional<Driver> driver = driverRepository.findById(id);

View File

@ -48,6 +48,24 @@ public class OrderService {
}
return orderRepository.save(order);
}
@Transactional
public Order addOrderWithId(String id, 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)
.orElseThrow(() -> new PickUpPointNotFoundException(sourcePickUpPointId));
final Car car = carRepository.findById(carId)
.orElseThrow(() -> new CarNotFoundException(carId));
final Order order;
if (destPickUpPointId != null) {
final PickUpPoint destPickUpPoint = pickUpPointRepository.findById(destPickUpPointId)
.orElseThrow(() -> new PickUpPointNotFoundException(destPickUpPointId));
order = new Order(id, value, status, date, client, sourcePickUpPoint, destPickUpPoint, car);
} else {
order = new Order(id, value, status, date, client, sourcePickUpPoint, null, car);
}
return orderRepository.save(order);
}
@Transactional(readOnly = true)
public Order findOrder(String id) {
final Optional<Order> order = orderRepository.findById(id);

View File

@ -20,6 +20,11 @@ public class PickUpPointService {
final PickUpPoint pickUpPoint = new PickUpPoint(address);
return pickUpPointRepository.save(pickUpPoint);
}
@Transactional
public PickUpPoint addPickUpPointWithId(String id, String address) {
final PickUpPoint pickUpPoint = new PickUpPoint(id, address);
return pickUpPointRepository.save(pickUpPoint);
}
@Transactional(readOnly = true)
public PickUpPoint findPickUpPoint(String id) {
final Optional<PickUpPoint> pickUpPoint = pickUpPointRepository.findById(id);

View File

@ -1,7 +1,9 @@
spring.jpa.hibernate.ddl-auto=update
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=update
#spring.sql.init.mode=always
#spring.sql.init.platform=postgres
#spring.datasource.url=jdbc:postgresql://192.168.0.177:5432/yan
#spring.datasource.username=yan
#spring.datasource.password=250303zyzf
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.data.mongodb.uri=mongodb://192.168.43.105:27017/yan
spring.data.mongodb.database=yan