Skip to content
Snippets Groups Projects
Commit 332379aa authored by Diana Gulčíková's avatar Diana Gulčíková
Browse files

fixed dependencies

parent aa41248e
No related branches found
No related tags found
2 merge requests!60Docker,!42fixed dependencies
Pipeline #
...@@ -47,18 +47,6 @@ ...@@ -47,18 +47,6 @@
<artifactId>spring-data-jpa</artifactId> <artifactId>spring-data-jpa</artifactId>
<version>3.0.3</version> <version>3.0.3</version>
</dependency> </dependency>
<dependency>
<groupId>fi.muni</groupId>
<artifactId>driver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>fi.muni</groupId>
<artifactId>component</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
......
package cz.muni.pa165.car; package cz.muni.pa165.car;
import cz.muni.pa165.car.data.model.Car; import cz.muni.pa165.car.data.model.Car;
import cz.muni.pa165.common_library.client.ClientConfig;
import cz.muni.pa165.common_library.exception.RestExceptionHandler; import cz.muni.pa165.common_library.exception.RestExceptionHandler;
import cz.muni.pa165.component.data.model.CarComponent;
import cz.muni.pa165.driver.data.model.Driver;
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.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
...@@ -20,7 +17,7 @@ import org.springframework.web.client.RestTemplate; ...@@ -20,7 +17,7 @@ import org.springframework.web.client.RestTemplate;
@SpringBootApplication @SpringBootApplication
@EnableJpaRepositories(basePackages = {"cz.muni.pa165.car.data.repository"}) @EnableJpaRepositories(basePackages = {"cz.muni.pa165.car.data.repository"})
@EnableTransactionManagement @EnableTransactionManagement
@EntityScan(basePackageClasses = {Car.class, Driver.class, CarComponent.class}) @EntityScan(basePackageClasses = {Car.class})
//@Import({RestExceptionHandler.class, ClientConfig.class}) //@Import({RestExceptionHandler.class, ClientConfig.class})
@Import(RestExceptionHandler.class) @Import(RestExceptionHandler.class)
public class App { public class App {
......
package cz.muni.pa165.car.data.repository;
import cz.muni.pa165.car.data.model.Car;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Repository for manipulation with car's components.
*/
@Repository
public interface CarComponentPairRepository extends JpaRepository<Car, Long> {}
package cz.muni.pa165.car.data.repository;
import cz.muni.pa165.car.data.model.Car;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Repository for manipulation with car's drivers.
*/
@Repository
public interface CarDriverPairRepository extends JpaRepository<Car, Long> {}
package cz.muni.pa165.car.mapper; package cz.muni.pa165.car.mapper;
import static cz.muni.pa165.car.restemplate.DbGetter.getComponentFromDb;
import cz.muni.pa165.car.data.model.Car; import cz.muni.pa165.car.data.model.Car;
import cz.muni.pa165.common_library.dtos.CarRequestDto; import cz.muni.pa165.common_library.dtos.CarRequestDto;
import cz.muni.pa165.common_library.dtos.CarResponseDto; import cz.muni.pa165.common_library.dtos.CarResponseDto;
import cz.muni.pa165.common_library.exception.DatabaseException;
import cz.muni.pa165.component.data.model.CarComponent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
......
package cz.muni.pa165.car.restemplate; package cz.muni.pa165.car.restemplate;
import cz.muni.pa165.component.data.model.CarComponent; import cz.muni.pa165.common_library.dtos.CarComponentDto;
import cz.muni.pa165.driver.data.model.Driver; import cz.muni.pa165.common_library.dtos.DriverInsightDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -24,9 +23,9 @@ public class DbGetter { ...@@ -24,9 +23,9 @@ public class DbGetter {
* @param id driver id * @param id driver id
* @return Driver object * @return Driver object
*/ */
public static Driver getDriverFromDb(Long id) { public static DriverInsightDto getDriverFromDb(Long id) {
String url = GET_DRIVER_URL + id; String url = GET_DRIVER_URL + id;
ResponseEntity<Driver> response = client.getForEntity(url, Driver.class); ResponseEntity<DriverInsightDto> response = client.getForEntity(url, DriverInsightDto.class);
return response.getBody(); return response.getBody();
} }
...@@ -36,9 +35,9 @@ public class DbGetter { ...@@ -36,9 +35,9 @@ public class DbGetter {
* @param id component id * @param id component id
* @return Component object * @return Component object
*/ */
public static CarComponent getComponentFromDb(Long id) { public static CarComponentDto getComponentFromDb(Long id) {
String url = GET_COMPONENT_URL + id; String url = GET_COMPONENT_URL + id;
ResponseEntity<CarComponent> response = client.getForEntity(url, CarComponent.class); ResponseEntity<CarComponentDto> response = client.getForEntity(url, CarComponentDto.class);
return response.getBody(); return response.getBody();
} }
......
...@@ -8,7 +8,6 @@ import cz.muni.pa165.car.mapper.CarMapper; ...@@ -8,7 +8,6 @@ import cz.muni.pa165.car.mapper.CarMapper;
import cz.muni.pa165.common_library.dtos.CarComponentDto; import cz.muni.pa165.common_library.dtos.CarComponentDto;
import cz.muni.pa165.common_library.dtos.CarResponseDto; import cz.muni.pa165.common_library.dtos.CarResponseDto;
import cz.muni.pa165.common_library.exception.DatabaseException; import cz.muni.pa165.common_library.exception.DatabaseException;
import cz.muni.pa165.component.data.model.CarComponent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -41,7 +40,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService { ...@@ -41,7 +40,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService {
throw new DatabaseException("Component with id " + componentId + " already in use"); throw new DatabaseException("Component with id " + componentId + " already in use");
} }
var components = car.getComponents(); var components = car.getComponents();
CarComponent carComponent = getComponentFromDb(componentId); CarComponentDto carComponent = getComponentFromDb(componentId);
components.add(carComponent.getId()); components.add(carComponent.getId());
car.setComponents(components); car.setComponents(components);
carRepository.save(car); carRepository.save(car);
...@@ -69,7 +68,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService { ...@@ -69,7 +68,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService {
() -> new DatabaseException("Car not found")); () -> new DatabaseException("Car not found"));
var componentDtos = new ArrayList<CarComponentDto>(); var componentDtos = new ArrayList<CarComponentDto>();
for (Long id : car.getComponents()) { for (Long id : car.getComponents()) {
CarComponent carComponent = getComponentFromDb(id); CarComponentDto carComponent = getComponentFromDb(id);
componentDtos.add( componentDtos.add(
new CarComponentDto( new CarComponentDto(
carComponent.getId(), carComponent.getId(),
......
...@@ -6,8 +6,8 @@ import cz.muni.pa165.car.data.repository.CarRepository; ...@@ -6,8 +6,8 @@ import cz.muni.pa165.car.data.repository.CarRepository;
import cz.muni.pa165.car.mapper.CarMapper; import cz.muni.pa165.car.mapper.CarMapper;
import cz.muni.pa165.common_library.dtos.CarResponseDto; import cz.muni.pa165.common_library.dtos.CarResponseDto;
import cz.muni.pa165.common_library.dtos.DriverDto; import cz.muni.pa165.common_library.dtos.DriverDto;
import cz.muni.pa165.common_library.dtos.DriverInsightDto;
import cz.muni.pa165.common_library.exception.DatabaseException; import cz.muni.pa165.common_library.exception.DatabaseException;
import cz.muni.pa165.driver.data.model.Driver;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -38,7 +38,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { ...@@ -38,7 +38,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService {
var drivers = car.getDrivers(); var drivers = car.getDrivers();
var savedDriver = getDriverFromDb(driverId); var savedDriver = getDriverFromDb(driverId);
drivers.add(savedDriver.getId()); drivers.add(savedDriver.id());
car.setDrivers(drivers); car.setDrivers(drivers);
carRepository.save(car); carRepository.save(car);
...@@ -66,11 +66,11 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { ...@@ -66,11 +66,11 @@ public class CarDriverPairServiceImpl implements CarDriverPairService {
() -> new DatabaseException("Car not found")); () -> new DatabaseException("Car not found"));
var driverDtos = new ArrayList<DriverDto>(); var driverDtos = new ArrayList<DriverDto>();
for (Long id : car.getDrivers()) { for (Long id : car.getDrivers()) {
Driver driver = getDriverFromDb(id); DriverInsightDto driver = getDriverFromDb(id);
driverDtos.add( driverDtos.add(
new DriverDto(driver.getId(), new DriverDto(driver.id(),
driver.getName(), driver.name(),
driver.getSurname()) driver.surname())
); );
} }
return driverDtos; return driverDtos;
...@@ -82,7 +82,11 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { ...@@ -82,7 +82,11 @@ public class CarDriverPairServiceImpl implements CarDriverPairService {
() -> new DatabaseException("Car not found")); () -> new DatabaseException("Car not found"));
var savedDriver = getDriverFromDb(driverId); var savedDriver = getDriverFromDb(driverId);
car.setMainDriverId(savedDriver.getId()); car.setMainDriverId(savedDriver.id());
var drivers = car.getDrivers();
drivers.add(savedDriver.id());
car.setDrivers(drivers);
carRepository.save(car); carRepository.save(car);
return CarMapper.carConverterToDto(car); return CarMapper.carConverterToDto(car);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment