-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 커서 페이지네이션 이용한 피드 전체리스트 API 구현 (#53)
* feature: 대소문자 구분 없이 category value 담아서 요청 시 대문자 변환 처리 (#27) * feature: 커서 페이지네이션 이용한 피드 전체리스트 API 구현 (#27) * refactor: 콜라보레이터 최대 20명까지 가능하도록 수정 (#27) * refactor: 충돌 해결을 위한 코드 일부 수정 (#27) * refactor: 코드 컨벤션 및 코드 메서드화 적용 (#27) * refactor: of 메서드 Builder 적용 및 컨벤션 리펙토링 (#27) * chore: 개행 제거 (#27) --------- Co-authored-by: 김동호 <[email protected]> Co-authored-by: kdkdhoho <[email protected]>
- Loading branch information
1 parent
9c7ad25
commit 378878c
Showing
14 changed files
with
261 additions
and
18 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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/listywave/common/config/EnumMappingConfig.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,15 @@ | ||
package com.listywave.common.config; | ||
|
||
import org.springframework.boot.convert.ApplicationConversionService; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.format.FormatterRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class EnumMappingConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addFormatters(FormatterRegistry registry) { | ||
ApplicationConversionService.configure(registry); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/listywave/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,15 @@ | ||
package com.listywave.common.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QuerydslConfig { | ||
|
||
@Bean | ||
JPAQueryFactory jpaQueryFactory(EntityManager em){ | ||
return new JPAQueryFactory(em); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/listywave/user/application/dto/FeedListsResponse.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,47 @@ | ||
package com.listywave.user.application.dto; | ||
|
||
import com.listywave.list.application.domain.Item; | ||
import com.listywave.list.application.domain.Lists; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record FeedListsResponse( | ||
Long id, | ||
String title, | ||
Boolean isPublic, | ||
List<ListItemsResponse> listItems | ||
) { | ||
public static FeedListsResponse of(Lists lists) { | ||
return FeedListsResponse.builder() | ||
.id(lists.getId()) | ||
.title(lists.getTitle()) | ||
.isPublic(lists.isPublic()) | ||
.listItems(ListItemsResponse.toList(lists)) | ||
.build(); | ||
} | ||
} | ||
|
||
@Builder | ||
record ListItemsResponse( | ||
Long id, | ||
int ranking, | ||
String title, | ||
String imageUrl | ||
) { | ||
public static ListItemsResponse of(Item item) { | ||
return ListItemsResponse.builder() | ||
.id(item.getId()) | ||
.ranking(item.getRanking()) | ||
.title(item.getTitle()) | ||
.imageUrl(item.getImageUrl()) | ||
.build(); | ||
} | ||
|
||
public static List<ListItemsResponse> toList(Lists lists) { | ||
return lists.getItems().stream() | ||
.map(ListItemsResponse::of) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/listywave/user/presentation/dto/response/AllUserListsResponse.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,25 @@ | ||
package com.listywave.user.presentation.dto.response; | ||
|
||
import com.listywave.list.application.domain.Lists; | ||
import com.listywave.user.application.dto.FeedListsResponse; | ||
import java.util.List; | ||
|
||
public record AllUserListsResponse( | ||
Long cursorId, | ||
Boolean hasNext, | ||
List<FeedListsResponse> feedLists | ||
) { | ||
public static AllUserListsResponse of(boolean hasNext, Long cursorId, List<Lists> feedLists) { | ||
return new AllUserListsResponse( | ||
cursorId, | ||
hasNext, | ||
toList(feedLists) | ||
); | ||
} | ||
|
||
public static List<FeedListsResponse> toList(List<Lists> feedLists) { | ||
return feedLists.stream() | ||
.map(FeedListsResponse::of) | ||
.toList(); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/com/listywave/user/repository/UserRepository.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.listywave.user.repository; | ||
|
||
import com.listywave.user.application.domain.User; | ||
import com.listywave.user.repository.custom.UserRepositoryCustom; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
public interface UserRepository extends JpaRepository<User, Long>, UserRepositoryCustom { | ||
|
||
Optional<User> findByOauthId(Long oauthId); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/listywave/user/repository/custom/UserRepositoryCustom.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,10 @@ | ||
package com.listywave.user.repository.custom; | ||
|
||
import com.listywave.list.application.domain.CategoryType; | ||
import com.listywave.list.application.domain.Lists; | ||
import java.util.List; | ||
|
||
public interface UserRepositoryCustom { | ||
|
||
List<Lists> findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size); | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/listywave/user/repository/custom/impl/UserRepositoryImpl.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,59 @@ | ||
package com.listywave.user.repository.custom.impl; | ||
|
||
import static com.listywave.list.application.domain.QItem.item; | ||
import static com.listywave.list.application.domain.QLists.lists; | ||
|
||
import com.listywave.list.application.domain.CategoryType; | ||
import com.listywave.list.application.domain.Lists; | ||
import com.listywave.user.repository.custom.UserRepositoryCustom; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class UserRepositoryImpl implements UserRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Lists> findFeedLists(Long userId, String type, CategoryType category, Long cursorId, int size) { | ||
List<Lists> fetch = queryFactory | ||
.select(lists) | ||
.from(lists) | ||
.leftJoin(lists.items, item) | ||
.where( | ||
userIdEq(userId), | ||
typeEq(type), | ||
categoryEq(category), | ||
listIdGt(cursorId) | ||
) | ||
.distinct() | ||
.limit(size + 1) | ||
.orderBy(lists.updatedDate.desc()) | ||
.fetch(); | ||
return fetch; | ||
} | ||
|
||
private BooleanExpression listIdGt(Long cursorId) { | ||
return cursorId == null ? null : lists.id.lt(cursorId); | ||
} | ||
|
||
private BooleanExpression categoryEq(CategoryType categoryCode) { | ||
if ("0".equals(categoryCode.getCodeValue())) { | ||
return null; | ||
} | ||
return lists.category.eq(categoryCode); | ||
} | ||
|
||
private BooleanExpression typeEq(String type) { | ||
if (type.equals("my")) { | ||
return lists.hasCollaboration.eq(false); | ||
} | ||
return lists.hasCollaboration.eq(true); | ||
} | ||
|
||
private BooleanExpression userIdEq(Long userId) { | ||
return userId == null ? null : lists.user.id.eq(userId); | ||
} | ||
} |
Oops, something went wrong.