Skip to content

Commit

Permalink
Merge pull request #136 from kakao-tech-campus-2nd-step3/Develop
Browse files Browse the repository at this point in the history
[Master] ํ…Œ์ŠคํŠธ์ฝ”๋“œ ์ˆ˜์ •
  • Loading branch information
minsu-cnu authored Nov 11, 2024
2 parents b8ca305 + 7513d27 commit 8d8c80e
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import team18.team18_be.recruitment.dto.response.RecruitmentAllResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentResponseForCompany;
import team18.team18_be.recruitment.dto.response.RecruitmentSummationResponse;
import team18.team18_be.recruitment.service.RecruitmentService;

@Tag(name = "๊ตฌ์ธ๊ธ€ ๊ด€๋ จ Controller")
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/team18/team18_be/recruitment/entity/Recruitment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.validation.constraints.NotNull;
import java.util.Date;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -20,28 +21,48 @@ public class Recruitment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long recruitmentId;
@NotNull
private String koreanTitle;
@NotNull
private String vietnameseTitle;
@NotNull
private String companySize;
@NotNull
private String area;
@NotNull
private Long salary;
@NotNull
private String workDuration;
@NotNull
private String workDays;
@NotNull
private String workType;
@NotNull
private String workHours;
@NotNull
private String requestedCareer;
@NotNull
private String majorBusiness;
@NotNull
private String eligibilityCriteria;
@NotNull
private String preferredConditions;
@NotNull
private String employerName;
@NotNull
private String companyName;
@NotNull
private Boolean hiring;
@NotNull
private Date uploadDate;

@ManyToOne
@JoinColumn(name = "companyId")
@NotNull
private Company company;

@OneToOne
@NotNull
private RecruitmentContent recruitmentContent;

public Recruitment(String koreanTitle, String vietnameseTitle, String companySize, String area,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.validation.constraints.NotNull;

@Entity
public class RecruitmentContent {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull
private Long resumeContentId;
@Lob
@Column(columnDefinition = "TEXT")
@NotNull
private String koreanDetailedDescription;
@Lob
@Column(columnDefinition = "TEXT")
@NotNull
private String vietnameseDetailedDescription;

public RecruitmentContent(String koreanDetailedDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public RecruitmentService(RecruitmentRepository recruitmentRepository,
this.recruitmentMapper = recruitmentMapper;
}

public void saveRecruitment(RecruitmentRequest recruitmentRequest)
public Long saveRecruitment(RecruitmentRequest recruitmentRequest)
throws JsonProcessingException {
String koreanTitle = recruitmentRequest.title();
String vietnameseTitle = openAiService.translateKoreanToVietnamese(koreanTitle);
Expand All @@ -51,12 +51,12 @@ public void saveRecruitment(RecruitmentRequest recruitmentRequest)
koreanDetailedDescription);
RecruitmentContent recruitmentContent = recruitmentContentRepository.save(
new RecruitmentContent(koreanDetailedDescription, vietnameseDetailedDescription));
recruitmentRepository.save(
return recruitmentRepository.save(
recruitmentMapper.toRecruitment(koreanTitle, vietnameseTitle, recruitmentRequest,
recruitmentContent, companyRepository.findById(recruitmentRequest.companyId())
.orElseThrow(() -> new NoSuchElementException("ํ•ด๋‹นํ•˜๋Š” ํšŒ์‚ฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")), true,
new Date()
));
)).getRecruitmentId();

}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/team18/team18_be/resume/entity/Resume.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import team18.team18_be.auth.entity.User;
Expand All @@ -20,17 +21,24 @@ public class Resume {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long resumeId;
@NotNull
private String applicantName;
@NotNull
private String address;
@NotNull
private String phoneNumber;
@NotNull
private String career;
@NotNull
private String korean;
@Lob
@Column(columnDefinition = "TEXT")
@NotNull
private String selfIntroduction;

@ManyToOne
@JoinColumn(name = "userId")
@NotNull
private User user;

public Resume(String applicantName, String address, String phoneNumber, String career,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public ResumeService(ResumeRepository resumeRepository,
this.applicationFormRepository = applicationFormRepository;
}

public void saveResume(ResumeRequest resumeRequest, User user) {
resumeRepository.save(resumeMapper.toResume(resumeRequest, user));
public Long saveResume(ResumeRequest resumeRequest, User user) {
return resumeRepository.save(resumeMapper.toResume(resumeRequest, user)).getResumeId();
}

public ResumeResponse findResumeByEmployee(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.transaction.Transactional;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,6 +16,7 @@
import team18.team18_be.auth.entity.User;
import team18.team18_be.auth.repository.AuthRepository;
import team18.team18_be.recruitment.dto.request.RecruitmentRequest;
import team18.team18_be.recruitment.dto.response.RecruitmentAllResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentSummationResponse;
import team18.team18_be.recruitment.entity.Recruitment;
import team18.team18_be.recruitment.repository.RecruitmentRepository;
Expand All @@ -23,11 +25,18 @@
import team18.team18_be.userInformation.repository.CompanyRepository;

@SpringBootTest(classes = Team18BeApplication.class)
@Transactional
public class RecruitmentServiceTest {

static final String NAME = "name";
static final String EMAIL = "email";

public static Long companyId;
public static Long firstRecruitmentId;
public static Long secondRecruitmentId;
public static Long thirdRecruitmentId;



@Autowired
RecruitmentRepository recruitmentRepository;
@Autowired
Expand All @@ -37,92 +46,63 @@ public class RecruitmentServiceTest {
@Autowired
AuthRepository authRepository;

@Test
@Transactional
@DisplayName("๊ตฌ์ธ๊ธ€ ์ €์žฅ")
public void saveRecruitmentTest() throws JsonProcessingException {
@BeforeEach
public void setup() throws JsonProcessingException {
User user = new User(NAME, EMAIL, "first");
Company company = new Company("MyCompany", "Tech", "MyBrand", 1000000L, "image", user);
companyRepository.save(company);

recruitmentService.saveRecruitment(
new RecruitmentRequest("๋ง›์žˆ๋Š” ๋ฐฅ์ƒ์—์„œ ์•„๋ฅด๋ฐ”์ดํŠธ๋ฅผ ๋ชจ์ง‘ํ•ฉ๋‹ˆ๋‹ค.", "50๋ช… ์ด์ƒ์˜ ์ง์›", "์„œ์šธ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
70000000L, "์ •๊ทœ์ง", "์ฃผ 5์ผ", "์ƒ๊ทผ", "์˜ค์ „ 10์‹œ๋ถ€ํ„ฐ ์˜คํ›„ 7์‹œ๊นŒ์ง€",
"๊ฒฝ๋ ฅ 5๋…„ ์ด์ƒ", "ํ•œ์‹ ๋ ˆ์Šคํ† ๋ž‘", "์š”๋ฆฌ ๊ด€๋ จ ์ „๊ณต ๋˜๋Š” ๊ฒฝ๋ ฅ",
"ํŒ€์›Œํฌ ๋ฐ ๋ฆฌ๋”์‹ญ ๊ฒฝํ—˜", "๋ฐ•์ •ํ˜ธ", "๋ง›์žˆ๋Š” ํ•œ์ƒ", 1L));
Recruitment recruitment = recruitmentRepository.findById(1L).get();
assertThat(recruitment.getArea()).isEqualTo("์„œ์šธ, ๋Œ€ํ•œ๋ฏผ๊ตญ");
}

@Test
@Transactional
@DisplayName("๊ตฌ์ธ๊ธ€ ์ „์ฒด์กฐํšŒ")
public void findAllRecruitmentTest() throws JsonProcessingException {
User user = new User(NAME, EMAIL, "first");
Company company = new Company("MyCompany", "Tech", "MyBrand", 1000000L, "image", user);
companyRepository.save(company);
authRepository.save(user);
Company company = new Company("MyCompany", "Tech", "MyBrand", 1000000L, "image", user);
companyId = companyRepository.save(company).getId();

recruitmentService.saveRecruitment(new RecruitmentRequest(
firstRecruitmentId = recruitmentService.saveRecruitment(new RecruitmentRequest(
"์ดˆ๋ณด์ž๋ฅผ ์œ„ํ•œ ์š”๋ฆฌ์‚ฌ ๋ชจ์ง‘", "30๋ช… ์ด์ƒ์˜ ์ง์›", "์ œ์ฃผ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
25000000L, "๊ณ„์•ฝ์ง", "์ฃผ 6์ผ", "ํŒŒํŠธํƒ€์ž„", "์˜ค์ „ 7์‹œ๋ถ€ํ„ฐ ์˜คํ›„ 3์‹œ๊นŒ์ง€",
"๊ฒฝ๋ ฅ 1๋…„ ์ด์ƒ", "์ง€์—ญ ๋ง›์ง‘", "์š”๋ฆฌ ๊ด€๋ จ ์ž๊ฒฉ์ฆ ์†Œ์ง€์ž ์šฐ๋Œ€",
"ํŒ€์›Œํฌ์™€ ์„ฑ์‹คํ•จ", "์ •ํ•˜์œค", "์ œ์ฃผ ๋ง›์ง‘", 1L));
"ํŒ€์›Œํฌ์™€ ์„ฑ์‹คํ•จ", "์ •ํ•˜์œค", "์ œ์ฃผ ๋ง›์ง‘", companyId));

recruitmentService.saveRecruitment(new RecruitmentRequest(
secondRecruitmentId = recruitmentService.saveRecruitment(new RecruitmentRequest(
"ํ”„๋ฆฌ๋žœ์„œ ์›น ๊ฐœ๋ฐœ์ž ๋ชจ์ง‘", "10๋ช… ์ดํ•˜์˜ ์ง์›", "์„œ์šธ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
100000000L, "ํ”„๋ฆฌ๋žœ์„œ", "์ฃผ 3์ผ", "์›๊ฒฉ ๊ทผ๋ฌด", "์œ ์—ฐํ•œ ๊ทผ๋ฌด ์‹œ๊ฐ„",
"๊ฒฝ๋ ฅ 7๋…„ ์ด์ƒ", "์Šคํƒ€ํŠธ์—…", "ํ’€์Šคํƒ ๊ฐœ๋ฐœ ๊ฒฝํ—˜ ํ•„์ˆ˜",
"๋ฌธ์ œ ํ•ด๊ฒฐ ๋Šฅ๋ ฅ ๋ฐ ์ฃผ๋„์„ฑ", "๊น€์žฌํ›ˆ", "ํ…Œํฌ์ด๋…ธ๋ฒ ์ด์…˜", 1L));
"๋ฌธ์ œ ํ•ด๊ฒฐ ๋Šฅ๋ ฅ ๋ฐ ์ฃผ๋„์„ฑ", "๊น€์žฌํ›ˆ", "ํ…Œํฌ์ด๋…ธ๋ฒ ์ด์…˜", companyId));

recruitmentService.saveRecruitment(new RecruitmentRequest(
thirdRecruitmentId = recruitmentService.saveRecruitment(new RecruitmentRequest(
"ํ•ด์™ธ ์˜์—… ์ „๋ฌธ๊ฐ€ ๋ชจ์ง‘", "200๋ช… ์ด์ƒ์˜ ์ง์›", "๋ถ€์‚ฐ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
120000000L, "์ •๊ทœ์ง", "์ฃผ 5์ผ", "์ƒ๊ทผ", "์˜ค์ „ 8์‹œ๋ถ€ํ„ฐ ์˜คํ›„ 5์‹œ๊นŒ์ง€",
"๊ฒฝ๋ ฅ 10๋…„ ์ด์ƒ", "๋ฌด์—ญ ํšŒ์‚ฌ", "๊ตญ์ œ ๋ฌด์—ญ ๋ฐ ์˜์—… ๊ด€๋ จ ์ „๊ณต",
"์˜์–ด ๋Šฅํ†ต ๋ฐ ํ˜‘์ƒ ๊ธฐ์ˆ ", "์ด๋ฏผํ˜ธ", "๊ธ€๋กœ๋ฒŒ ํŠธ๋ ˆ์ด๋“œ", 1L));
"์˜์–ด ๋Šฅํ†ต ๋ฐ ํ˜‘์ƒ ๊ธฐ์ˆ ", "์ด๋ฏผํ˜ธ", "๊ธ€๋กœ๋ฒŒ ํŠธ๋ ˆ์ด๋“œ", companyId));
}

@Test
@Transactional
@DisplayName("๊ตฌ์ธ๊ธ€ ์ €์žฅ")
public void saveRecruitmentTest() {
Recruitment recruitment = recruitmentRepository.findById(firstRecruitmentId).get();
assertThat(recruitment.getArea()).isEqualTo("์ œ์ฃผ, ๋Œ€ํ•œ๋ฏผ๊ตญ");
}

@Test
@Transactional
@DisplayName("๊ตฌ์ธ๊ธ€ ์ „์ฒด์กฐํšŒ")
public void findAllRecruitmentTest(){
Pageable pageable = PageRequest.of(0, 5);

List<RecruitmentSummationResponse> recruitmentSummationResponseList = recruitmentService.getAllRecruitment(
RecruitmentAllResponse recruitmentAllResponse = recruitmentService.getAllRecruitment(
pageable);
assertThat(recruitmentSummationResponseList.size()).isEqualTo(3);
assertThat(recruitmentAllResponse.content().size()).isEqualTo(3);
}

@Test
@Transactional
@DisplayName("๊ตฌ์ธ๊ธ€ ๊ธ‰์—ฌ ์ˆœ์„œ๋Œ€๋กœ ์ „์ฒด์กฐํšŒ")
public void findAllRecruitmentBySalaryTest() throws JsonProcessingException {
User user = new User(NAME, EMAIL, "first");
Company company = new Company("MyCompany", "Tech", "MyBrand", 1000000L, "image", user);
companyRepository.save(company);
authRepository.save(user);

recruitmentService.saveRecruitment(new RecruitmentRequest(
"์ดˆ๋ณด์ž๋ฅผ ์œ„ํ•œ ์š”๋ฆฌ์‚ฌ ๋ชจ์ง‘", "30๋ช… ์ด์ƒ์˜ ์ง์›", "์ œ์ฃผ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
25000000L, "๊ณ„์•ฝ์ง", "์ฃผ 6์ผ", "ํŒŒํŠธํƒ€์ž„", "์˜ค์ „ 7์‹œ๋ถ€ํ„ฐ ์˜คํ›„ 3์‹œ๊นŒ์ง€",
"๊ฒฝ๋ ฅ 1๋…„ ์ด์ƒ", "์ง€์—ญ ๋ง›์ง‘", "์š”๋ฆฌ ๊ด€๋ จ ์ž๊ฒฉ์ฆ ์†Œ์ง€์ž ์šฐ๋Œ€",
"ํŒ€์›Œํฌ์™€ ์„ฑ์‹คํ•จ", "์ •ํ•˜์œค", "์ œ์ฃผ ๋ง›์ง‘", 1L));

recruitmentService.saveRecruitment(new RecruitmentRequest(
"ํ”„๋ฆฌ๋žœ์„œ ์›น ๊ฐœ๋ฐœ์ž ๋ชจ์ง‘", "10๋ช… ์ดํ•˜์˜ ์ง์›", "์„œ์šธ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
100000000L, "ํ”„๋ฆฌ๋žœ์„œ", "์ฃผ 3์ผ", "์›๊ฒฉ ๊ทผ๋ฌด", "์œ ์—ฐํ•œ ๊ทผ๋ฌด ์‹œ๊ฐ„",
"๊ฒฝ๋ ฅ 7๋…„ ์ด์ƒ", "์Šคํƒ€ํŠธ์—…", "ํ’€์Šคํƒ ๊ฐœ๋ฐœ ๊ฒฝํ—˜ ํ•„์ˆ˜",
"๋ฌธ์ œ ํ•ด๊ฒฐ ๋Šฅ๋ ฅ ๋ฐ ์ฃผ๋„์„ฑ", "๊น€์žฌํ›ˆ", "ํ…Œํฌ์ด๋…ธ๋ฒ ์ด์…˜", 1L));

recruitmentService.saveRecruitment(new RecruitmentRequest(
"ํ•ด์™ธ ์˜์—… ์ „๋ฌธ๊ฐ€ ๋ชจ์ง‘", "200๋ช… ์ด์ƒ์˜ ์ง์›", "๋ถ€์‚ฐ, ๋Œ€ํ•œ๋ฏผ๊ตญ",
120000000L, "์ •๊ทœ์ง", "์ฃผ 5์ผ", "์ƒ๊ทผ", "์˜ค์ „ 8์‹œ๋ถ€ํ„ฐ ์˜คํ›„ 5์‹œ๊นŒ์ง€",
"๊ฒฝ๋ ฅ 10๋…„ ์ด์ƒ", "๋ฌด์—ญ ํšŒ์‚ฌ", "๊ตญ์ œ ๋ฌด์—ญ ๋ฐ ์˜์—… ๊ด€๋ จ ์ „๊ณต",
"์˜์–ด ๋Šฅํ†ต ๋ฐ ํ˜‘์ƒ ๊ธฐ์ˆ ", "์ด๋ฏผํ˜ธ", "๊ธ€๋กœ๋ฒŒ ํŠธ๋ ˆ์ด๋“œ", 1L));

Pageable pageable = PageRequest.of(0, 5);

List<RecruitmentSummationResponse> recruitmentSummationResponseList = recruitmentService.getAllRecruitmentAndSortBySalary(
RecruitmentAllResponse recruitmentAllResponse = recruitmentService.getAllRecruitmentAndSortBySalary(
pageable);

assertThat(recruitmentSummationResponseList.get(0).recruitmentId()).isEqualTo(3L);
assertThat(recruitmentSummationResponseList.get(1).recruitmentId()).isEqualTo(2L);
assertThat(recruitmentSummationResponseList.get(2).recruitmentId()).isEqualTo(1L);
assertThat(recruitmentAllResponse.content().get(0).recruitmentId()).isEqualTo(thirdRecruitmentId);
assertThat(recruitmentAllResponse.content().get(1).recruitmentId()).isEqualTo(secondRecruitmentId);
assertThat(recruitmentAllResponse.content().get(2).recruitmentId()).isEqualTo(firstRecruitmentId);
}

}
Loading

0 comments on commit 8d8c80e

Please sign in to comment.