-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] : 게시글 상호작용 엔티티 연관관계 매핑 삭제 * [feat] : 게시글 상호작용 엔티티 builder 삭제 후 정적 팩토리 메서드 추가 * [feat] : 게시글 상호작용 엔티티 수량 증가 메서드 추가 * [chore] : querydsl 의존성 추가 * [chore] : 256 인코딩 삭제 * [chore] : s3 API 스웨거 명세 * [rename] : 질문글 dto 경로 변경 * [feat] : 질문글 검색 DTO 추가 * [feat] : 질문글 검색 요청 DTO 추가 * [feat] : JobGroup 필드 추가 및 변환함수 추가 * [chore] : querydsl 설정 파일 추가 * [test] : repository test 추상 클래스에 querydsl 설정 파일 포함 * [feat] : 직군 및 검색어 필터링 동적 쿼리 작성 * [test] : 직군 및 검색어 필터링 동적 쿼리 테스트 * [feat] : request dto 채택 여부 필드 null 허용 * [test] : questionPostFixture 객체 추가 * [test] : 질문글 키워드 필터링 repository test * [feat] : 응답 dto 채택 여부 필드 추가 * [style] : 응답 dto 필드명 변경 * [feat] : 질문글 entity<->dto 매퍼 추가 * [feat] : 질문글 검색 비즈니스 로직 추가 * [feat] : 질문글 검색 API 로직 추가 * [feat] : 질문글 검색 API http method 변경 * [feat] : 질문글 검색 채택여부 필터링 추가 * [test] : 질문글 검색 채택여부 필터링 테스트 * [test] : 질문글 검색 통합 테스트 * [style] : 코드 리포멧팅 * [style] : dto 팩토리 메서드 네이밍 변경 * [feat] : dto 검증 로직 추가 * [test] : dto 검증 로직 테스트 * [chore] : yml 디코딩 추가
- Loading branch information
Showing
24 changed files
with
484 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/dnd/gongmuin/answer/dto/AnswerDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/dnd/gongmuin/common/config/QueryDslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.dnd.gongmuin.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
|
||
@Configuration | ||
public class QueryDslConfig { | ||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/dnd/gongmuin/question_post/dto/request/QuestionPostSearchCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.dnd.gongmuin.question_post.dto.request; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.validation.constraints.Size; | ||
|
||
public record QuestionPostSearchCondition( | ||
String keyword, | ||
@Size(max = 3, message = "직군은 3개까지 선택 가능합니다.") | ||
List<String> jobGroups, | ||
Boolean isChosen | ||
) { | ||
} |
2 changes: 1 addition & 1 deletion
2
...post/dto/RegisterQuestionPostRequest.java → .../request/RegisterQuestionPostRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ongmuin/question_post/dto/MemberInfo.java → ...uestion_post/dto/response/MemberInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
..._post/dto/QuestionPostDetailResponse.java → .../response/QuestionPostDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/dnd/gongmuin/question_post/dto/response/QuestionPostSimpleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.dnd.gongmuin.question_post.dto.response; | ||
|
||
public record QuestionPostSimpleResponse( | ||
Long questionPostId, | ||
String title, | ||
String content, | ||
String jobGroup, | ||
int reward, | ||
String createdAt, | ||
boolean isChosen | ||
// TODO: 8/11/24 북마크 수, 추천수 추가 | ||
) { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/gongmuin/question_post/repository/QuestionPostQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dnd.gongmuin.question_post.repository; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
|
||
import com.dnd.gongmuin.question_post.domain.QuestionPost; | ||
import com.dnd.gongmuin.question_post.dto.request.QuestionPostSearchCondition; | ||
|
||
public interface QuestionPostQueryRepository { | ||
Slice<QuestionPost> searchQuestionPosts(QuestionPostSearchCondition condition, Pageable pageable); | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/dnd/gongmuin/question_post/repository/QuestionPostQueryRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.dnd.gongmuin.question_post.repository; | ||
|
||
import static com.dnd.gongmuin.question_post.domain.QQuestionPost.*; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.domain.SliceImpl; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.dnd.gongmuin.member.domain.JobGroup; | ||
import com.dnd.gongmuin.question_post.domain.QuestionPost; | ||
import com.dnd.gongmuin.question_post.dto.request.QuestionPostSearchCondition; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class QuestionPostQueryRepositoryImpl implements QuestionPostQueryRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Slice<QuestionPost> searchQuestionPosts(QuestionPostSearchCondition condition, Pageable pageable) { | ||
List<QuestionPost> content = queryFactory.select(questionPost) | ||
.from(questionPost) | ||
.where( | ||
keywordContains(condition.keyword()), | ||
jobGroupContains(condition.jobGroups()), | ||
isChosenEq(condition.isChosen()) | ||
) | ||
.limit(pageable.getPageSize() + 1L) | ||
.offset(pageable.getOffset()) | ||
.fetch(); | ||
boolean hasNext = hasNext(pageable.getPageSize(), content); | ||
return new SliceImpl<>(content, pageable, hasNext); | ||
} | ||
|
||
private BooleanExpression isChosenEq(Boolean isChosen) { | ||
if (isChosen == null) { | ||
return null; | ||
} | ||
if (Boolean.TRUE.equals(isChosen)) { | ||
return questionPost.isChosen.eq(Boolean.TRUE); | ||
} else { | ||
return questionPost.isChosen.eq(Boolean.FALSE); | ||
} | ||
} | ||
|
||
private BooleanExpression jobGroupContains(List<String> jobGroups) { | ||
if (jobGroups == null || jobGroups.isEmpty()) | ||
return null; // 직군 필터링 선택 안할 때 | ||
List<JobGroup> selectedJobGroups = JobGroup.from(jobGroups); // string -> enum | ||
return questionPost.jobGroup.in(selectedJobGroups); | ||
} | ||
|
||
private BooleanExpression keywordContains(String keyword) { | ||
return keyword != null ? questionPost.title.contains(keyword) : null; | ||
} | ||
|
||
private boolean hasNext(int pageSize, List<QuestionPost> questionPosts) { | ||
if (questionPosts.size() <= pageSize) { | ||
return false; | ||
} | ||
questionPosts.remove(pageSize); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.