Merge branch 'main' of https://github.com/Parpaillax/Ludotheque
# Conflicts: # src/main/java/fr/eni/demo/bll/LocationService.java # src/main/java/fr/eni/demo/bll/LocationServiceImpl.java
This commit is contained in:
@@ -5,5 +5,6 @@ import fr.eni.demo.bo.Location;
|
||||
public interface LocationService {
|
||||
Location findById(Long id);
|
||||
void add(Location location);
|
||||
void update(Location location);
|
||||
void updateDateEnd(String id, Location location);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Date;
|
||||
public class LocationServiceImpl implements LocationService {
|
||||
|
||||
private final LocationRepository locationRepository;
|
||||
private StockService stockService;
|
||||
|
||||
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||
this.locationRepository = locationRepository;
|
||||
@@ -25,6 +26,13 @@ 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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