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

[BUG] CI가 통과하게 한다 #176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProgramEntity> 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<ProgramEntity> 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<ProgramEntity> 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<ProgramEntity> getPrograms() {
return programRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,94 @@
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;
import org.springframework.boot.ApplicationArguments;
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<Long> programs = getPrograms().stream().map(ProgramEntity::getId).collect(Collectors.toSet());

if(programs.isEmpty()) return;

Set<Long> presentations = getPresentations().stream()
.map(PresentationEntity::getProgramId)
.collect(Collectors.toSet());

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

List<TeamEntity> teams= getTeams();
teams.forEach(team->log.info(team.getName()));

target.forEach(targetId ->
{
Set<PresentationEntity> 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<String> getTeamList(){
return Arrays.stream(teamList.split(",")).toList();
}

private List<ProgramEntity> getPrograms(){
return programRepository.findAll();
}

private List<TeamEntity> getTeams(){
List<String> teams = getTeamList();
try {
return teamRepository.findAllTeams().stream().filter(team -> teams.contains(team.getName())).toList();
} catch (NotFoundTeamException e){
return createTeams();
}
}

private List<TeamEntity> createTeams(){
Set<TeamEntity> teams = getTeamList().stream().map(team -> TeamEntity.builder().name(team).status(false).build()).collect(Collectors.toSet());
return teamRepository.saveAll(teams);
}

private List<PresentationEntity> 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<Long> programs =
getPrograms().stream().map(ProgramEntity::getId).collect(Collectors.toSet());

if (programs.isEmpty()) return;

Set<Long> presentations =
getPresentations().stream()
.map(PresentationEntity::getProgramId)
.collect(Collectors.toSet());

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

List<TeamEntity> teams = getTeams();
teams.forEach(team -> log.info(team.getName()));

target.forEach(
targetId -> {
Set<PresentationEntity> 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<String> getTeamList() {
return Arrays.stream(teamList.split(",")).toList();
}

private List<ProgramEntity> getPrograms() {
return programRepository.findAll();
}

private List<TeamEntity> getTeams() {
List<String> teams = getTeamList();
try {
return teamRepository.findAllTeams().stream()
.filter(team -> teams.contains(team.getName()))
.toList();
} catch (NotFoundTeamException e) {
return createTeams();
}
}

private List<TeamEntity> createTeams() {
Set<TeamEntity> teams =
getTeamList().stream()
.map(team -> TeamEntity.builder().name(team).status(false).build())
.collect(Collectors.toSet());
return teamRepository.saveAll(teams);
}

private List<PresentationEntity> getPresentations() {
return presentationRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,45 @@

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;
import org.springframework.boot.ApplicationArguments;
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<TeamEntity> 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<TeamEntity> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public interface TeamRepository extends JpaRepository<TeamEntity, Long> {
@Query("SELECT T FROM TeamEntity T WHERE T.status = true order by T.name")
List<TeamEntity> findAllActiveTeams();


@Query("SELECT T FROM TeamEntity T ORDER BY T.name")
List<TeamEntity> findAllTeams();
}
Loading
Loading