From 04235ad967b7ff11fe3484c1253d38ac3380d2e9 Mon Sep 17 00:00:00 2001 From: vesem Date: Wed, 11 Aug 2021 07:30:39 -0400 Subject: [PATCH] Cascade delete on army --- .../warhammer/service/impl/ArmyServiceImpl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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); } }