From 32148da6ed18a9ff7793bfe1bdcb255352bd5759 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Thu, 15 Aug 2024 12:38:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=20=EC=84=A4=EC=A0=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=8B=A8=EA=B3=BC=EB=8C=80,=20=ED=95=99=EA=B3=BC=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20AfiiliationCode=20?= =?UTF-8?q?affiliationName=20->=20name=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/entity/enums/AffiliationCode.java | 10 ++--- .../member/entity/role/Affiliation.java | 5 +++ .../member/service/MemberServiceImpl.java | 2 +- .../global/database/InitialDataLoader.java | 38 ++++++++++--------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java index b3f7f5a..f7ea7ce 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java @@ -60,12 +60,12 @@ public enum AffiliationCode { private final int val; private final String councilType; - private final String councilName; + private final String name; public static AffiliationCode fromCouncilName(String councilName) { for (AffiliationCode affiliationCodeIns : AffiliationCode.values()) { - if (affiliationCodeIns.councilName.equals(councilName)) { + if (affiliationCodeIns.name.equals(councilName)) { return affiliationCodeIns; } } @@ -74,7 +74,7 @@ public static AffiliationCode fromCouncilName(String councilName) { public static List getDepartmentsByCollegeName(String collegeName) { AffiliationCode college = Arrays.stream(AffiliationCode.values()) - .filter(ac -> ac.getCouncilName().equals(collegeName)) + .filter(ac -> ac.getName().equals(collegeName)) .findFirst() .orElseThrow(() -> new BusinessException(INVALID_AFFILIATION)); @@ -85,7 +85,7 @@ public static List getDepartmentsByCollegeName(String colle // 단과대에 속한 학과를 필터링하여 반환합니다. return Arrays.stream(AffiliationCode.values()) .filter(code -> code.getCouncilType().equals("학과") && code.getVal() > college.getVal() && code.getVal() <= getMaxValForCollege(college)) - .map(department -> AffiliationResponse.fromAffiliationResponse(department.getVal(), department.getCouncilName())) + .map(department -> AffiliationResponse.fromAffiliationResponse(department.getVal(), department.getName())) .collect(Collectors.toList()); } @@ -108,6 +108,6 @@ private static int getMaxValForCollege(AffiliationCode college) { @JsonValue public String getAffiliationCode() { - return this.councilName; + return this.name; } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/Affiliation.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/Affiliation.java index 589928d..191997f 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/Affiliation.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/Affiliation.java @@ -1,5 +1,6 @@ package com.example.bigbrotherbe.domain.member.entity.role; +import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -28,4 +29,8 @@ public class Affiliation { @Column private String presidentName; + + public static Affiliation toEntity(AffiliationCode affiliationCode) { + return Affiliation.builder().affiliation_id((long)affiliationCode.getVal()).councilType(affiliationCode.getCouncilType()).name(affiliationCode.getName()).build(); + } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java index 01c6ac9..bd6cd6f 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java @@ -207,7 +207,7 @@ public void makeAffiliation() { public List getColleges() { return Arrays.stream(AffiliationCode.values()) .filter(code -> code.getCouncilType().equals("단과대")) - .map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getCouncilName())) + .map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getName())) .collect(Collectors.toList()); } diff --git a/src/main/java/com/example/bigbrotherbe/global/database/InitialDataLoader.java b/src/main/java/com/example/bigbrotherbe/global/database/InitialDataLoader.java index 905f41f..3ba4d3a 100644 --- a/src/main/java/com/example/bigbrotherbe/global/database/InitialDataLoader.java +++ b/src/main/java/com/example/bigbrotherbe/global/database/InitialDataLoader.java @@ -1,6 +1,7 @@ package com.example.bigbrotherbe.global.database; import com.example.bigbrotherbe.domain.member.entity.Member; +import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; import com.example.bigbrotherbe.domain.member.repository.AffiliationMemberRepository; import com.example.bigbrotherbe.domain.member.repository.AffiliationRepository; import com.example.bigbrotherbe.domain.member.repository.MemberRepository; @@ -20,15 +21,10 @@ public class InitialDataLoader { public CommandLineRunner loadData(MemberRepository memberRepository, AffiliationRepository affiliationRepository, AffiliationMemberRepository affiliationMemberRepository, PasswordEncoder passwordEncoder) { return args -> { - if (affiliationRepository.findByName("응용소프트웨어전공").isEmpty()) { - affiliationRepository.save(Affiliation.builder().affiliation_id(1L).name("응용소프트웨어전공").councilType("학과").build()); - } - - if (affiliationRepository.findByName("디지털콘텐츠디자인학과").isEmpty()) { - affiliationRepository.save(Affiliation.builder().affiliation_id(2L).name("디지털콘텐츠디자인학과").councilType("학과").build()); - } - if (affiliationRepository.findByName("ICT융합대학").isEmpty()) { - affiliationRepository.save(Affiliation.builder().affiliation_id(3L).name("ICT융합대학").councilType("단과대").build()); + for(AffiliationCode affiliationCode : AffiliationCode.values()){ + if(affiliationRepository.findByName(affiliationCode.getName()).isEmpty()){ + affiliationRepository.save(Affiliation.toEntity(affiliationCode)); + } } // Check if an admin user already exists if (memberRepository.findByUsername("admin").isEmpty()) { @@ -38,17 +34,25 @@ public CommandLineRunner loadData(MemberRepository memberRepository, Affiliation admin.setEmail("developthreefeet@gmail.com"); admin.setUsername("admin"); memberRepository.save(admin); - Affiliation affiliation = affiliationRepository.findByName("응용소프트웨어전공") - .orElseThrow(() -> new IllegalArgumentException("잘못된 소속 이름입니다.")); + + Affiliation college = Affiliation.toEntity(AffiliationCode.ICT); // AffiliationMember 엔티티 생성 - AffiliationMember affiliationMember = AffiliationMember.builder() - .member(admin) - .affiliation(affiliation) - .role("ROLE_ADMIN") - .build(); + affiliationMemberRepository.save(AffiliationMember + .builder() + .member(admin) + .affiliation(college) + .role("ROLE_ADMIN") + .build()); + + Affiliation affiliation = Affiliation.toEntity(AffiliationCode.SOFTWARE_APPLICATIONS); + affiliationMemberRepository.save(AffiliationMember + .builder() + .member(admin) + .affiliation(affiliation) + .role("ROLE_ADMIN") + .build()); - affiliationMemberRepository.save(affiliationMember); } }; } From 1e8b58881fb3f125f26e8b53762c4e6a6861e3bf Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Thu, 15 Aug 2024 12:39:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore=20:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=ED=99=98=EA=B2=BD=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EA=B0=92=20=EC=84=A4=EC=A0=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-local.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index ed0c9b9..ac31f4a 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,20 +1,20 @@ spring: -# datasource: -# url: ${DB_URL} -# driver-class-name: com.mysql.cj.jdbc.Driver -# username: ${DB_USER_NAME} -# password: ${DB_PASSWORD} - - # 태태 로컬 데이터베이스 설정 datasource: - url: jdbc:mysql://localhost:3306/bigbrother + url: ${DB_URL} driver-class-name: com.mysql.cj.jdbc.Driver - username: root - password: 1234 + username: ${DB_USER_NAME} + password: ${DB_PASSWORD} + + # 태태 로컬 데이터베이스 설정 +# datasource: +# url: jdbc:mysql://localhost:3306/bigbrother +# driver-class-name: com.mysql.cj.jdbc.Driver +# username: root +# password: 1234 jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: format_sql: true