From 7c1e15ad4ab159278e6bdf2c57c0fdba6c9b291e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B5=90=ED=9C=98?= Date: Sun, 30 Jun 2024 16:14:21 +0900 Subject: [PATCH] init: queryDSL --- .../CoffeeChat/config/CorsMvcConfig.java | 2 +- .../CoffeeChat/dto/CreateMentorRequest.java | 2 + .../CoffeeChat/entity/Application.java | 8 +- .../soongsil/CoffeeChat/entity/Mentee.java | 3 +- .../soongsil/CoffeeChat/entity/Mentor.java | 4 +- .../CoffeeChat/entity/PossibleDate.java | 7 +- .../com/soongsil/CoffeeChat/entity/User.java | 2 +- .../CoffeeChatApplicationTests.java | 2 +- .../CoffeeChat/Mentor/MentorSaveTest.java | 99 +++++++++++++++++++ 9 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 src/test/java/com/soongsil/CoffeeChat/Mentor/MentorSaveTest.java diff --git a/src/main/java/com/soongsil/CoffeeChat/config/CorsMvcConfig.java b/src/main/java/com/soongsil/CoffeeChat/config/CorsMvcConfig.java index d6e87ef..e068149 100644 --- a/src/main/java/com/soongsil/CoffeeChat/config/CorsMvcConfig.java +++ b/src/main/java/com/soongsil/CoffeeChat/config/CorsMvcConfig.java @@ -16,7 +16,7 @@ public void addCorsMappings(CorsRegistry corsRegistry) { corsRegistry.addMapping("/**") //모든 경로에서 매핑 진행 .exposedHeaders("Set-Cookie") //노출할 헤더값은 쿠키헤더 - .allowedOrigins("https://localhost:3000", "https://cogo.life", "https://coffeego-ssu.web.app") + .allowedOrigins("https://localhost:3000", "https://cogo.life", "https://coffeego-ssu.web.app", "http://localhost:8080") .allowedMethods("OPTIONS", "GET", "POST", "PUT", "DELETE") .allowedHeaders("*") .allowCredentials(true) diff --git a/src/main/java/com/soongsil/CoffeeChat/dto/CreateMentorRequest.java b/src/main/java/com/soongsil/CoffeeChat/dto/CreateMentorRequest.java index c9faaad..7f2a6e4 100644 --- a/src/main/java/com/soongsil/CoffeeChat/dto/CreateMentorRequest.java +++ b/src/main/java/com/soongsil/CoffeeChat/dto/CreateMentorRequest.java @@ -1,8 +1,10 @@ package com.soongsil.CoffeeChat.dto; import lombok.Getter; +import lombok.Setter; @Getter +@Setter public class CreateMentorRequest { private String phoneNum; private String birth; diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/Application.java b/src/main/java/com/soongsil/CoffeeChat/entity/Application.java index 78e71eb..ea5a4d8 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/Application.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/Application.java @@ -3,6 +3,7 @@ import java.time.LocalDate; import java.time.LocalTime; +import lombok.*; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -17,17 +18,12 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Getter @Setter @Builder -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @DynamicInsert @DynamicUpdate diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/Mentee.java b/src/main/java/com/soongsil/CoffeeChat/entity/Mentee.java index 2f144e9..89c49d9 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/Mentee.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/Mentee.java @@ -12,12 +12,13 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; @Entity -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Builder public class Mentee { diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java b/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java index 2748d88..3718c6e 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java @@ -17,11 +17,12 @@ import lombok.*; @Entity -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Builder @Getter @Setter +@ToString(of = {"id", "picture", "part"}) //@DiscriminatorValue("mentor") //@PrimaryKeyJoinColumn(name = "mentor_id") public class Mentor { @@ -32,7 +33,6 @@ public class Mentor { @Column private String picture; - //TODO: aws파지면 사진처리 해줘야됨 @Column(name = "phone_num") private String phoneNum; diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/PossibleDate.java b/src/main/java/com/soongsil/CoffeeChat/entity/PossibleDate.java index d865200..9076e1a 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/PossibleDate.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/PossibleDate.java @@ -13,17 +13,14 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; @Entity @Builder @NoArgsConstructor @AllArgsConstructor @Getter +@ToString(of = {"id", "date", "startTime", "endTime", "apply"}) public class PossibleDate { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/User.java b/src/main/java/com/soongsil/CoffeeChat/entity/User.java index 86f23b5..5afdc40 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/User.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/User.java @@ -7,7 +7,7 @@ @Entity @Getter @Setter -@Table(name = "user_table") +@Table //@Inheritance(strategy = InheritanceType.JOINED) //자식 : Mentor, Mentee //@DiscriminatorColumn // 하위 테이블의 구분 컬럼 생성(default = DTYPE) public class User { diff --git a/src/test/java/com/soongsil/CoffeeChat/CoffeeChatApplicationTests.java b/src/test/java/com/soongsil/CoffeeChat/CoffeeChatApplicationTests.java index 1212bc0..6ab1c08 100644 --- a/src/test/java/com/soongsil/CoffeeChat/CoffeeChatApplicationTests.java +++ b/src/test/java/com/soongsil/CoffeeChat/CoffeeChatApplicationTests.java @@ -9,7 +9,7 @@ import com.soongsil.CoffeeChat.entity.*; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; + import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/soongsil/CoffeeChat/Mentor/MentorSaveTest.java b/src/test/java/com/soongsil/CoffeeChat/Mentor/MentorSaveTest.java new file mode 100644 index 0000000..e104bc8 --- /dev/null +++ b/src/test/java/com/soongsil/CoffeeChat/Mentor/MentorSaveTest.java @@ -0,0 +1,99 @@ +package com.soongsil.CoffeeChat.Mentor; + +import com.soongsil.CoffeeChat.dto.CreateMentorRequest; +import com.soongsil.CoffeeChat.entity.Mentor; +import com.soongsil.CoffeeChat.entity.PossibleDate; +import com.soongsil.CoffeeChat.entity.User; +import com.soongsil.CoffeeChat.repository.MentorRepository; +import com.soongsil.CoffeeChat.repository.PossibleDateRepository; +import com.soongsil.CoffeeChat.repository.UserRepository; +import com.soongsil.CoffeeChat.service.UserService; +import jakarta.transaction.Transactional; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Commit; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Optional; +import java.util.stream.IntStream; +import java.util.stream.LongStream; + +@SpringBootTest +@Transactional +@Commit +public class MentorSaveTest { + @Autowired + private MentorRepository mentorRepository; + @Autowired + private PossibleDateRepository possibleDateRepository; + @Autowired + private UserRepository userRepository; + @Autowired + private UserService userService; + + @Test + public void testCreate500UsersWithMentors() { + IntStream.range(0, 500).forEach(i -> { + String username = "user" + i; + // User 객체 생성 + User user = new User(); + user.setUsername(username); + user.setRole("ROLE_USER"); // 초기 역할 설정 + + // User 객체 저장 + userRepository.save(user); + + // CreateMentorRequest DTO 생성 + CreateMentorRequest mentorRequest = new CreateMentorRequest(); + mentorRequest.setPhoneNum("010-0000-000" + i); + mentorRequest.setBirth("1990-01-01"); + mentorRequest.setPart("BE"); + + // saveMentorInformation 메소드 호출 + userService.saveMentorInformation(username, mentorRequest); + }); + + // 사용자와 멘토 생성 확인 + long userCount = userRepository.count(); + assert(userCount == 500); + } + + + //멘토 500개생성 + @Test + public void add500Mentors() { + IntStream.range(0, 500).forEach(i -> { + Mentor mentor = Mentor.builder() + .phoneNum("010-1234-" + String.format("%04d", i)) + .birth("1990-01-01") + .part("BE") + .build(); + mentorRepository.save(mentor); + }); + } + + @Test + @Transactional + public void addPossibleDatesForMentors() { + LongStream.range(1, 501).forEach(mentorId -> { + Optional mentorOptional = mentorRepository.findById(mentorId); + if (mentorOptional.isPresent()) { + Mentor mentor = mentorOptional.get(); + for (int i = 0; i < 3; i++) { + PossibleDate possibleDate = PossibleDate.builder() + .mentor(mentor) + .date(LocalDate.now().plusDays(i)) + .startTime(LocalTime.of(10, 0).plusHours(i)) + .endTime(LocalTime.of(11, 0).plusHours(i)) + .apply(false) + .build(); + possibleDateRepository.save(possibleDate); + } + } + }); + } + + +}