diff --git a/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java b/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java index 6bfab5d00423c8d3d98678183195ed5aa81459c5..7f3c6f15fcbd5ac83dd1404b31d7f536c1335ced 100644 --- a/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java +++ b/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java @@ -13,6 +13,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * Service for manipulation with car's components. @@ -32,6 +33,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService { } @Override + @Transactional public CarResponseDto addComponent(Long componentId, Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); @@ -48,6 +50,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService { } @Override + @Transactional public CarResponseDto removeComponent(Long componentId, Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); @@ -63,6 +66,7 @@ public class CarComponentPairServiceImpl implements CarComponentPairService { } @Override + @Transactional(readOnly = true) public List<CarComponentResponseDto> getAllComponentsOfCar(Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); diff --git a/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java b/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java index 543d9dc41a8f8c0e2c5809ae530ba7bdaaaceb5c..69a346e75892e29da32841ffa09138c9633a32ae 100644 --- a/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java +++ b/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java @@ -13,6 +13,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * Service for Driver Manager. @@ -32,6 +33,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { } @Override + @Transactional public CarResponseDto assignDriverToCar(Long driverId, Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); @@ -46,6 +48,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { } @Override + @Transactional public CarResponseDto unassignDriverFromCar(Long driverId, Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); @@ -61,6 +64,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { } @Override + @Transactional(readOnly = true) public List<DriverDto> getAllDriversOfCar(Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); @@ -77,6 +81,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { } @Override + @Transactional public CarResponseDto setMainDriver(Long carId, Long driverId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); @@ -92,6 +97,7 @@ public class CarDriverPairServiceImpl implements CarDriverPairService { } @Override + @Transactional public CarResponseDto removeMainDriver(Long carId) { var car = carRepository.findById(carId).orElseThrow( () -> new DatabaseException("Car not found")); diff --git a/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java b/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java index 38f8d647f3621f3baa6413ab6d99339b8f83d58a..e9d2921a46c4e18271b8b1a0169006bc145cdd65 100644 --- a/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java +++ b/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java @@ -13,6 +13,7 @@ import cz.muni.pa165.common_library.exception.DatabaseException; import java.util.List; import java.util.Objects; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** @@ -33,6 +34,7 @@ public class CarServiceImpl implements CarService { } @Override + @Transactional public CarResponseDto postCar(CarRequestDto carRequestDto) { var componentIds = carRequestDto.getComponentIds(); @@ -46,6 +48,7 @@ public class CarServiceImpl implements CarService { } @Override + @Transactional(readOnly = true) public CarResponseDto getCarById(Long carId) { return carConverterToDto(carRepository.findById(carId).orElseThrow( () -> new DatabaseException( @@ -55,6 +58,7 @@ public class CarServiceImpl implements CarService { } @Override + @Transactional(readOnly = true) public List<CarResponseDto> getAllCars() { return carRepository .findAll() @@ -64,6 +68,7 @@ public class CarServiceImpl implements CarService { } @Override + @Transactional public String deleteById(Long carId) { carRepository.deleteById(carId); return "Car with id = " + carId + " deleted!"; diff --git a/component/src/main/java/cz/muni/pa165/component/service/ComponentService.java b/component/src/main/java/cz/muni/pa165/component/service/ComponentService.java index bc08b2303e3f9fefeb1e0fe247d5b0052a93b020..58042fa226dda885ed35bf5a77938d8dc014bd0a 100644 --- a/component/src/main/java/cz/muni/pa165/component/service/ComponentService.java +++ b/component/src/main/java/cz/muni/pa165/component/service/ComponentService.java @@ -8,6 +8,7 @@ import cz.muni.pa165.component.data.repository.ComponentRepositoryInterface; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** @@ -34,6 +35,7 @@ public class ComponentService implements ComponentServiceInterface { * @param carComponentId id of the component. * @return found car component. */ + @Transactional(readOnly = true) public CarComponentResponseDto getCarComponentById(Long carComponentId) { return carComponentConverter(componentRepository.findById(carComponentId).orElseThrow( () -> new DatabaseException("Something went wrong when finding car component with id: " @@ -45,6 +47,7 @@ public class ComponentService implements ComponentServiceInterface { * * @return list of stored car components. */ + @Transactional(readOnly = true) public List<CarComponentResponseDto> getAllCarComponents() { return componentRepository.findAll() .stream() @@ -57,6 +60,7 @@ public class ComponentService implements ComponentServiceInterface { * * @param carComponentId of the car component for removal. */ + @Transactional public String deleteById(Long carComponentId) { componentRepository.deleteById(carComponentId); return "Car component with id: " + carComponentId + "was successfully deleted"; diff --git a/driver/src/main/java/cz/muni/pa165/driver/service/DriverServiceImpl.java b/driver/src/main/java/cz/muni/pa165/driver/service/DriverServiceImpl.java index db4a956e00ee8e037026541705fc262ecb78ee2a..3aa0f458c1b74cd297b3bc7aa1a9dfb8a0b728b4 100644 --- a/driver/src/main/java/cz/muni/pa165/driver/service/DriverServiceImpl.java +++ b/driver/src/main/java/cz/muni/pa165/driver/service/DriverServiceImpl.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * Implementation of driver service. @@ -34,6 +35,7 @@ public class DriverServiceImpl implements DriverService { * @param driverAddDto driver dto object * @return dto of added driver */ + @Transactional public DriverResponseDto addDriver(DriverAddDto driverAddDto) { var driver = driverMapper.convertToDriver(driverAddDto); return driverMapper.convertToResponseDto(driverRepository.save(driver)); @@ -46,6 +48,7 @@ public class DriverServiceImpl implements DriverService { * @param driverUpdateDto data to be updated * @return dto of updated driver */ + @Transactional public DriverResponseDto updateDriverById(Long id, DriverUpdateDto driverUpdateDto) { var driver = driverRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Driver with given id not found.")); @@ -59,6 +62,7 @@ public class DriverServiceImpl implements DriverService { * @param driver existing driver * @param driverUpdateDto driver update dto */ + @Transactional private static void updateDriverAttributes(Driver driver, DriverUpdateDto driverUpdateDto) { if (driverUpdateDto.name() != null) { driver.setName(driverUpdateDto.name()); @@ -80,6 +84,7 @@ public class DriverServiceImpl implements DriverService { * @param id driver id * @return dto of removed driver */ + @Transactional public DriverResponseDto removeDriverById(Long id) { var found = driverRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException( @@ -93,6 +98,7 @@ public class DriverServiceImpl implements DriverService { * * @return all stored drivers dto list */ + @Transactional(readOnly = true) public List<DriverInsightDto> getAllDrivers() { System.out.println(); return driverRepository.findAll() @@ -107,6 +113,7 @@ public class DriverServiceImpl implements DriverService { * @param id driver id * @return found driver dto if successful */ + @Transactional(readOnly = true) public DriverInsightDto getDriverById(Long id) { return driverMapper.convertToInsightDto(driverRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException( diff --git a/race/src/main/java/cz/muni/pa165/race/rest/RaceController.java b/race/src/main/java/cz/muni/pa165/race/rest/RaceController.java index 907c1066bfcde52f66c95b7c435817bd4d882bde..d9ef0981a81cd5921c9a4e8afa7e93edf58dbb99 100644 --- a/race/src/main/java/cz/muni/pa165/race/rest/RaceController.java +++ b/race/src/main/java/cz/muni/pa165/race/rest/RaceController.java @@ -88,7 +88,7 @@ public class RaceController { return ResponseEntity.ok(raceService.assignPositionForDriverTwo(raceId, position)); } - @Operation(summary = "Assign position for driver two") + @Operation(summary = "Assign position for driver one") @PatchMapping(path = "/assignPointsDriverOne", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<RaceDto> assignPositionDriverOne(@RequestParam Long raceId, diff --git a/race/src/main/java/cz/muni/pa165/race/service/RaceService.java b/race/src/main/java/cz/muni/pa165/race/service/RaceService.java index 48797427e5a4ea415d066893b00fbc75636b3fbc..ad0ff086584e5b069e37b0b1a937903042b8bc0f 100644 --- a/race/src/main/java/cz/muni/pa165/race/service/RaceService.java +++ b/race/src/main/java/cz/muni/pa165/race/service/RaceService.java @@ -18,6 +18,7 @@ import java.util.Objects; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; /** @@ -44,6 +45,7 @@ public class RaceService implements RaceServiceI { * @param raceDto race to insert. * @return inserted race. */ + @Transactional public RaceDto postRace(RaceDto raceDto) { raceDto.setId(null); return convertRace(raceRepository.save(convertRaceDto(raceDto))); @@ -54,6 +56,7 @@ public class RaceService implements RaceServiceI { * * @param raceId race id */ + @Transactional public String deleteRace(Long raceId) { raceRepository.deleteById(raceId); return "Race with id: " + raceId + "was succesfully deleted"; @@ -62,6 +65,7 @@ public class RaceService implements RaceServiceI { /** * Assigns driver one. */ + @Transactional public RaceDto assignDriverOne(Long driverId, Long raceId, Long carId) { var race = raceRepository.findById(raceId) .orElseThrow(() -> new DatabaseException("Race not found")); @@ -83,6 +87,7 @@ public class RaceService implements RaceServiceI { /** * Assigns driver two. */ + @Transactional public RaceDto assignDriverTwo(Long driverId, Long raceId, Long carId) { var race = raceRepository.findById(raceId) .orElseThrow(() -> new DatabaseException("Race not found")); @@ -108,6 +113,7 @@ public class RaceService implements RaceServiceI { * @param raceId id of race. * @return found race. */ + @Transactional(readOnly = true) public RaceDto findRaceById(Long raceId) { return convertRace(raceRepository.findById(raceId).orElseThrow( () -> new DatabaseException("Something went wrong when" @@ -119,6 +125,7 @@ public class RaceService implements RaceServiceI { * * @return found races. */ + @Transactional(readOnly = true) public List<RaceDto> findRaces() { return raceRepository.findAll().stream().map(this::convertRace).toList(); } @@ -130,6 +137,7 @@ public class RaceService implements RaceServiceI { * @param position position of driver two. * @return updated race. */ + @Transactional public RaceDto assignPositionForDriverTwo(Long raceId, Integer position) { var race = raceRepository.findById(raceId).orElseThrow(() -> new DatabaseException("Race not found")); @@ -144,10 +152,11 @@ public class RaceService implements RaceServiceI { * @param position position of driver one. * @return updated race. */ + @Transactional public RaceDto assignPositionForDriverOne(Long raceId, Integer position) { var race = raceRepository.findById(raceId).orElseThrow(() -> new DatabaseException("Race not found")); - race.getDriver2().setFinalPosition(position); + race.getDriver1().setFinalPosition(position); return convertRace(raceRepository.save(race)); } @@ -157,6 +166,7 @@ public class RaceService implements RaceServiceI { * @param location location of the race. * @return set if ids of most suitable drivers for given location. */ + @Transactional(readOnly = true) public Set<Long> findMostSuitableDriver(Location location) { var races = raceRepository.findRacesByLocation(location); Map<Long, Integer> driverWithPoints = new HashMap<>(); diff --git a/race/src/main/java/cz/muni/pa165/race/service/SeasonService.java b/race/src/main/java/cz/muni/pa165/race/service/SeasonService.java index 78670308be1f9f75ec5a07814ebf7bb58841bf21..1cfe9d6140c24fa11898d66ad9b9250d2cf1fbb6 100644 --- a/race/src/main/java/cz/muni/pa165/race/service/SeasonService.java +++ b/race/src/main/java/cz/muni/pa165/race/service/SeasonService.java @@ -10,6 +10,7 @@ import cz.muni.pa165.race.data.repository.SeasonRepository; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * Season service. @@ -33,6 +34,7 @@ public class SeasonService implements SeasonServiceI { * @param seasonDto season to insert. * @return inserted season. */ + @Transactional public SeasonDto postSeason(SeasonDto seasonDto) { seasonDto.setId(null); return seasonConverter(seasonRepository.save(seasonDtoConverter(seasonDto))); @@ -44,6 +46,7 @@ public class SeasonService implements SeasonServiceI { * @param seasonId season id. * @return found season. */ + @Transactional(readOnly = true) public SeasonDto getSeasonById(Long seasonId) { return seasonConverter(seasonRepository.findById(seasonId).orElseThrow( () -> new DatabaseException("Something went wrong when" @@ -55,6 +58,7 @@ public class SeasonService implements SeasonServiceI { * * @return found seasons. */ + @Transactional(readOnly = true) public List<SeasonDto> getAllSeasons() { return seasonRepository.findAll() .stream() @@ -68,6 +72,7 @@ public class SeasonService implements SeasonServiceI { * @param seasonId season id. * @return found season. */ + @Transactional public String deleteById(Long seasonId) { seasonRepository.deleteById(seasonId); return "Season with id: " + seasonId + "was succesfully deleted"; @@ -80,6 +85,7 @@ public class SeasonService implements SeasonServiceI { * @param seasonId season id. * @return modified race. */ + @Transactional(readOnly = true) public SeasonDto addRace(Long raceId, Long seasonId) { var season = seasonRepository.findById(seasonId) .orElseThrow(() -> new DatabaseException("Season not found"));