Cascade delete on army

This commit is contained in:
vesem 2021-08-11 07:30:39 -04:00
parent 884446e031
commit 04235ad967

View File

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