Skip to content

Commit

Permalink
init: queryDSL
Browse files Browse the repository at this point in the history
  • Loading branch information
김교휘 authored and 김교휘 committed Jun 30, 2024
1 parent efcb11c commit 7c1e15a
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/soongsil/CoffeeChat/entity/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;
import java.time.LocalTime;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/soongsil/CoffeeChat/entity/Mentee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,7 +33,6 @@ public class Mentor {

@Column
private String picture;
//TODO: aws파지면 사진처리 해줘야됨

@Column(name = "phone_num")
private String phoneNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/soongsil/CoffeeChat/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Entity
@Getter
@Setter
@Table(name = "user_table")
@Table
//@Inheritance(strategy = InheritanceType.JOINED) //자식 : Mentor, Mentee
//@DiscriminatorColumn // 하위 테이블의 구분 컬럼 생성(default = DTYPE)
public class User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
99 changes: 99 additions & 0 deletions src/test/java/com/soongsil/CoffeeChat/Mentor/MentorSaveTest.java
Original file line number Diff line number Diff line change
@@ -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<Mentor> 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);
}
}
});
}


}

0 comments on commit 7c1e15a

Please sign in to comment.