Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] PresentationInitializer Team 생성 로직 추가 #163

Merged
merged 10 commits into from
Oct 3, 2024
2 changes: 1 addition & 1 deletion eeos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ group = 'com.econovation'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '11'
sourceCompatibility = '17'
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,7 +38,7 @@ public void run(ApplicationArguments args) throws Exception {

Set<Long> target = programs.stream().filter(programId -> !presentations.contains(programId)).collect(Collectors.toSet());

Long defaultTeamId = teamRepository.findById(0L).orElseThrow().getId();
Long defaultTeamId = getTempTeam().getId();

Set<PresentationEntity> entities = target.stream().map(targetId -> PresentationEntity.builder().teamId(defaultTeamId).programId(targetId).build()).collect(Collectors.toSet());

Expand All @@ -49,6 +50,19 @@ private List<ProgramEntity> 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<PresentationEntity> getPresentations(){
return presentationRepository.findAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class TeamInitializer implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("-----------Team Initializer-----------");
if(isEmptyTable()){
try {
TeamEntity defaultTeam = TeamEntity.builder().id(0L).name("임시 활동 팀").status(false).build();
teamRepository.save(defaultTeam);
log.info("임시 팀이 생성되었습니다.");
} catch (Exception e){
log.error("임시 팀이 생성되지 않았습니다.");
}
else log.info("임시 팀이 생성되지 않았습니다.");
System.out.println("---------------------------------------");

}
Expand Down
Loading