Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[✨ feat] 직무필터링, 사용자 필터링 정보, 필터링 재설정(직무, 계획) API 구현 #183

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/org/terning/terningserver/domain/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.terning.terningserver.domain.enums.Grade;
import org.terning.terningserver.domain.enums.JobType;
import org.terning.terningserver.domain.enums.WorkingPeriod;
import org.terning.terningserver.dto.auth.request.SignUpFilterRequestDto;

import static lombok.AccessLevel.PROTECTED;
import static jakarta.persistence.GenerationType.IDENTITY;
Expand All @@ -23,6 +23,9 @@ public class Filter {
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
private JobType jobType;

@Enumerated(EnumType.STRING)
private Grade grade;

Expand All @@ -34,7 +37,8 @@ public class Filter {
private int startMonth; // 근무 시작 월


public void updateFilter(Grade grade, WorkingPeriod workingPeriod, int startYear, int startMonth) {
public void updateFilter(JobType jobType, Grade grade, WorkingPeriod workingPeriod, int startYear, int startMonth) {
this.jobType = jobType;
this.grade = grade;
this.workingPeriod = workingPeriod;
this.startYear = startYear;
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/terning/terningserver/domain/enums/JobType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.terning.terningserver.domain.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.terning.terningserver.exception.CustomException;
import org.terning.terningserver.exception.enums.ErrorMessage;

@Getter
@RequiredArgsConstructor
public enum JobType {
TOTAL("total", "전체"),
PLAN("plan", "기획/전략"),
MARKETING("marketing", "마케팅/홍보"),
ADMIN("admin", "사무/회계"),
SALES("sales", "인사/영업"),
DESIGN("design", "디자인/예술"),
IT("it", "개발/IT"),
RESEARCH("research", "연구/생산"),
ETC("etc", "기타");

private final String key;
private final String value;

public static JobType fromKey(String key) {
for (JobType jobType : JobType.values()) {
if (jobType.key.equalsIgnoreCase(key)) {
return jobType;
}
}
throw new CustomException(ErrorMessage.INVALID_JOB_TYPE);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.terning.terningserver.dto.filter.request;

public record UpdateUserFilterRequestDto(
String jobType,
String grade,
String workingPeriod,
int startYear,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

@Builder(access = PRIVATE)
public record UserFilterDetailResponseDto(
String jobType,
String grade,
String workingPeriod,
Integer startYear,
Integer startMonth
) {
public static UserFilterDetailResponseDto of(final Filter userFilter) {
return UserFilterDetailResponseDto.builder()
.grade(userFilter == null ? null : userFilter.getGrade().getKey())
.workingPeriod(userFilter == null ? null : userFilter.getWorkingPeriod().getKey())
.jobType(userFilter == null || userFilter.getJobType() == null ? "total" : userFilter.getJobType().getKey())
.grade(userFilter == null || userFilter.getGrade() == null ? null : userFilter.getGrade().getKey())
.workingPeriod(userFilter == null || userFilter.getWorkingPeriod() == null ? null : userFilter.getWorkingPeriod().getKey())
.startYear(userFilter == null ? null : userFilter.getStartYear())
.startMonth(userFilter == null ? null : userFilter.getStartMonth())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public enum ErrorMessage {
FAILED_TOKEN_REISSUE(404, "토큰 재발급에 실패하였습니다"),
UNAUTHORIZED_JWT_EXCEPTION(401, "유효하지 않은 토큰입니다"),

// 사용자 필터링 정보 생성
// 필터링
FAILED_SIGN_UP_USER_FILTER_CREATION(404, "사용자 필터 생성에 실패하였습니다"),
FAILED_SIGN_UP_USER_FILTER_ASSIGNMENT(404, "사용자 필터 연결에 실패하였습니다"),
INVALID_JOB_TYPE(401, "유효하지 않은 직무 카테고리입니다."),

// 스크랩
EXISTS_SCRAP_ALREADY(400, "이미 스크랩했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.data.support.PageableExecutionUtils;
import org.terning.terningserver.domain.InternshipAnnouncement;
import org.terning.terningserver.domain.enums.Grade;
import org.terning.terningserver.domain.enums.JobType;
import org.terning.terningserver.domain.enums.WorkingPeriod;


Expand Down Expand Up @@ -115,6 +116,7 @@ public List<Tuple> findFilteredInternshipsWithScrapInfo(User user, String sortBy
.from(internshipAnnouncement)
.leftJoin(internshipAnnouncement.scraps, scrap).on(scrap.user.eq(user))
.where(
getJobTypeFilter(user),
getGraduatingFilter(user),
getWorkingPeriodFilter(user),
getStartDateFilter(user)
Expand Down Expand Up @@ -199,4 +201,11 @@ private NumberTemplate<Integer> sortAnnouncementsByDeadline() {
isNotExpired
);
}

private BooleanExpression getJobTypeFilter(User user) {
if (user.getFilter().getJobType() == JobType.TOTAL) {
return null; // total일 경우 모든 직무 공고 허용
}
return internshipAnnouncement.jobType.eq(user.getFilter().getJobType().getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.terning.terningserver.domain.Token;
import org.terning.terningserver.domain.User;
import org.terning.terningserver.domain.enums.Grade;
import org.terning.terningserver.domain.enums.JobType;
import org.terning.terningserver.domain.enums.ProfileImage;
import org.terning.terningserver.domain.enums.WorkingPeriod;
import org.terning.terningserver.dto.auth.request.SignInRequestDto;
Expand Down Expand Up @@ -208,12 +209,14 @@ private void deleteUser(User user) {
}

private Filter buildFilterFromRequest(SignUpFilterRequestDto request) {
JobType jobType = JobType.TOTAL;
Grade grade = Grade.fromKey(request.grade());
WorkingPeriod workingPeriod = WorkingPeriod.fromKey(request.workingPeriod());
int startYear = request.startYear();
int startMonth = request.startMonth();

return Filter.builder()
.jobType(jobType)
.grade(grade)
.workingPeriod(workingPeriod)
.startYear(startYear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.terning.terningserver.domain.Filter;
import org.terning.terningserver.domain.User;
import org.terning.terningserver.domain.enums.Grade;
import org.terning.terningserver.domain.enums.JobType;
import org.terning.terningserver.domain.enums.WorkingPeriod;
import org.terning.terningserver.dto.filter.request.UpdateUserFilterRequestDto;
import org.terning.terningserver.dto.filter.response.UserFilterDetailResponseDto;
Expand Down Expand Up @@ -35,33 +36,37 @@ public void updateUserFilter(UpdateUserFilterRequestDto responseDto, Long userId
User user = findUser(userId);
Filter filter = user.getFilter();

JobType jobType = (responseDto.jobType() == null || responseDto.jobType().isBlank())
? JobType.TOTAL : JobType.fromKey(responseDto.jobType());
Grade grade = Grade.fromKey(responseDto.grade());
WorkingPeriod workingPeriod = WorkingPeriod.fromKey(responseDto.workingPeriod());

if (filter != null) {
updateExistingFilter(filter, grade, workingPeriod, responseDto);
updateExistingFilter(filter, jobType, grade, workingPeriod, responseDto);
}

createFilter(user, grade, workingPeriod, responseDto);
createFilter(user, jobType, grade, workingPeriod, responseDto);
}

private User findUser(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new CustomException(NOT_FOUND_USER_EXCEPTION));
}

private void updateExistingFilter(Filter filter, Grade grade, WorkingPeriod workingPeriod, UpdateUserFilterRequestDto dto) {
private void updateExistingFilter(Filter filter, JobType jobType, Grade grade, WorkingPeriod workingPeriod, UpdateUserFilterRequestDto dto) {
filter.updateFilter(
jobType,
grade,
workingPeriod,
dto.startYear(),
dto.startMonth()
);
}

private void createFilter(User user, Grade grade, WorkingPeriod workingPeriod, UpdateUserFilterRequestDto dto) {
private void createFilter(User user, JobType jobType, Grade grade, WorkingPeriod workingPeriod, UpdateUserFilterRequestDto dto) {
Filter savedFilter = filterRepository.save(
Filter.builder()
.jobType(jobType)
.grade(grade)
.workingPeriod(workingPeriod)
.startYear(dto.startYear())
Expand Down
Loading