diff --git a/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java index fbdef24b..d3ea1520 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java +++ b/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java @@ -3,51 +3,54 @@ import com.blackcompany.eeos.program.application.model.ProgramAttendMode; import com.blackcompany.eeos.program.persistence.ProgramEntity; import com.blackcompany.eeos.program.persistence.ProgramRepository; +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; -import java.util.List; -import java.util.stream.Collectors; - @Component @RequiredArgsConstructor @Slf4j public class ProgramInitializer implements ApplicationRunner { - private final ProgramRepository programRepository; - private final String defaultUrl = "https://github.com/JNU-econovation/weekly_presentation/tree/2024-1/2024-1/A_team/1st"; - - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("------------Program Initializer----------"); - List programs = getPrograms(); - - if(programs.isEmpty()) return; - - programs = programs.stream() - .map(program -> { - if(program.getGithubUrl()==null){ - return program.toBuilder().githubUrl(defaultUrl).build(); - } - return program; - }) - .map(program -> { - if(program.getAttendMode()==null){ - return program.toBuilder().attendMode(ProgramAttendMode.END).build(); - } - - return program; - }) - .collect(Collectors.toList()); - - programRepository.saveAll(programs); - System.out.println("----------------------------------------------"); - } - - private List getPrograms(){ - return programRepository.findAll(); - } + private final ProgramRepository programRepository; + private final String defaultUrl = + "https://github.com/JNU-econovation/weekly_presentation/tree/2024-1/2024-1/A_team/1st"; + + @Override + public void run(ApplicationArguments args) throws Exception { + System.out.println("------------Program Initializer----------"); + List programs = getPrograms(); + + if (programs.isEmpty()) return; + + programs = + programs.stream() + .map( + program -> { + if (program.getGithubUrl() == null) { + return program.toBuilder().githubUrl(defaultUrl).build(); + } + return program; + }) + .map( + program -> { + if (program.getAttendMode() == null) { + return program.toBuilder().attendMode(ProgramAttendMode.END).build(); + } + + return program; + }) + .collect(Collectors.toList()); + + programRepository.saveAll(programs); + System.out.println("----------------------------------------------"); + } + + private List getPrograms() { + return programRepository.findAll(); + } } diff --git a/eeos/src/main/java/com/blackcompany/eeos/target/application/model/AttendModel.java b/eeos/src/main/java/com/blackcompany/eeos/target/application/model/AttendModel.java index b45dc640..1c947aeb 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/target/application/model/AttendModel.java +++ b/eeos/src/main/java/com/blackcompany/eeos/target/application/model/AttendModel.java @@ -2,8 +2,6 @@ import com.blackcompany.eeos.common.application.model.MemberIdModel; import com.blackcompany.eeos.common.support.AbstractModel; -import com.blackcompany.eeos.target.application.exception.DeniedChangeAttendException; -import com.blackcompany.eeos.target.application.exception.DeniedSaveAttendException; import com.blackcompany.eeos.target.application.exception.NotSameBeforeAttendStatusException; import java.util.List; import java.util.stream.Collectors; @@ -35,8 +33,9 @@ public String getStatus() { return status.getStatus(); } - public boolean isAttended(){ - return (!this.status.equals(AttendStatus.NONRESPONSE) && !this.status.equals(AttendStatus.NONRELATED)); + public boolean isAttended() { + return (!this.status.equals(AttendStatus.NONRESPONSE) + && !this.status.equals(AttendStatus.NONRELATED)); } public boolean isRelated() { diff --git a/eeos/src/main/java/com/blackcompany/eeos/target/application/service/AttendService.java b/eeos/src/main/java/com/blackcompany/eeos/target/application/service/AttendService.java index 6dda6829..771a5e93 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/target/application/service/AttendService.java +++ b/eeos/src/main/java/com/blackcompany/eeos/target/application/service/AttendService.java @@ -130,9 +130,10 @@ public QueryAttendActiveStatusResponse getAttendInfo(Long programId, String acti } private void validateAttend(ProgramModel programModel, AttendModel attendModel) { - if (programModel.getAttendMode().equals(ProgramAttendMode.END)) throw new NotStartAttendException(); - if(attendModel.isAttended()) throw new DeniedChangeAttendException(); - if(!attendModel.isRelated()) throw new DeniedSaveAttendException(); + if (programModel.getAttendMode().equals(ProgramAttendMode.END)) + throw new NotStartAttendException(); + if (attendModel.isAttended()) throw new DeniedChangeAttendException(); + if (!attendModel.isRelated()) throw new DeniedSaveAttendException(); } private ProgramModel findProgram(final Long programId) { 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 3591e857..ad6e59d6 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 @@ -7,6 +7,10 @@ import com.blackcompany.eeos.team.application.exception.NotFoundTeamException; import com.blackcompany.eeos.team.persistence.TeamEntity; import com.blackcompany.eeos.team.persistence.TeamRepository; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -14,81 +18,83 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - // 기존에 저장된 Program과 Team을 매핑하는 구조 @Component @RequiredArgsConstructor @Slf4j public class PresentationInitializer implements ApplicationRunner { - private final PresentationRepository presentationRepository; - private final ProgramRepository programRepository; - private final TeamRepository teamRepository; - - @Value("${eeos.team.list}") - private String teamList; - - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("------------Presentation Initializer----------"); - Set programs = getPrograms().stream().map(ProgramEntity::getId).collect(Collectors.toSet()); - - if(programs.isEmpty()) return; - - Set presentations = getPresentations().stream() - .map(PresentationEntity::getProgramId) - .collect(Collectors.toSet()); - - Set target = programs.stream() - .filter(programId -> !presentations.contains(programId)) - .collect(Collectors.toSet()); - - List teams= getTeams(); - teams.forEach(team->log.info(team.getName())); - - target.forEach(targetId -> - { - Set entities = - teams.stream() - .map(TeamEntity::getId) - .map(teamId -> PresentationEntity.builder() - .teamId(teamId) - .programId(targetId) - .build()) - .collect(Collectors.toSet()); - presentationRepository.saveAll(entities); - }); - - System.out.println("----------------------------------------------"); - } - - private List getTeamList(){ - return Arrays.stream(teamList.split(",")).toList(); - } - - private List getPrograms(){ - return programRepository.findAll(); - } - - private List getTeams(){ - List teams = getTeamList(); - try { - return teamRepository.findAllTeams().stream().filter(team -> teams.contains(team.getName())).toList(); - } catch (NotFoundTeamException e){ - return createTeams(); - } - } - - private List createTeams(){ - Set teams = getTeamList().stream().map(team -> TeamEntity.builder().name(team).status(false).build()).collect(Collectors.toSet()); - return teamRepository.saveAll(teams); - } - - private List getPresentations(){ - return presentationRepository.findAll(); - } + private final PresentationRepository presentationRepository; + private final ProgramRepository programRepository; + private final TeamRepository teamRepository; + + @Value("${eeos.team.list}") + private String teamList; + + @Override + public void run(ApplicationArguments args) throws Exception { + System.out.println("------------Presentation Initializer----------"); + Set programs = + getPrograms().stream().map(ProgramEntity::getId).collect(Collectors.toSet()); + + if (programs.isEmpty()) return; + + Set presentations = + getPresentations().stream() + .map(PresentationEntity::getProgramId) + .collect(Collectors.toSet()); + + Set target = + programs.stream() + .filter(programId -> !presentations.contains(programId)) + .collect(Collectors.toSet()); + + List teams = getTeams(); + teams.forEach(team -> log.info(team.getName())); + + target.forEach( + targetId -> { + Set entities = + teams.stream() + .map(TeamEntity::getId) + .map( + teamId -> + PresentationEntity.builder().teamId(teamId).programId(targetId).build()) + .collect(Collectors.toSet()); + presentationRepository.saveAll(entities); + }); + + System.out.println("----------------------------------------------"); + } + + private List getTeamList() { + return Arrays.stream(teamList.split(",")).toList(); + } + + private List getPrograms() { + return programRepository.findAll(); + } + + private List getTeams() { + List teams = getTeamList(); + try { + return teamRepository.findAllTeams().stream() + .filter(team -> teams.contains(team.getName())) + .toList(); + } catch (NotFoundTeamException e) { + return createTeams(); + } + } + + private List createTeams() { + Set teams = + getTeamList().stream() + .map(team -> TeamEntity.builder().name(team).status(false).build()) + .collect(Collectors.toSet()); + return teamRepository.saveAll(teams); + } + + private List getPresentations() { + return presentationRepository.findAll(); + } } diff --git a/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java index f905c19e..391ba759 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java +++ b/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java @@ -2,6 +2,9 @@ import com.blackcompany.eeos.team.persistence.TeamEntity; import com.blackcompany.eeos.team.persistence.TeamRepository; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -9,40 +12,35 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; - - // 기존 데이터베이스와의 데이터 정합성을 위한 클래스 @RequiredArgsConstructor @Slf4j @Component public class TeamInitializer implements ApplicationRunner { - private final TeamRepository teamRepository; - - @Value("${eeos.team.list}") - private String teamList; - - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("-----------Team Initializer-----------"); - Arrays.stream(teamList.split(",")).forEach(log::info); - try { - Set newTeams = Arrays.stream(teamList.split(",")) - .map(teamName -> TeamEntity.builder().name(teamName).status(false).build()) - .collect(Collectors.toSet()); - teamRepository.saveAll(newTeams); - log.info("임시 팀이 생성되었습니다."); - } catch (Exception e){ - log.error("임시 팀이 생성되지 않았습니다."); - } - System.out.println("---------------------------------------"); - - } - - private boolean isEmptyTable(){ - return teamRepository.findAllTeams().isEmpty(); - } + private final TeamRepository teamRepository; + + @Value("${eeos.team.list}") + private String teamList; + + @Override + public void run(ApplicationArguments args) throws Exception { + System.out.println("-----------Team Initializer-----------"); + Arrays.stream(teamList.split(",")).forEach(log::info); + try { + Set newTeams = + Arrays.stream(teamList.split(",")) + .map(teamName -> TeamEntity.builder().name(teamName).status(false).build()) + .collect(Collectors.toSet()); + teamRepository.saveAll(newTeams); + log.info("임시 팀이 생성되었습니다."); + } catch (Exception e) { + log.error("임시 팀이 생성되지 않았습니다."); + } + System.out.println("---------------------------------------"); + } + + private boolean isEmptyTable() { + return teamRepository.findAllTeams().isEmpty(); + } } diff --git a/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamEntity.java b/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamEntity.java index 4004494d..6ba617b7 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamEntity.java +++ b/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamEntity.java @@ -30,9 +30,7 @@ public class TeamEntity extends BaseEntity { @Column(unique = true, name = ENTITY_PREFIX + "_name", nullable = false) private String name; - @Column( - name = ENTITY_PREFIX + "_status", - nullable = false) + @Column(name = ENTITY_PREFIX + "_status", nullable = false) @Builder.Default private boolean status = true; // 현학기 활동팀 1, 아니면 0 diff --git a/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamRepository.java b/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamRepository.java index 0d4aba3c..167d141d 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamRepository.java +++ b/eeos/src/main/java/com/blackcompany/eeos/team/persistence/TeamRepository.java @@ -20,7 +20,6 @@ public interface TeamRepository extends JpaRepository { @Query("SELECT T FROM TeamEntity T WHERE T.status = true order by T.name") List findAllActiveTeams(); - @Query("SELECT T FROM TeamEntity T ORDER BY T.name") List findAllTeams(); }