diff --git a/be/src/main/java/com/example/be/core/application/dto/request/StudyRequest.java b/be/src/main/java/com/example/be/core/application/dto/request/StudyRequest.java index 73edc29..095a2cb 100644 --- a/be/src/main/java/com/example/be/core/application/dto/request/StudyRequest.java +++ b/be/src/main/java/com/example/be/core/application/dto/request/StudyRequest.java @@ -1,6 +1,7 @@ package com.example.be.core.application.dto.request; import com.example.be.core.domain.study.StudyDay; +import com.example.be.core.domain.study.StudyRegion; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDate; import java.util.EnumSet; @@ -47,8 +48,8 @@ public class StudyRequest { @NotBlank private String rule; - @Schema(type = "String", description = "지역, NULL") - private String region; + @Schema(type = "StudyRegion", description = "지역, NULL") + private StudyRegion region; @Schema(type = "String", description = "스터디 하는 요일, NOT NULL") @NotBlank @@ -60,7 +61,7 @@ public class StudyRequest { public StudyRequest(String title, String content, Integer level, String language, String speakingTest, String grade, Integer maxCapacity, Integer minCapacity, String rule, - String region, String studyDay, String posterImage) { + StudyRegion region, String studyDay, String posterImage) { this.title = title; this.content = content; this.level = level; diff --git a/be/src/main/java/com/example/be/core/application/dto/response/StudyDetailResponse.java b/be/src/main/java/com/example/be/core/application/dto/response/StudyDetailResponse.java index 7f36e2e..e57dfb8 100644 --- a/be/src/main/java/com/example/be/core/application/dto/response/StudyDetailResponse.java +++ b/be/src/main/java/com/example/be/core/application/dto/response/StudyDetailResponse.java @@ -1,5 +1,6 @@ package com.example.be.core.application.dto.response; +import com.example.be.core.domain.study.StudyRegion; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import javax.validation.constraints.Positive; @@ -39,8 +40,8 @@ public class StudyDetailResponse { @Schema(type = "String", description = "대면, 비대면 규칙, NOT NULL") private final String rule; - @Schema(type = "String", description = "지역, NULL") - private final String region; + @Schema(type = "StudyRegion", description = "지역, NULL") + private final StudyRegion region; @Schema(type = "String", description = "스터디 하는 요일, NOT NULL") private final String studyDay; @@ -62,7 +63,7 @@ public class StudyDetailResponse { public StudyDetailResponse(Long studyId, String title, String content, Integer level, String language, String speakingTest, String grade, Integer maxCapacity, Integer minCapacity, - String rule, String region, String studyDay, String posterImage, Integer interestCount, + String rule, StudyRegion region, String studyDay, String posterImage, Integer interestCount, Boolean isInterested, Boolean isLeader, MemberProfilesResponse memberProfiles) { this.studyId = studyId; this.title = title; diff --git a/be/src/main/java/com/example/be/core/domain/member/Member.java b/be/src/main/java/com/example/be/core/domain/member/Member.java index ecd9092..6df8d5c 100644 --- a/be/src/main/java/com/example/be/core/domain/member/Member.java +++ b/be/src/main/java/com/example/be/core/domain/member/Member.java @@ -3,6 +3,8 @@ import com.example.be.core.domain.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -33,6 +35,8 @@ public class Member extends BaseEntity { private String uniqueId; private String profileImage; + + @Enumerated(EnumType.STRING) private MemberType memberType; private Boolean alarmStatus; private Integer point; diff --git a/be/src/main/java/com/example/be/core/domain/study/Study.java b/be/src/main/java/com/example/be/core/domain/study/Study.java index 1212965..545ffba 100644 --- a/be/src/main/java/com/example/be/core/domain/study/Study.java +++ b/be/src/main/java/com/example/be/core/domain/study/Study.java @@ -5,6 +5,8 @@ import javax.persistence.Column; import javax.persistence.Convert; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -43,8 +45,8 @@ public class Study extends BaseEntity { private String rule; - @Convert(converter = StudyRegionConverter.class) - private String region; + @Enumerated(EnumType.STRING) + private StudyRegion region; private Integer maxCapacity; @@ -55,7 +57,7 @@ public class Study extends BaseEntity { private String grade; public Study(String title, String content, String posterImage, String language, Integer level, - EnumSet studyDay, String rule, String region, Integer maxCapacity, + EnumSet studyDay, String rule, StudyRegion region, Integer maxCapacity, Integer minCapacity, String speakingTest, String grade) { this.title = title; this.content = content; @@ -72,7 +74,7 @@ public Study(String title, String content, String posterImage, String language, } public void modify(String title, String content, String posterImage, String language, Integer level, - EnumSet studyDay, String rule, String region, Integer maxCapacity, + EnumSet studyDay, String rule, StudyRegion region, Integer maxCapacity, Integer minCapacity, String speakingTest, String grade) { this.title = title; this.content = content; diff --git a/be/src/main/java/com/example/be/core/domain/study/StudyDay.java b/be/src/main/java/com/example/be/core/domain/study/StudyDay.java index 97dbf17..684a9e6 100644 --- a/be/src/main/java/com/example/be/core/domain/study/StudyDay.java +++ b/be/src/main/java/com/example/be/core/domain/study/StudyDay.java @@ -1,7 +1,8 @@ package com.example.be.core.domain.study; +import com.fasterxml.jackson.annotation.JsonCreator; +import java.util.Arrays; import lombok.Getter; -import lombok.ToString; @Getter public enum StudyDay { @@ -13,9 +14,16 @@ public enum StudyDay { SATURDAY("토"), SUNDAY("일"); - private String studyDay; + private final String studyDay; StudyDay(String studyDay) { this.studyDay = studyDay; } + + public static StudyDay convert(String source) { + return Arrays.stream(values()) + .filter(v -> v.studyDay.equals(source)) + .findAny() + .orElseThrow(IllegalArgumentException::new); + } } diff --git a/be/src/main/java/com/example/be/core/domain/study/StudyDayConverter.java b/be/src/main/java/com/example/be/core/domain/study/StudyDayConverter.java index 9e975be..1826097 100644 --- a/be/src/main/java/com/example/be/core/domain/study/StudyDayConverter.java +++ b/be/src/main/java/com/example/be/core/domain/study/StudyDayConverter.java @@ -14,19 +14,21 @@ public class StudyDayConverter implements AttributeConverter, @Override public String convertToDatabaseColumn(EnumSet attribute) { StringBuilder sb = new StringBuilder(); - attribute.stream().forEach(e -> sb.append(e.getStudyDay() + ",")); + attribute.forEach(e -> sb.append(e.getStudyDay()).append(",")); String result = sb.toString(); - if (result.charAt(result.length() - 1) == ',') result = result.substring(0, result.length() - 1); + if (result.charAt(result.length() - 1) == ',') { + result = result.substring(0, result.length() - 1); + } log.debug("[DB 에서 사용될 StudyDay 정보] : {}", result); return result; } @Override public EnumSet convertToEntityAttribute(String dbData) { - if (dbData == null || dbData == "" || dbData.contains(".")) return EnumSet.noneOf(StudyDay.class); + if (dbData == null || dbData.equals("") || dbData.contains(".")) return EnumSet.noneOf(StudyDay.class); EnumSet attribute = EnumSet.noneOf(StudyDay.class); String[] dbDataArray = StringUtils.trimAllWhitespace(dbData).toUpperCase().split(","); - Arrays.stream(dbDataArray).forEach(e -> attribute.add(StudyDay.valueOf(e))); + Arrays.stream(dbDataArray).forEach(e -> attribute.add(StudyDay.convert(e))); log.debug("[Entity 에서 사용될 StudyDay 정보] : {}", attribute); return attribute; } diff --git a/be/src/main/java/com/example/be/core/domain/study/StudyRegion.java b/be/src/main/java/com/example/be/core/domain/study/StudyRegion.java index 73c35a7..cbd0124 100644 --- a/be/src/main/java/com/example/be/core/domain/study/StudyRegion.java +++ b/be/src/main/java/com/example/be/core/domain/study/StudyRegion.java @@ -1,5 +1,7 @@ package com.example.be.core.domain.study; +import com.fasterxml.jackson.annotation.JsonCreator; +import java.util.Arrays; import lombok.Getter; @Getter @@ -21,7 +23,7 @@ public enum StudyRegion { JEJU("제주"), ETC("기타"); - private String region; + private final String region; StudyRegion(String region) { this.region = region; diff --git a/be/src/main/java/com/example/be/core/domain/study/StudyRegionConverter.java b/be/src/main/java/com/example/be/core/domain/study/StudyRegionConverter.java deleted file mode 100644 index 139a2fc..0000000 --- a/be/src/main/java/com/example/be/core/domain/study/StudyRegionConverter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.example.be.core.domain.study; - -import java.util.Objects; -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; - -@Converter -public class StudyRegionConverter implements AttributeConverter { - - @Override - public String convertToDatabaseColumn(StudyRegion attribute) { - if (Objects.isNull(attribute)) { - return null; - } - return attribute.getRegion(); - } - - @Override - public StudyRegion convertToEntityAttribute(String dbData) { - if (dbData.isBlank()){ - return null; - } - return StudyRegion.valueOf(dbData); - } -} diff --git a/be/src/test/java/com/example/be/core/application/study/StudyCreateTest.java b/be/src/test/java/com/example/be/core/application/study/StudyCreateTest.java index f086f6e..a1aa167 100644 --- a/be/src/test/java/com/example/be/core/application/study/StudyCreateTest.java +++ b/be/src/test/java/com/example/be/core/application/study/StudyCreateTest.java @@ -6,6 +6,7 @@ import com.example.be.core.application.dto.request.StudyRequest; import com.example.be.core.application.dto.response.StudyDetailResponse; import com.example.be.core.domain.study.StudyDay; +import com.example.be.core.domain.study.StudyRegion; import java.util.EnumSet; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -37,7 +38,7 @@ void create_study() throws Exception { 5, 1, "대면", - "서울", + StudyRegion.SEOUL, "월,화,수", "study" ); diff --git a/be/src/test/java/com/example/be/core/application/study/StudyModifyTest.java b/be/src/test/java/com/example/be/core/application/study/StudyModifyTest.java index 493c613..ee88c87 100644 --- a/be/src/test/java/com/example/be/core/application/study/StudyModifyTest.java +++ b/be/src/test/java/com/example/be/core/application/study/StudyModifyTest.java @@ -6,6 +6,7 @@ import com.example.be.core.application.dto.request.StudyRequest; import com.example.be.core.application.dto.response.StudyDetailResponse; import com.example.be.core.domain.study.StudyDay; +import com.example.be.core.domain.study.StudyRegion; import com.example.be.core.domain.study.StudyType; import java.util.EnumSet; import org.junit.jupiter.api.DisplayName; @@ -31,7 +32,7 @@ void normal_modify() throws Exception { Long memberId = 1L; StudyRequest request = new StudyRequest("수정 제목", "수정 내용", 5, "수정 언어", "수정 목표", "수정 자격증", - 5, 1, "대면", "서울", "월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg"); + 5, 1, "대면", StudyRegion.SEOUL, "월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg"); //when studyService.modify(memberId, studyId, request); diff --git a/be/src/test/java/com/example/be/core/web/study/StudyControllerCreatTest.java b/be/src/test/java/com/example/be/core/web/study/StudyControllerCreatTest.java index d8f0dac..6dda6a7 100644 --- a/be/src/test/java/com/example/be/core/web/study/StudyControllerCreatTest.java +++ b/be/src/test/java/com/example/be/core/web/study/StudyControllerCreatTest.java @@ -14,6 +14,7 @@ import com.example.be.core.application.dto.response.MemberProfilesResponse; import com.example.be.core.application.dto.response.StudyDetailResponse; import com.example.be.core.domain.study.StudyDay; +import com.example.be.core.domain.study.StudyRegion; import com.example.be.core.web.InitControllerTest; import com.example.be.core.web.StudyController; import java.util.ArrayList; @@ -45,9 +46,9 @@ void create_study() throws Exception { Integer likeCount = 10; StudyRequest request = new StudyRequest("스터디1", "내용1", 3, "english", - "OPIC", "AL", 5, 1, "대면", "서울", "월,화,수","https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg"); + "OPIC", "AL", 5, 1, "대면", StudyRegion.SEOUL, "월,화,수","https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg"); StudyDetailResponse response = new StudyDetailResponse(memberId, "스터디1", "내용1", 3, "english", - "OPIC", "AL", 5, 1, "대면", "서울","월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg",likeCount, false, Boolean.TRUE, new MemberProfilesResponse("leader", new ArrayList<>())); + "OPIC", "AL", 5, 1, "대면", StudyRegion.SEOUL,"월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg",likeCount, false, Boolean.TRUE, new MemberProfilesResponse("leader", new ArrayList<>())); BaseResponse baseResponse = new BaseResponse<>(CREATE_STUDY_SUCCESS, response); when(studyService.create(refEq(request), refEq(memberId))) diff --git a/be/src/test/java/com/example/be/core/web/study/StudyControllerDetailFindTest.java b/be/src/test/java/com/example/be/core/web/study/StudyControllerDetailFindTest.java index 2a9010d..0b318b4 100644 --- a/be/src/test/java/com/example/be/core/web/study/StudyControllerDetailFindTest.java +++ b/be/src/test/java/com/example/be/core/web/study/StudyControllerDetailFindTest.java @@ -13,6 +13,7 @@ import com.example.be.core.application.dto.response.MemberProfilesResponse; import com.example.be.core.application.dto.response.StudyDetailResponse; import com.example.be.core.domain.study.StudyDay; +import com.example.be.core.domain.study.StudyRegion; import com.example.be.core.web.InitControllerTest; import com.example.be.core.web.StudyController; import java.util.ArrayList; @@ -44,7 +45,7 @@ void find_detail_study_log() throws Exception { Long studyId = 1L; Integer likeCount = 10; StudyDetailResponse response = new StudyDetailResponse(memberId, "스터디1", "내용1", 3, "english", - "OPIC", "AL", 5, 1, "대면", "서울","월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg",likeCount, false, Boolean.TRUE, new MemberProfilesResponse("leader", new ArrayList<>())); + "OPIC", "AL", 5, 1, "대면", StudyRegion.SEOUL,"월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg",likeCount, false, Boolean.TRUE, new MemberProfilesResponse("leader", new ArrayList<>())); BaseResponse baseResponse = new BaseResponse<>( FIND_DETAIL_STUDY_SUCCESS, response); diff --git a/be/src/test/java/com/example/be/core/web/study/StudyControllerModifyTest.java b/be/src/test/java/com/example/be/core/web/study/StudyControllerModifyTest.java index 9d827b2..a6d62e0 100644 --- a/be/src/test/java/com/example/be/core/web/study/StudyControllerModifyTest.java +++ b/be/src/test/java/com/example/be/core/web/study/StudyControllerModifyTest.java @@ -14,6 +14,7 @@ import com.example.be.core.application.dto.response.MemberProfilesResponse; import com.example.be.core.application.dto.response.StudyDetailResponse; import com.example.be.core.domain.study.StudyDay; +import com.example.be.core.domain.study.StudyRegion; import com.example.be.core.web.InitControllerTest; import com.example.be.core.web.StudyController; import java.util.ArrayList; @@ -46,9 +47,9 @@ void modify_study() throws Exception { Long studyId = 1L; Integer likeCount = 10; StudyRequest request = new StudyRequest("스터디1", "내용1", 3, "english", - "OPIC", "AL", 5, 1, "대면", "서울", "월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg"); + "OPIC", "AL", 5, 1, "대면", StudyRegion.SEOUL, "월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg"); StudyDetailResponse response = new StudyDetailResponse(memberId, "스터디1", "내용1", 3, "english", - "OPIC", "AL", 5, 1, "대면", "서울","월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg",likeCount, false, Boolean.TRUE, new MemberProfilesResponse("leader", new ArrayList<>())); + "OPIC", "AL", 5, 1, "대면", StudyRegion.SEOUL,"월,화,수", "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/a4cd3848-b965-4504-90ce-b772398d7f11.jpeg",likeCount, false, Boolean.TRUE, new MemberProfilesResponse("leader", new ArrayList<>())); BaseResponse baseResponse = new BaseResponse<>(MODIFY_STUDY_SUCCESS, response); when(studyService.modify(refEq(memberId), refEq(studyId), refEq(request))) diff --git a/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java b/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java index fd9b866..d078b7b 100644 --- a/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java +++ b/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java @@ -10,6 +10,7 @@ import com.example.be.core.domain.study.Study; import com.example.be.core.domain.study.StudyDay; import com.example.be.core.domain.study.StudyMember; +import com.example.be.core.domain.study.StudyRegion; import com.example.be.core.repository.assignment.AssignmentMemberRepository; import com.example.be.core.repository.assignment.AssignmentRepository; import com.example.be.core.repository.member.MemberRepository; @@ -74,6 +75,8 @@ public class DataBaseConfigurator implements InitializingBean { private List tableNames; + EnumSet studyDay = EnumSet.allOf(StudyDay.class); + @Override public void afterPropertiesSet() throws Exception { entityManager.unwrap(Session.class).doWork(this::extractTableNames); @@ -164,9 +167,9 @@ private void initStudy() { "study-posterImage" + i, "study-language" + i, i, - EnumSet.of(StudyDay.MONDAY), + studyDay, "study-rule" + i, - "study-region" + i, + StudyRegion.SEOUL, i, i, "study-speakingTest" + i, @@ -176,11 +179,15 @@ private void initStudy() { for (int j = 1; j <= NUMBER_OF_MEMBER; j++) { Member member = memberRepository.findById((long) j) .orElseThrow(NotFoundMemberIdException::new); + boolean leader = Boolean.FALSE; + if(j == 1){ + leader = Boolean.TRUE; + } studyMemberRepository.save( new StudyMember( member, study, - Boolean.TRUE + leader ) ); }