44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package com.carService.demo.manager;
|
|
|
|
import com.carService.demo.domain.Car;
|
|
import com.carService.demo.domain.User;
|
|
import com.carService.demo.repository.CarRepository;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class CarManagerImpl implements CarManager {
|
|
private final CarRepository carRepository;
|
|
|
|
@Override
|
|
public Car createCar(Car car) {
|
|
return this.carRepository.save(car);
|
|
}
|
|
|
|
@Override
|
|
public List<Car> getAllCars() {
|
|
var cars = this.carRepository.findAll();
|
|
return cars;
|
|
}
|
|
|
|
@Override
|
|
public Optional<Car> getCarById(Long carId) {
|
|
return this.carRepository.findById(carId);
|
|
}
|
|
public List<Car> getCarsByUser(User user) {
|
|
return this.carRepository.findByUser(user);
|
|
}
|
|
public List<Car> getCarsByUserId(Long userId) {
|
|
return this.carRepository.findByUserId(userId);
|
|
}
|
|
|
|
@Override
|
|
public void deleteCarByID(Long carId) {
|
|
this.carRepository.deleteById(carId);
|
|
}
|
|
}
|