-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 콘텐츠 관리 - 콘텐츠 조회 구현 #206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0c027aa
feat: Content 단건조회 구현
plzslp 41528e0
build: QueryDSL 의존성 추가
plzslp 8ba7ee2
feat: 콘텐츠 목록 조회 Controller 코드 작성
plzslp 311a6d3
feat: ContentCursorRequest 추가 및 파라미터 변환을 위한 WebConfig 추가
plzslp a0f9912
feat: Content 엔티티 contentTags 배치사이즈 어노테이션 추가
plzslp b12e976
feat: QueryDslConfig 추가
plzslp 9241160
feat: Content QueryDslRepository 구현
plzslp 17059b5
feat: 목록 조회 ContentService 로직 작성
plzslp d6b30da
feat: 목록 조회 ContentMapper 로직 작성
plzslp 0751c8a
test: Content 조회 API 테스트 코드 작성
plzslp cb95f46
test: Content 조회 Service 로직 테스트 코드 작성
plzslp 7335de0
style: QueryDSL 통합테스트 Todo 주석 추가
plzslp 449981a
refactor: QueryDslTestConfig 추가
plzslp 10f728b
refactor: FollowRepositoryTest에 QueryDslTestConfig import 추가
plzslp 61df9c2
refactor: 업데이트 멀티파트 스키마의 DTO 타입 수정
plzslp 95af603
refactor: limit 검증에 Positive 추가
plzslp 8e7850e
refactor: Controller 테스트 요청값 수정
plzslp 334462f
refactor: 콘텐츠 커서 값 서비스 검증 로직 추가
plzslp 74dadfa
feat: V12 scheam.sql ContentStats average_rating 컬럼 추가
plzslp 34dbbda
refactor: ContentStats averageRating 필드 추가, updateRating() 메서드 추가
plzslp 4b5c0c3
refactor: ContentRepositoryImpl RATE 정렬/커서를 averageRating 기준으로 교체
plzslp fbb6b1f
refactor: ContentMapper RATE 커서를 getAverageRating()으로 교체
plzslp e705d49
refactor: ContentMapper 정렬 방향 반환값 ASCENDING/DESCENDING으로 수정
plzslp dcf7950
refactor: cursor 값을 예외 메시지에서 제거
plzslp e48ac49
refactor: 콘텐츠 cursor 검증 추가 및 limit 한도 추가
plzslp 6488863
fix: Cursor 예외 사용되지 않는 파라미터 제거
plzslp 53a45db
fix: 피드백 반영
plzslp 151ade2
refactor: 콘텐츠 커서 검증 커스텀 어노테이션으로 리펙토링
plzslp 1d2406e
refactor: WebConfig InitBinder로 분리
plzslp 30cb7e3
fix: 콘텐츠 통계 검증 로직 추가
plzslp 3eb0c61
fix: 커서 idAfter XOR 검증로직 제거 및 Validator 테스트 코드 추가
plzslp 140a20c
fix: N+1 문제 해결 및 XOR 커서 검증 복구
plzslp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/codeit/team5/mopl/config/QueryDslConfig.java
This file contains hidden or 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,19 @@ | ||
| package com.codeit.team5.mopl.config; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import jakarta.persistence.EntityManager; | ||
| import jakarta.persistence.PersistenceContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class QueryDslConfig { | ||
|
|
||
| @PersistenceContext | ||
| private EntityManager entityManager; | ||
|
|
||
| @Bean | ||
| public JPAQueryFactory jpaQueryFactory() { | ||
| return new JPAQueryFactory(entityManager); | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| package com.codeit.team5.mopl.config; | ||
|
|
||
| import com.codeit.team5.mopl.global.exception.InvalidSortDirectionException; | ||
| import com.codeit.team5.mopl.watcher.constant.SortByType; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.format.FormatterRegistry; | ||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
|
||
| @Configuration | ||
| public class WebConfig implements WebMvcConfigurer { | ||
|
|
||
| @Override | ||
| public void addFormatters(FormatterRegistry registry) { | ||
| registry.addConverter(String.class, Sort.Direction.class, value -> { | ||
| if (value.equalsIgnoreCase("ASCENDING") || value.equalsIgnoreCase("ASC")) { | ||
| return Sort.Direction.ASC; | ||
| } | ||
| if (value.equalsIgnoreCase("DESCENDING") || value.equalsIgnoreCase("DESC")) { | ||
| return Sort.Direction.DESC; | ||
| } | ||
| throw new InvalidSortDirectionException(value); | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/codeit/team5/mopl/content/dto/request/ContentCursorRequest.java
This file contains hidden or 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,34 @@ | ||
| package com.codeit.team5.mopl.content.dto.request; | ||
|
|
||
| import com.codeit.team5.mopl.content.entity.ContentSortByType; | ||
| import com.codeit.team5.mopl.content.entity.ContentType; | ||
| import jakarta.validation.constraints.Max; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Positive; | ||
| import java.util.List; | ||
| import org.springframework.data.domain.Sort; | ||
|
|
||
| @ValidCursor | ||
| public record ContentCursorRequest( | ||
| ContentType typeEqual, | ||
|
|
||
| String keywordLike, | ||
|
|
||
| List<String> tagsIn, | ||
|
|
||
| String cursor, | ||
|
|
||
| String idAfter, | ||
|
|
||
| @NotNull | ||
| @Positive | ||
| @Max(100) | ||
| Integer limit, | ||
|
plzslp marked this conversation as resolved.
|
||
|
|
||
| @NotNull | ||
| Sort.Direction sortDirection, | ||
|
|
||
| @NotNull | ||
| ContentSortByType sortBy | ||
| ) { | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/main/java/com/codeit/team5/mopl/content/dto/request/ValidCursor.java
This file contains hidden or 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.codeit.team5.mopl.content.dto.request; | ||
|
|
||
| import jakarta.validation.Constraint; | ||
| import jakarta.validation.Payload; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Constraint(validatedBy = ValidCursorValidator.class) | ||
| public @interface ValidCursor { | ||
|
|
||
| String message() default "커서 값이 유효하지 않습니다."; | ||
|
|
||
| Class<?>[] groups() default {}; | ||
|
|
||
| Class<? extends Payload>[] payload() default {}; | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/codeit/team5/mopl/content/dto/request/ValidCursorValidator.java
This file contains hidden or 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,40 @@ | ||
| package com.codeit.team5.mopl.content.dto.request; | ||
|
|
||
| import jakarta.validation.ConstraintValidator; | ||
| import jakarta.validation.ConstraintValidatorContext; | ||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| public class ValidCursorValidator implements ConstraintValidator<ValidCursor, ContentCursorRequest> { | ||
|
|
||
| @Override | ||
| public boolean isValid(ContentCursorRequest request, ConstraintValidatorContext context) { | ||
| String cursor = request.cursor(); | ||
| String idAfter = request.idAfter(); | ||
|
|
||
| if ((cursor == null) ^ (idAfter == null)) return false; | ||
|
|
||
| if (cursor == null) return true; | ||
|
|
||
| try { | ||
| UUID.fromString(idAfter); | ||
| } catch (IllegalArgumentException e) { | ||
| return false; | ||
|
plzslp marked this conversation as resolved.
|
||
| } | ||
|
|
||
| try { | ||
| switch (request.sortBy()) { | ||
| case CREATED_AT -> Instant.parse(cursor); | ||
| case WATCHER_COUNT -> Long.parseLong(cursor); | ||
| case RATE -> { | ||
| double val = Double.parseDouble(cursor); | ||
| if (!Double.isFinite(val)) return false; | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/codeit/team5/mopl/content/entity/ContentSortByType.java
This file contains hidden or 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,24 @@ | ||
| package com.codeit.team5.mopl.content.entity; | ||
|
|
||
| import com.codeit.team5.mopl.content.exception.ContentIncorrectSortByException; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum ContentSortByType { | ||
| CREATED_AT("createdAt"), | ||
| WATCHER_COUNT("watcherCount"), | ||
| RATE("rate") | ||
| ; | ||
| private final String value; | ||
|
|
||
| public static ContentSortByType from(String text) { | ||
| for (ContentSortByType type : ContentSortByType.values()) { | ||
| if (type.getValue().equalsIgnoreCase(text)) { | ||
| return type; | ||
| } | ||
| } | ||
| throw new ContentIncorrectSortByException(text); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.