Skip to content

Commit

Permalink
Merge pull request #171 from Funssion-SWM/employer
Browse files Browse the repository at this point in the history
feat: employee 조회 리스트 api
  • Loading branch information
goathoon authored Nov 3, 2023
2 parents 016d988 + 88bf2fa commit 5dce321
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 117 deletions.
3 changes: 1 addition & 2 deletions src/main/java/Funssion/Inforum/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import Funssion.Inforum.access_handler.JwtAccessDeniedHandler;
import Funssion.Inforum.access_handler.JwtAuthenticationEntryPoint;
import Funssion.Inforum.access_handler.NonSocialLoginFailureHandler;
import Funssion.Inforum.common.constant.Role;
import Funssion.Inforum.domain.member.service.OAuthService;
import Funssion.Inforum.jwt.JwtSecurityConfig;
import Funssion.Inforum.jwt.TokenProvider;
Expand All @@ -28,7 +27,7 @@

import java.util.Arrays;

import static Funssion.Inforum.common.constant.Role.*;
import static Funssion.Inforum.common.constant.Role.EMPLOYER;

@Slf4j
@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package Funssion.Inforum.domain.employer.controller;

import Funssion.Inforum.common.dto.IsSuccessResponseDto;
import Funssion.Inforum.domain.employer.dto.EmployeeDto;
import Funssion.Inforum.domain.employer.domain.Employee;
import Funssion.Inforum.domain.employer.domain.EmployeeWithStatus;
import Funssion.Inforum.domain.employer.domain.InterviewResult;
import Funssion.Inforum.domain.employer.service.EmployerService;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

Expand All @@ -14,10 +15,21 @@
@RequiredArgsConstructor
public class EmployerController {
private final EmployerService employerService;

@GetMapping("/employees")
public List<EmployeeDto> getEmployeesLookingForJob(@RequestParam(required = false, defaultValue = "0") @Min(0) Long page){
return employerService.getEmployeesLookingForJob(page);
public List<Employee> getEmployeesListOfInterview(@RequestParam Boolean done){
return employerService.getEmployeesOfInterview(done);
}
@GetMapping("/interview-result/{employeeId}")
public InterviewResult getResultOfInterview(@PathVariable Long employeeId){
return employerService.getResultOfInterview(employeeId);
}

@GetMapping("/like/employees")
public List<EmployeeWithStatus> getLikeEmployees(){
return employerService.getLikeEmployees();
}

@PostMapping("/like/{userId}")
public IsSuccessResponseDto likeEmployee(@PathVariable Long userId){
employerService.likeEmployee(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class Employee {
private final String username;
private final String imagePath;
private final String rank;
private final Long score;
private final Boolean isLike;
private final String introduce;
private final String developmentArea;
private final String description;
private final String techStack;
private final Boolean isVisible;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Funssion.Inforum.domain.employer.domain;

import Funssion.Inforum.domain.interview.constant.InterviewStatus;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
@Builder
public class EmployeeWithStatus {
private final Long userId;
private final String username;
private final String imagePath;
private final String rank;
private final String introduce;
private final String developmentArea;
private final String description;
private final String techStack;
private final Boolean isVisible;
private final InterviewStatus status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Funssion.Inforum.domain.employer.domain;

import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@Builder
@RequiredArgsConstructor
public class InterviewResult {
private final String question1;
private final String answer1;
private final String question2;
private final String answer2;
private final String question3;
private final String answer3;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.employer.domain.Employee;
import Funssion.Inforum.domain.employer.domain.EmployeeWithStatus;
import Funssion.Inforum.domain.employer.domain.InterviewResult;
import Funssion.Inforum.domain.employer.dto.EmployerLikesEmployee;
import Funssion.Inforum.domain.employer.dto.EmployerProfile;
import Funssion.Inforum.domain.employer.dto.EmployerUnlikesEmployee;
import Funssion.Inforum.domain.interview.constant.InterviewStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
Expand All @@ -19,6 +22,58 @@ public EmployerRepository(DataSource dataSource){
this.template = new JdbcTemplate(dataSource);
}

public List<Employee> getInterviewEmployees(Boolean isDone){
Long employerId = SecurityContextUtils.getAuthorizedUserId();
String sql =
"SELECT U.id, U.name, U.image_path, U.rank, EMP.introduce, EMP.development_area, EMP.description, jsonb_array_elements(EMP.tech_stack) AS tech_stack, EMP.is_visible " +
"FROM member.info U, member.professional_profile EMP " +
"WHERE U.id = EMP.user_id " +
"AND (SELECT status " +
"FROM interview.info " +
"WHERE employer_id = ? AND employee_id = U.id) ";
sql += isDone
? " = "
: " != " ;
sql += "'DONE'";
return template.query(sql,employeeListRowMapper(),employerId);
}


public List<EmployeeWithStatus> getLikeEmployees() {
Long employerId = SecurityContextUtils.getAuthorizedUserId();
String sql =
"SELECT U.id, U.name, U.image_path, U.rank, EMP.introduce, EMP.development_area, EMP.description, jsonb_array_elements(EMP.tech_stack) AS tech_stack, EMP.is_visible, INTER.status " +
"FROM member.info U " +
"INNER JOIN member.professional_profile EMP " +
"ON U.id = EMP.user_id " +
"LEFT JOIN interview.info INTER " +
"ON INTER.employee_id = U.id " +
"INNER JOIN employer.to_employee L " +
"ON L.employer_id = ? and L.employee_id = U.id ";
return template.query(sql,employeeWithStatusListRowMapper(),employerId);
}

public InterviewResult getInterviewResultOf(Long userId){
Long employerId = SecurityContextUtils.getAuthorizedUserId();
String sql =
"SELECT question_1, answer_1, question_2, answer_2, question_3, answer_3 " +
"FROM interview.info " +
"WHERE employee_id = ? and employer_id = ?";
return template.queryForObject(sql, interviewReulstRowMapper(),userId,employerId);
}

private RowMapper<InterviewResult> interviewReulstRowMapper() {
return (rs,rowNum) ->
InterviewResult.builder()
.question1(rs.getString("question_1"))
.answer1(rs.getString("answer_1"))
.question2(rs.getString("question_2"))
.answer2(rs.getString("answer_2"))
.question3(rs.getString("question_3"))
.answer3(rs.getString("answer_3"))
.build();
}

public EmployerProfile getEmployerProfile(Long employerId){
String sql =
"SELECT id, company, name, image_path,rank " +
Expand All @@ -37,27 +92,7 @@ private RowMapper<EmployerProfile> EmployerProfileRowMapper() {
.rank(rs.getString("rank"))
.build();
}
public List<Employee> getEmployeesLookingForJob(Long page){
String sql =
"SELECT MEM.id, MEM.name, MEM.image_path, MEM.rank, MEM.score, " +
"CASE WHEN EMPLOYER_LIKE.employee_id IS NOT NULL THEN 'true' ELSE 'false' END AS i_like " +
"FROM member.info MEM " +
"JOIN (" +
"SELECT user_id " +
"FROM member.professional_profile " +
"WHERE is_visible = true" +
") EMP " +
"ON MEM.id = EMP.user_id " +
"LEFT JOIN (" +
"SELECT employee_id " +
"FROM employer.to_employee " +
"WHERE employer_id = ?" +
") EMPLOYER_LIKE " +
"ON MEM.id = EMPLOYER_LIKE.employee_id " +
"ORDER BY MEM.score DESC " +
"LIMIT 5 OFFSET (? * 5)";
return template.query(sql,employeeListRowMapper(), SecurityContextUtils.getUserId(),page);
}


public EmployerLikesEmployee likeEmployee(Long userId){
Long employerId = SecurityContextUtils.getAuthorizedUserId();
Expand Down Expand Up @@ -92,8 +127,27 @@ private RowMapper<Employee> employeeListRowMapper(){
.username(rs.getString("name"))
.imagePath(rs.getString("image_path"))
.rank(rs.getString("rank"))
.score(rs.getLong("score"))
.isLike(rs.getBoolean("i_like"))
.developmentArea(rs.getString("development_area"))
.introduce(rs.getString("introduce"))
.techStack(rs.getString("tech_stack"))
.description(rs.getString("description"))
.isVisible(rs.getBoolean("is_visible"))
.build();
}

private RowMapper<EmployeeWithStatus> employeeWithStatusListRowMapper(){
return (rs,rowNum) ->
EmployeeWithStatus.builder()
.userId(rs.getLong("id"))
.username(rs.getString("name"))
.imagePath(rs.getString("image_path"))
.rank(rs.getString("rank"))
.developmentArea(rs.getString("development_area"))
.introduce(rs.getString("introduce"))
.techStack(rs.getString("tech_stack"))
.description(rs.getString("description"))
.isVisible(rs.getBoolean("is_visible"))
.status(InterviewStatus.nullableValueOf(rs.getString("status")))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,32 @@

import Funssion.Inforum.common.exception.badrequest.BadRequestException;
import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.employer.dto.EmployeeDto;
import Funssion.Inforum.domain.employer.domain.Employee;
import Funssion.Inforum.domain.employer.domain.EmployeeWithStatus;
import Funssion.Inforum.domain.employer.domain.InterviewResult;
import Funssion.Inforum.domain.employer.dto.EmployerLikesEmployee;
import Funssion.Inforum.domain.employer.dto.EmployerProfile;
import Funssion.Inforum.domain.employer.dto.EmployerUnlikesEmployee;
import Funssion.Inforum.domain.employer.repository.EmployerRepository;
import Funssion.Inforum.domain.interview.constant.InterviewStatus;
import Funssion.Inforum.domain.interview.repository.InterviewRepository;
import Funssion.Inforum.domain.notification.domain.Notification;
import Funssion.Inforum.domain.notification.repository.NotificationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

import static Funssion.Inforum.common.constant.NotificationType.NEW_EMPLOYER;

@Service
@RequiredArgsConstructor
public class EmployerService {
private final EmployerRepository employerRepository;
private final InterviewRepository interviewRepository;
private final NotificationRepository notificationRepository;

@Transactional(readOnly = true)
public List<EmployeeDto> getEmployeesLookingForJob(Long page){
return employerRepository.getEmployeesLookingForJob(page)
.stream()
.map(employee -> new EmployeeDto(employee))
.collect(Collectors.toList());
}
@Transactional
public EmployerLikesEmployee likeEmployee(Long employeeId){
Long employerId = SecurityContextUtils.getAuthorizedUserId();
Expand Down Expand Up @@ -64,4 +61,19 @@ public EmployerUnlikesEmployee unlikesEmployee(Long employeeId){

}

public List<Employee> getEmployeesOfInterview(Boolean done) {
return employerRepository.getInterviewEmployees(done);
}

public InterviewResult getResultOfInterview(Long employeeId){
Long employerId = SecurityContextUtils.getAuthorizedUserId();
if(!interviewRepository.getInterviewStatusOfUser(employerId, employeeId).getStatus().equals(InterviewStatus.DONE.toString()))
throw new BadRequestException("면접이 완료되지 않은 지원자입니다.");

return employerRepository.getInterviewResultOf(employeeId);
}

public List<EmployeeWithStatus> getLikeEmployees() {
return employerRepository.getLikeEmployees();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ public enum InterviewStatus {
DONE("면접이 완료 되었습니다.");
private final String status;

public static InterviewStatus nullableValueOf(String name){
if (name == null) {
return null;
}
try {
return InterviewStatus.valueOf(name);
} catch (IllegalArgumentException e) {
return null; // Enum 상수가 존재하지 않는 경우 null 반환
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public List<UserProfileForEmployer> findUserProfilesForEmployer(TechStackDto tec
paramList.add(techStackDto.getDevelopmentArea());
String sql = "SELECT *, CASE WHEN EMPLOYER_LIKE.employee_id IS NOT NULL THEN 'true' ELSE 'false' END AS i_like " +
"FROM (" +
" SELECT m.id, m.name, m.image_path, m.rank, p.introduce, p.development_area, p.tech_stack, p.description, (" +
" SELECT m.id, m.name, m.image_path, m.rank, p.introduce, p.development_area, jsonp.tech_stack, p.description, (" +
" SELECT 2*count(stack_element)" +
" FROM jsonb_array_elements(p.tech_stack) AS stack_element" +
" WHERE p.development_area = ? AND stack_element->>'stack' in " + techStackElements(techStackDto.getTechStacks(), paramList) +
Expand Down
Loading

0 comments on commit 5dce321

Please sign in to comment.