add isRent to stock if location is in progress
This commit is contained in:
@@ -4,4 +4,5 @@ import fr.eni.demo.bo.Location;
|
||||
|
||||
public interface LocationService {
|
||||
void add(Location location);
|
||||
void update(Location location);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package fr.eni.demo.bll;
|
||||
|
||||
import fr.eni.demo.bo.Location;
|
||||
import fr.eni.demo.dal.LocationRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class LocationServiceImpl implements LocationService {
|
||||
private LocationRepository locationRepository;
|
||||
private StockService stockService;
|
||||
|
||||
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||
this.locationRepository = locationRepository;
|
||||
@@ -16,5 +16,12 @@ public class LocationServiceImpl implements LocationService {
|
||||
@Override
|
||||
public void add(Location location) {
|
||||
locationRepository.save(location);
|
||||
stockService.isRent(location.getStock(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Location location) {
|
||||
locationRepository.save(location);
|
||||
stockService.isRent(location.getStock(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ public interface StockService {
|
||||
Optional<Stock> findById(Long gameId);
|
||||
List<StockCount> findAllByName(String name);
|
||||
Stock findByRef(String ref);
|
||||
void isRent(Stock stock, boolean value);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class StockServiceImpl implements StockService{
|
||||
|
||||
@Override
|
||||
public List<StockCount> findAllByName(String name){
|
||||
List<Stock> stocks = stockRepository.findByNameIsContainingIgnoreCase(name);
|
||||
List<Stock> stocks = stockRepository.findByNameIsContainingIgnoreCaseAndIsRentFalse(name);
|
||||
List<StockCount> result = stocks.stream()
|
||||
.collect(Collectors.groupingBy(Stock::getName, Collectors.counting()))
|
||||
.entrySet().stream()
|
||||
@@ -49,4 +49,13 @@ public class StockServiceImpl implements StockService{
|
||||
}
|
||||
return stock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isRent(Stock stock, boolean value) {
|
||||
if (stock == null) {
|
||||
throw new EntityNotFoundException("Stock non valide");
|
||||
}
|
||||
stock.setIsRent(value);
|
||||
stockRepository.save(stock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ public class Stock {
|
||||
@Field(name = "GAME_DAILY_PRICE")
|
||||
private Double dailyPrice;
|
||||
|
||||
@Field(name = "GAME_IS_RENT")
|
||||
private Boolean isRent;
|
||||
|
||||
@DBRef
|
||||
@Field(name = "GAME_TYPE")
|
||||
private List<GameType> gameType;
|
||||
|
||||
@@ -8,6 +8,6 @@ import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface StockRepository extends MongoRepository<Stock,Long> {
|
||||
List<Stock> findByNameIsContainingIgnoreCase(String name);
|
||||
List<Stock> findByNameIsContainingIgnoreCaseAndIsRentFalse(String name);
|
||||
Stock findByRefEQ(String ref);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user