diff --git a/src/main/java/com/warhammer/service/impl/ArmyServiceImpl.java b/src/main/java/com/warhammer/service/impl/ArmyServiceImpl.java index 9ad03186..b2ea065c 100644 --- a/src/main/java/com/warhammer/service/impl/ArmyServiceImpl.java +++ b/src/main/java/com/warhammer/service/impl/ArmyServiceImpl.java @@ -1,24 +1,20 @@ package com.warhammer.service.impl; -import com.warhammer.domain.UnitArmy; -import com.warhammer.service.ArmyService; import com.warhammer.domain.Army; +import com.warhammer.domain.UnitArmy; import com.warhammer.repository.ArmyRepository; +import com.warhammer.service.ArmyService; import com.warhammer.service.dto.ArmyDTO; import com.warhammer.service.mapper.ArmyMapper; -import liquibase.pro.packaged.S; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.LinkedList; import java.util.List; import java.util.Optional; -import java.util.stream.Collector; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Service Implementation for managing {@link Army}. @@ -86,6 +82,12 @@ public class ArmyServiceImpl implements ArmyService { @Override public void delete(Long id) { log.debug("Request to delete Army : {}", id); + List units = this.findUnits(id); + if (!units.isEmpty()) { + units.forEach(unit -> + unitArmyService.delete(unit.getId()) + ); + } armyRepository.deleteById(id); } }