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 {
|
public interface LocationService {
|
||||||
Location findById(Long id);
|
Location findById(Long id);
|
||||||
void add(Location location);
|
void add(Location location);
|
||||||
|
void update(Location location);
|
||||||
void updateDateEnd(String id, Location location);
|
void updateDateEnd(String id, Location location);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.Date;
|
|||||||
public class LocationServiceImpl implements LocationService {
|
public class LocationServiceImpl implements LocationService {
|
||||||
|
|
||||||
private final LocationRepository locationRepository;
|
private final LocationRepository locationRepository;
|
||||||
|
private StockService stockService;
|
||||||
|
|
||||||
public LocationServiceImpl(LocationRepository locationRepository) {
|
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||||
this.locationRepository = locationRepository;
|
this.locationRepository = locationRepository;
|
||||||
@@ -25,6 +26,13 @@ public class LocationServiceImpl implements LocationService {
|
|||||||
@Override
|
@Override
|
||||||
public void add(Location location) {
|
public void add(Location location) {
|
||||||
locationRepository.save(location);
|
locationRepository.save(location);
|
||||||
|
stockService.isRent(location.getStock(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Location location) {
|
||||||
|
locationRepository.save(location);
|
||||||
|
stockService.isRent(location.getStock(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ public interface StockService {
|
|||||||
Optional<Stock> findById(Long gameId);
|
Optional<Stock> findById(Long gameId);
|
||||||
List<StockCount> findAllByName(String name);
|
List<StockCount> findAllByName(String name);
|
||||||
Stock findByRef(String ref);
|
Stock findByRef(String ref);
|
||||||
|
void isRent(Stock stock, boolean value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class StockServiceImpl implements StockService{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StockCount> findAllByName(String name){
|
public List<StockCount> findAllByName(String name){
|
||||||
List<Stock> stocks = stockRepository.findByNameIsContainingIgnoreCase(name);
|
List<Stock> stocks = stockRepository.findByNameIsContainingIgnoreCaseAndIsRentFalse(name);
|
||||||
List<StockCount> result = stocks.stream()
|
List<StockCount> result = stocks.stream()
|
||||||
.collect(Collectors.groupingBy(Stock::getName, Collectors.counting()))
|
.collect(Collectors.groupingBy(Stock::getName, Collectors.counting()))
|
||||||
.entrySet().stream()
|
.entrySet().stream()
|
||||||
@@ -49,4 +49,13 @@ public class StockServiceImpl implements StockService{
|
|||||||
}
|
}
|
||||||
return stock;
|
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")
|
@Field(name = "GAME_DAILY_PRICE")
|
||||||
private Double dailyPrice;
|
private Double dailyPrice;
|
||||||
|
|
||||||
|
@Field(name = "GAME_IS_RENT")
|
||||||
|
private Boolean isRent;
|
||||||
|
|
||||||
@DBRef
|
@DBRef
|
||||||
@Field(name = "GAME_TYPE")
|
@Field(name = "GAME_TYPE")
|
||||||
private List<GameType> gameType;
|
private List<GameType> gameType;
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ import java.util.List;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface StockRepository extends MongoRepository<Stock,Long> {
|
public interface StockRepository extends MongoRepository<Stock,Long> {
|
||||||
List<Stock> findByNameIsContainingIgnoreCase(String name);
|
List<Stock> findByNameIsContainingIgnoreCaseAndIsRentFalse(String name);
|
||||||
Stock findByRefEQ(String ref);
|
Stock findByRefEQ(String ref);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user