From e4ce43c115838ec40c33c327c04c27488ccaa632 Mon Sep 17 00:00:00 2001 From: Bellmin <71818636+rlajm1203@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:21:04 +0900 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20PresentationInitializer=20Team=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eeos/build.gradle | 2 +- .../util/PresentationInitializer.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/eeos/build.gradle b/eeos/build.gradle index 2ae47c6a..627875f0 100644 --- a/eeos/build.gradle +++ b/eeos/build.gradle @@ -33,7 +33,7 @@ group = 'com.econovation' version = '0.0.1-SNAPSHOT' java { - sourceCompatibility = '11' + sourceCompatibility = '17' } configurations { diff --git a/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java index c26e34cf..8b532f04 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java +++ b/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java @@ -4,6 +4,7 @@ import com.blackcompany.eeos.program.persistence.ProgramRepository; import com.blackcompany.eeos.target.persistence.PresentationEntity; import com.blackcompany.eeos.target.persistence.PresentationRepository; +import com.blackcompany.eeos.team.application.exception.NotFoundTeamException; import com.blackcompany.eeos.team.persistence.TeamEntity; import com.blackcompany.eeos.team.persistence.TeamRepository; import lombok.RequiredArgsConstructor; @@ -37,7 +38,7 @@ public void run(ApplicationArguments args) throws Exception { Set target = programs.stream().filter(programId -> !presentations.contains(programId)).collect(Collectors.toSet()); - Long defaultTeamId = teamRepository.findById(0L).orElseThrow().getId(); + Long defaultTeamId = getTempTeam().getId(); Set entities = target.stream().map(targetId -> PresentationEntity.builder().teamId(defaultTeamId).programId(targetId).build()).collect(Collectors.toSet()); @@ -49,6 +50,19 @@ private List getPrograms(){ return programRepository.findAll(); } + private TeamEntity getTempTeam(){ + try { + return teamRepository.findTeamEntityByName("임시 활동 팀").stream().findFirst().orElseThrow(()->new NotFoundTeamException(0L)); + } catch (NotFoundTeamException e){ + return createTempTeam(); + } + } + + private TeamEntity createTempTeam(){ + TeamEntity newTeam = TeamEntity.builder().name("임시 활동 팀").status(false).build(); + return teamRepository.save(newTeam); + } + private List getPresentations(){ return presentationRepository.findAll(); }