Skip to content

Commit

Permalink
Merge pull request #298 from techeer-sv/BE/#295
Browse files Browse the repository at this point in the history
구인공고 리스트 API 모집여부 출력 및 모집 중 필터링 추가
  • Loading branch information
baekhangyeol authored Nov 18, 2023
2 parents 9a8b1c3 + e707f7b commit acd257d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ public ResponseEntity<ResultResponse> recruitmentDetails(@PathVariable Long recr
.header(SET_COOKIE, cookie.toString())
.body(ResultResponse.of(ResultCode.RECRUITMENT_GET_SUCCESS, result));
}

/**
* 모집 여부 필터링
* 모집 중 필터링
*/

@Operation(summary = "findRecruitmentList", description = "구인 게시글 조회")
@GetMapping
public ResponseEntity<ResultResponse> recruitmentList(@RequestParam(required = false) List<Position> positions,
@RequestParam(required = false) List<String> tags,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) Boolean isRecruiting,
PageRequest pageRequest) {
Pageable pageable = pageRequest.of();
List<GetRecruitmentResponse> result = recruitmentService.findRecruitmentList(positions, tags, keyword, pageable);
List<GetRecruitmentResponse> result = recruitmentService.findRecruitmentList(positions, tags, keyword, isRecruiting, pageable);
return ResponseEntity.ok(ResultResponse.of(ResultCode.RECRUITMENT_PAGING_GET_SUCCESS, result));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public class Recruitment extends BaseEntity {
@Column(nullable = false)
private LocalDateTime period;

@Column(nullable = false)
private Boolean isRecruiting;

@PrePersist
private void initIsRecruiting() {
this.isRecruiting = LocalDateTime.now().isBefore(this.endDate);
}

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Position position;
Expand Down Expand Up @@ -83,6 +91,7 @@ public void updateRecruitment(UpdateRecruitmentRequest request, Tags tags) {
this.recruitmentCount = request.getRecruitmentCount();
this.type = request.getType();
this.endDate = request.getEndDate();
this.isRecruiting = request.getIsRecruiting();
this.position = request.getPosition();
recruitmentTags.clear();
addTag(tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class UpdateRecruitmentRequest {
@NotNull(message = "period cannot be null")
private LocalDateTime period;

@NotNull(message = "isRecruiting cannot be null")
private Boolean isRecruiting;

@NotNull(message = "position cannot be null")
private Position position;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class GetRecruitmentDetailResponse {

private int viewCount;

private boolean isRecruiting;

private List<String> techTags;


Expand All @@ -47,6 +49,7 @@ public static GetRecruitmentDetailResponse from(Recruitment recruitment) {
.period(recruitment.getPeriod())
.position(recruitment.getPosition())
.recruitmentCount(recruitment.getRecruitmentCount())
.isRecruiting(recruitment.getIsRecruiting())
.viewCount(recruitment.getViewCount())
.techTags(recruitment.getTagNames())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.graphy.backend.domain.recruitment.domain.Position;
import com.graphy.backend.domain.recruitment.domain.Recruitment;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -24,6 +25,8 @@ public class GetRecruitmentResponse {

private Position position;

private boolean isRecruiting;

private List<String> techTags;

public static GetRecruitmentResponse from(Recruitment recruitment) {
Expand All @@ -32,6 +35,7 @@ public static GetRecruitmentResponse from(Recruitment recruitment) {
.nickname(recruitment.getMember().getNickname())
.title(recruitment.getTitle())
.position(recruitment.getPosition())
.isRecruiting(recruitment.getIsRecruiting())
.techTags(recruitment.getTagNames())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface RecruitmentCustomRepository {
List<Recruitment> findRecruitments(List<Position> positions,
List<String> tags,
String keyword,
Boolean isRecruiting,
Pageable pageable);

Optional<Recruitment> findRecruitmentWithMember(Long recruitmentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.graphy.backend.domain.recruitment.repository.RecruitmentCustomRepository;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;

Expand All @@ -24,14 +25,17 @@ public class RecruitmentCustomRepositoryImpl implements RecruitmentCustomReposit
public List<Recruitment> findRecruitments(List<Position> positions,
List<String> tags,
String title,
Boolean isRecruiting,
Pageable pageable) {

return jpaQueryFactory
.selectFrom(recruitment)
.distinct()
.where(
tagIn(tags),
positionIn(positions),
recruitmentTitleLike(title)
recruitmentTitleLike(title),
isRecruiting(isRecruiting)
)
.join(recruitment.member, member).fetchJoin()
.leftJoin(recruitmentTag).on(recruitmentTag.recruitment.eq(recruitment))
Expand Down Expand Up @@ -63,5 +67,10 @@ private BooleanExpression positionIn(List<Position> positions) {
private BooleanExpression recruitmentTitleLike(String title) {
return title != null ? recruitment.title.like(title) : null;
}

private BooleanExpression isRecruiting(Boolean isRecruiting) {
if(isRecruiting == null) return null;
return recruitment.isRecruiting.eq(isRecruiting);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public GetRecruitmentDetailResponse findRecruitmentById(Long recruitmentId) {
public List<GetRecruitmentResponse> findRecruitmentList(List<Position> positions,
List<String> tags,
String keyword,
Boolean isRecruiting,
Pageable pageable) {
List<Recruitment> result = recruitmentRepository.findRecruitments(positions, tags, keyword, pageable);
List<Recruitment> result = recruitmentRepository.findRecruitments(positions, tags, keyword, isRecruiting, pageable);
if (result.isEmpty()) throw new EmptyResultException(ErrorCode.RECRUITMENT_NOT_EXIST);

return GetRecruitmentResponse.listOf(result);
Expand Down

0 comments on commit acd257d

Please sign in to comment.