Skip to content

Commit

Permalink
[REFACTOR] 이전 학기 팀 리스트 환경 변수에서 가져와 생성 (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlajm1203 authored Oct 3, 2024
1 parent e4ce43c commit f878217
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import com.blackcompany.eeos.team.persistence.TeamRepository;
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
Expand All @@ -17,12 +22,18 @@ 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 {
TeamEntity defaultTeam = TeamEntity.builder().id(0L).name("임시 활동 팀").status(false).build();
teamRepository.save(defaultTeam);
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("임시 팀이 생성되지 않았습니다.");
Expand Down
11 changes: 10 additions & 1 deletion eeos/src/main/resources/application-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ eeos:
admin:
name : ${ADMIN_NAME}
loginId : ${ADMIN_LOGIN_ID}
password: ${ADMIN_PASSWORD}
password: ${ADMIN_PASSWORD}
team:
list: ${ECONOVATION_TEAM_LIST}

server:
servlet:
encoding:
charset: UTF-8
enabled: true
force: true
3 changes: 3 additions & 0 deletions eeos/src/main/resources/application-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ spring:
ddl-auto: validate
generate-ddl: true
open-in-view: false
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect
flyway:
baseline-on-migrate: true
enabled: true
Expand Down

0 comments on commit f878217

Please sign in to comment.