add isRent to stock if location is in progress
This commit is contained in:
committed by
mepiphana2023
parent
e19b32e4bf
commit
b4c8f2af6b
@@ -4,4 +4,5 @@ import fr.eni.demo.bo.Location;
|
|||||||
|
|
||||||
public interface LocationService {
|
public interface LocationService {
|
||||||
void add(Location location);
|
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.bo.Location;
|
||||||
import fr.eni.demo.dal.LocationRepository;
|
import fr.eni.demo.dal.LocationRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class LocationServiceImpl implements LocationService {
|
public class LocationServiceImpl implements LocationService {
|
||||||
private LocationRepository locationRepository;
|
private LocationRepository locationRepository;
|
||||||
|
private StockService stockService;
|
||||||
|
|
||||||
public LocationServiceImpl(LocationRepository locationRepository) {
|
public LocationServiceImpl(LocationRepository locationRepository) {
|
||||||
this.locationRepository = locationRepository;
|
this.locationRepository = locationRepository;
|
||||||
@@ -16,5 +16,12 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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