правка метода копирования бара
This commit is contained in:
@@ -92,17 +92,24 @@ public class BarService {
|
||||
return BarResponseDto.mapToDto(bar);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public BarResponseDto copyBar(Long id, String name) {
|
||||
BarEntity barEntity = barEntityRepository.findById(id).orElseThrow();
|
||||
Long oldId = barEntity.getId();
|
||||
String oldName = barEntity.getName();
|
||||
barEntity.setName(name);
|
||||
barEntity.setActive(false);
|
||||
barEntity.setId(null);
|
||||
BarEntity newBar = barEntityRepository.save(barEntity);
|
||||
log.info("Бар {} - {} скопирован как {} - {}", oldId, oldName, newBar.getId(), name);
|
||||
|
||||
return BarResponseDto.mapToDto(newBar);
|
||||
BarEntity entity = new BarEntity();
|
||||
entity.setName(name);
|
||||
entity.setActive(false);
|
||||
entity.setIngredients(new ArrayList<>());
|
||||
barEntityRepository.save(entity);
|
||||
List<IngredientEntity> ingredients = barEntity.getIngredients()
|
||||
.stream()
|
||||
.peek(i -> i.getBars().add(entity))
|
||||
.toList();
|
||||
entity.setIngredients(ingredients);
|
||||
ingredientRepository.saveAll(ingredients);
|
||||
log.info("Бар {} - {}, скопирован как {} - {}", barEntity.getId(), barEntity.getName(), entity.getId(), name);
|
||||
|
||||
return BarResponseDto.mapToDto(entity);
|
||||
}
|
||||
|
||||
private List<CocktailEntity> findAllowedCocktails(List<IngredientEntity> ingredients) {
|
||||
|
||||
Reference in New Issue
Block a user