-
Notifications
You must be signed in to change notification settings - Fork 0
[fix] 기록장 조회 api 수정 #105
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
[fix] 기록장 조회 api 수정 #105
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
bef5696
[feat] VisibleForTesting 어노테이션을 위한 의존성 주입 (#119)
buzz0331 7633448
[feat] Cursor 객체 도입 (인코딩, 디코딩 담당) (#119)
buzz0331 1b555b1
[feat] 기록장 조회 api 핸들러 (#119)
buzz0331 57b8098
[feat] 기록장 조회 api 쿼리 작성 (#119)
buzz0331 8cf54bc
[feat] 기록장 조회 api 관련 dto 선언 (#119)
buzz0331 3948164
[feat] 필요한 Enum 타입 선언 (#119)
buzz0331 58cccf0
[refactor] 필요없는 클래스 제거 (#119)
buzz0331 d49d428
[feat] 특정 게시물을 사용자가 좋아요 눌렀는지 여부 조회 쿼리 (#119)
buzz0331 143605e
[feat] Query 조회용 dto (PostQueryDto) (#119)
buzz0331 68e07e6
[feat] 특정 투표에 대한 투표항목을 가져오는 쿼리 (#119)
buzz0331 5739d25
[feat] 필요없는 쿼리 제거 (#119)
buzz0331 2712947
[feat] VoteItem 조회용 Dto (#119)
buzz0331 df2dda0
[feat] VoteItem 투표 수 비율 구하는 알고리즘 (#119)
buzz0331 963813e
[test] VoteItem 투표 수 비율 구하는 알고리즘 단위 테스트 (#119)
buzz0331 6df9a82
[refactor] SearchTypeParams 예외 메시지 수정 (#119)
buzz0331 8f98b5a
[feat] 기록장 조회 서비스 로직 (#119)
buzz0331 6382803
[test] 기록장 조회 api 통합 테스트를 위한 update 메서드 (#119)
buzz0331 01a575e
[test] 기록장 조회 api 통합 테스트 (#119)
buzz0331 9df0382
[refactor] 블러처리 로직 수정 (#119)
buzz0331 8973ad2
[refactor] 검증 로직 수정 (#119)
buzz0331 ebb99fb
[fix] status ACTIVE만 조회되도록 수정 (#119)
buzz0331 43be9be
[merge] conflict 해결 (#100)
buzz0331 2adbc00
[refactor] 안쓰는 쿼리 삭제 (#100)
buzz0331 fd8792a
[refactor] PostType 통합 (#119)
buzz0331 e1496fb
[refactor] 에러코드 및 sql case 문 수정 (#119)
buzz0331 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package konkuk.thip.common.util; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| import java.net.URLDecoder; | ||
| import java.net.URLEncoder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.LocalDateTime; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.function.Function; | ||
|
|
||
| @Getter | ||
| public class Cursor { | ||
|
|
||
| private static final String SPLIT_DELIMITER = "\\|"; | ||
| private static final String JOIN_DELIMITER = "|"; | ||
| private static final int DEFAULT_PAGE_SIZE = 10; | ||
|
|
||
| private final List<String> rawCursorList; | ||
| private final int pageSize; | ||
| private final boolean isFirstRequest; | ||
|
|
||
| // 인코딩용 생성자 (pageSize는 default 사용) | ||
| public Cursor(List<String> rawCursorList) { | ||
| this(rawCursorList, DEFAULT_PAGE_SIZE); | ||
| } | ||
|
|
||
| private Cursor(List<String> rawCursorList, int pageSize) { | ||
| this.rawCursorList = rawCursorList; | ||
| this.pageSize = pageSize; | ||
| this.isFirstRequest = rawCursorList.isEmpty(); | ||
| } | ||
|
|
||
| // 디코딩을 위한 정적 팩토리 메서드 | ||
| public static Cursor from(String encoded, int pageSize) { | ||
| if (encoded == null || !encoded.contains("|")) { | ||
| return new Cursor(List.of(), pageSize); // 빈 커서 생성 | ||
| } | ||
| String decoded = URLDecoder.decode(encoded, StandardCharsets.UTF_8); | ||
| List<String> parts = Arrays.asList(decoded.split(SPLIT_DELIMITER)); | ||
| return new Cursor(parts, pageSize); | ||
| } | ||
|
|
||
| public String toEncodedString() { | ||
| String raw = String.join(JOIN_DELIMITER, rawCursorList); | ||
| return URLEncoder.encode(raw, StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| public LocalDateTime getLocalDateTime(int index) { | ||
| return getAs(index, LocalDateTime::parse, "LocalDateTime"); | ||
| } | ||
|
|
||
| public Long getLong(int index) { | ||
| return getAs(index, Long::parseLong, "Long"); | ||
| } | ||
|
|
||
| public Integer getInteger(int index) { | ||
| return getAs(index, Integer::parseInt, "Integer"); | ||
| } | ||
|
|
||
| public String getString(int index) { | ||
| return get(index); | ||
| } | ||
|
|
||
| private String get(int index) { | ||
| if (index < 0 || index >= rawCursorList.size()) { | ||
| throw new IndexOutOfBoundsException("인덱스가 범위를 벗어났습니다: " + index); | ||
| } | ||
| return rawCursorList.get(index); | ||
| } | ||
|
|
||
| private <T> T getAs(int index, Function<String, T> parser, String typeName) { | ||
| try { | ||
| return parser.apply(get(index)); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException( | ||
| String.format("커서에서 %s 값을 파싱할 수 없습니다: '%s'", typeName, get(index)), e | ||
| ); | ||
| } | ||
| } | ||
| } | ||
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
6 changes: 3 additions & 3 deletions
6
src/main/java/konkuk/thip/post/application/port/out/PostLikeQueryPort.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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| package konkuk.thip.post.application.port.out; | ||
|
|
||
| public interface PostLikeQueryPort { | ||
| import java.util.Set; | ||
|
|
||
| int countByPostId(Long postId); | ||
| boolean existsByPostIdAndUserId(Long postId, Long userId); | ||
| public interface PostLikeQueryPort { | ||
|
|
||
| Set<Long> findPostIdsLikedByUser(Set<Long> postIds, Long userId); | ||
| } |
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import konkuk.thip.common.dto.BaseResponse; | ||
| import konkuk.thip.common.security.annotation.UserId; | ||
| import konkuk.thip.record.adapter.in.web.response.RecordSearchResponse; | ||
| import konkuk.thip.record.application.port.in.dto.RecordSearchQuery; | ||
| import konkuk.thip.record.application.port.in.dto.RecordSearchUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
@@ -16,18 +17,43 @@ public class RecordQueryController { | |
|
|
||
| private final RecordSearchUseCase recordSearchUseCase; | ||
|
|
||
| /** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
| * 방의 게시글(기록, 투표) 목록 조회 | ||
| * @param roomId | ||
| * @param type : group , mine | ||
| * @param sort : 그룹 기록 -> 최신순 / 내 기록 -> 페이지 높은 순 default 정렬 | ||
| * @param pageStart | ||
| * @param pageEnd | ||
| * @param isOverview : 총평보기 필터 여부 | ||
| * @param isPageFilter : 페이지 필터 여부 | ||
| * @param userId | ||
| * @return | ||
| */ | ||
| @GetMapping("/rooms/{roomId}/posts") | ||
| public BaseResponse<RecordSearchResponse> viewRecordList( | ||
| @PathVariable final Long roomId, | ||
| @RequestParam(required = false) final String type, | ||
| @RequestParam(required = false, defaultValue = "group") final String type, | ||
| @RequestParam(required = false) final String sort, | ||
| @RequestParam(required = false) final Integer pageStart, | ||
| @RequestParam(required = false) final Integer pageEnd, | ||
| @RequestParam final Boolean isOverview, | ||
| @RequestParam final Integer pageNum, | ||
| @RequestParam(required = false, defaultValue = "false") final Boolean isOverview, | ||
| @RequestParam(required = false, defaultValue = "false") final Boolean isPageFilter, | ||
| @RequestParam(required = false) final String cursor, | ||
| @UserId final Long userId | ||
| ) { | ||
| return BaseResponse.ok(recordSearchUseCase.search(roomId, type, sort, pageStart, pageEnd, isOverview, pageNum, userId)); | ||
| return BaseResponse.ok(recordSearchUseCase.search( | ||
| RecordSearchQuery.builder() | ||
| .roomId(roomId) | ||
| .type(type) | ||
| .sort(sort) | ||
| .pageStart(pageStart) | ||
| .pageEnd(pageEnd) | ||
| .isOverview(isOverview) | ||
| .isPageFilter(isPageFilter) | ||
| .nextCursor(cursor) | ||
| .userId(userId) | ||
| .build() | ||
| )); | ||
| } | ||
|
|
||
| } | ||
39 changes: 0 additions & 39 deletions
39
src/main/java/konkuk/thip/record/adapter/in/web/response/RecordDto.java
This file was deleted.
Oops, something went wrong.
65 changes: 32 additions & 33 deletions
65
src/main/java/konkuk/thip/record/adapter/in/web/response/RecordSearchResponse.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 |
|---|---|---|
| @@ -1,42 +1,41 @@ | ||
| package konkuk.thip.record.adapter.in.web.response; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
| import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
| import lombok.Builder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Builder | ||
| public record RecordSearchResponse( | ||
| List<RecordSearchResult> recordList, | ||
| Integer page, | ||
| Integer size, | ||
| Boolean first, | ||
| Boolean last | ||
| List<PostDto> postList, | ||
| String nextCursor, | ||
| Boolean isLast | ||
| ){ | ||
|
|
||
| public static RecordSearchResponse of(List<RecordSearchResult> recordList, | ||
| Integer page, | ||
| Integer size, | ||
| Boolean first, | ||
| Boolean last) { | ||
| return new RecordSearchResponse(recordList, page, size, first, last); | ||
| } | ||
|
|
||
| @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") | ||
| @JsonSubTypes({ | ||
| @JsonSubTypes.Type(value = RecordDto.class, name = "RECORD"), | ||
| @JsonSubTypes.Type(value = VoteDto.class, name = "VOTE") | ||
| }) | ||
| public sealed interface RecordSearchResult permits RecordDto, VoteDto { | ||
| String type(); | ||
| String postDate(); | ||
| int page(); | ||
| Long userId(); | ||
| String nickName(); | ||
| String profileImageUrl(); | ||
| String content(); | ||
| int likeCount(); | ||
| int commentCount(); | ||
| boolean isLiked(); | ||
| boolean isWriter(); | ||
| @Builder | ||
| public record PostDto( | ||
| Long postId, | ||
| String postDate, | ||
| String postType, | ||
| int page, | ||
| Long userId, | ||
| String nickName, | ||
| String profileImageUrl, | ||
| String content, | ||
| int likeCount, | ||
| int commentCount, | ||
| boolean isLiked, | ||
| boolean isWriter, | ||
| boolean isLocked, | ||
| List<VoteItemDto> voteItems | ||
| ) { | ||
| public record VoteItemDto( | ||
| Long voteItemId, | ||
| String itemName, | ||
| int percentage, | ||
| boolean isVoted | ||
| ) { | ||
| public static VoteItemDto of(Long voteItemId, String itemName, int percentage, boolean isVoted) { | ||
| return new VoteItemDto(voteItemId, itemName, percentage, isVoted); | ||
| } | ||
| } | ||
| } | ||
| } |
60 changes: 0 additions & 60 deletions
60
src/main/java/konkuk/thip/record/adapter/in/web/response/VoteDto.java
This file was deleted.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
커서 디코딩 로직의 견고성을 개선해주세요.
현재
encoded.contains("|")체크만으로는 불완전한 커서 문자열을 정확히 검증하기 어렵습니다.다음 케이스들을 고려해보세요:
"""|"또는"||"🤖 Prompt for AI Agents