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

Merge branch 'small_fixes_on_car_module' into 'milestone_2'

fixed dependencies

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