Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.ftm.server.adapter.in.web.post.dto.response.GetUserPickPopularPostsResponse;
import com.ftm.server.application.port.in.post.GetUserPickPopularPostsUseCase;
import com.ftm.server.application.query.FindByUserIdQuery;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.infrastructure.security.UserPrincipal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -19,9 +22,14 @@ public class GetUserPickPopularPostsController {
private final GetUserPickPopularPostsUseCase userPickPopularPostsUseCase;

@GetMapping("/api/posts/userpick/popular")
public ResponseEntity<ApiResponse> getUserPickPopularPosts() {
public ResponseEntity<ApiResponse> getUserPickPopularPosts(
@AuthenticationPrincipal UserPrincipal userPrincipal) {
List<GetUserPickPopularPostsResponse> userPickPopularPostsResponses =
userPickPopularPostsUseCase.execute().stream()
userPickPopularPostsUseCase
.execute(
FindByUserIdQuery.of(
userPrincipal == null ? null : userPrincipal.getId()))
.stream()
.map(GetUserPickPopularPostsResponse::from)
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.ftm.server.adapter.in.web.post.dto.response.LoadUserPickBiblePostsResponse;
import com.ftm.server.application.port.in.post.LoadUserPickBiblePostsUseCase;
import com.ftm.server.application.query.FindByUserIdQuery;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.infrastructure.security.UserPrincipal;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -17,9 +20,14 @@ public class LoadUserPickBiblePostsController {
private final LoadUserPickBiblePostsUseCase userPickBiblePostsUseCase;

@GetMapping("/api/posts/userpick/bible")
public ResponseEntity<ApiResponse> loadUserPickGroomingBiblePosts() {
public ResponseEntity<ApiResponse> loadUserPickGroomingBiblePosts(
@AuthenticationPrincipal UserPrincipal userPrincipal) {
List<LoadUserPickBiblePostsResponse> result =
userPickBiblePostsUseCase.execute().stream()
userPickBiblePostsUseCase
.execute(
FindByUserIdQuery.of(
userPrincipal == null ? null : userPrincipal.getId()))
.stream()
.map(LoadUserPickBiblePostsResponse::from)
.toList();
return ResponseEntity.ok(ApiResponse.success(SuccessResponseCode.OK, result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.ftm.server.adapter.in.web.post.dto.response.LoadUserPickTopBookmarkPostsResponse;
import com.ftm.server.application.port.in.post.LoadUserPickTopBookmarkPostsUseCase;
import com.ftm.server.application.query.FindByUserIdQuery;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.infrastructure.security.UserPrincipal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -17,9 +20,16 @@ public class LoadUserPickTopBookmarkPostsController {
private final LoadUserPickTopBookmarkPostsUseCase useCase;

@GetMapping("/api/posts/userpick/top-bookmarks")
public ResponseEntity<ApiResponse> loadTopBookmarkPosts() {
public ResponseEntity<ApiResponse> loadTopBookmarkPosts(
@AuthenticationPrincipal UserPrincipal userPrincipal) {
List<LoadUserPickTopBookmarkPostsResponse> result =
useCase.execute().stream().map(LoadUserPickTopBookmarkPostsResponse::from).toList();
useCase
.execute(
FindByUserIdQuery.of(
userPrincipal == null ? null : userPrincipal.getId()))
.stream()
.map(LoadUserPickTopBookmarkPostsResponse::from)
.toList();
return ResponseEntity.ok(ApiResponse.success(SuccessResponseCode.OK, result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class GetUserPickPopularPostsResponse {
private final Long scrapCount;
private final String imageUrl;
private final List<String> hashtags;
private final Boolean userBookmarkYn;

public static GetUserPickPopularPostsResponse from(UserPickPopularPostsVo vo) {
return new GetUserPickPopularPostsResponse(
Expand All @@ -29,6 +30,7 @@ public static GetUserPickPopularPostsResponse from(UserPickPopularPostsVo vo) {
vo.getLikeCount(),
vo.getScrapCount(),
vo.getImageUrl(),
vo.getHashtags());
vo.getHashtags(),
vo.getUserBookmarkYn());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class LoadUserPickBiblePostsResponse {
private final Long scrapCount;
private final String imageUrl;
private final List<String> hashtags;
private final Boolean userBookmarkYn;

public static LoadUserPickBiblePostsResponse from(UserPickBiblePostsVo vo) {
return new LoadUserPickBiblePostsResponse(
Expand All @@ -30,6 +31,7 @@ public static LoadUserPickBiblePostsResponse from(UserPickBiblePostsVo vo) {
vo.getLikeCount(),
vo.getScrapCount(),
vo.getImageUrl(),
vo.getHashtags());
vo.getHashtags(),
vo.getUserBookmarkYn());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class LoadUserPickTopBookmarkPostsResponse {
private final Long scrapCount;
private final String imageUrl;
private final List<String> hashtags;
private final Boolean userBookmarkYn;

public static LoadUserPickTopBookmarkPostsResponse from(LoadUserPickTopBookmarkPostsVo vo) {
return new LoadUserPickTopBookmarkPostsResponse(
Expand All @@ -31,6 +32,7 @@ public static LoadUserPickTopBookmarkPostsResponse from(LoadUserPickTopBookmarkP
vo.getLikeCount(),
vo.getScrapCount(),
vo.getImageUrl(),
vo.getHashtags());
vo.getHashtags(),
vo.getUserBookmarkYn());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.ftm.server.application.port.out.cache.LoadUserPickBiblePostsWithCachePort;
import com.ftm.server.application.port.out.persistence.post.LoadPostPort;
import com.ftm.server.application.query.FindUserPickBiblePostsQuery;
import com.ftm.server.application.vo.post.PostWithIdAndAuthorVo;
import com.ftm.server.common.annotation.Adapter;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,22 +21,22 @@ public class LoadUserPickBiblePostsWithCacheAdapter implements LoadUserPickBible
@Cacheable(
cacheNames = USER_PICK_BIBLE_POSTS_CACHE_NAME,
key = USER_PICK_BIBLE_POSTS_CACHE_KEY_ALL)
public List<PostWithIdAndAuthorVo> getUserPickBiblePost() {
public List<Long> getUserPickBiblePost() {
return execute();
}

@Override
@CachePut(
cacheNames = USER_PICK_BIBLE_POSTS_CACHE_NAME,
key = USER_PICK_BIBLE_POSTS_CACHE_KEY_ALL)
public List<PostWithIdAndAuthorVo> getUserPickBiblePostCachePut() {
public List<Long> getUserPickBiblePostCachePut() {
return execute();
}

public List<PostWithIdAndAuthorVo> execute() {
public List<Long> execute() {
// 최근 1개월 상위 4개 post id를 조회

List<PostWithIdAndAuthorVo> postList =
List<Long> postList =
loadPostPort.loadUserPickBiblePosts(FindUserPickBiblePostsQuery.of(4));

if (postList.isEmpty()) return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.ftm.server.application.port.out.persistence.post.LoadPostPort;
import com.ftm.server.application.query.FindUserPickPopularPostsQuery;
import com.ftm.server.common.annotation.Adapter;
import com.ftm.server.domain.entity.Post;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -29,22 +28,22 @@ public class LoadUserPickPopularPostsWithCacheAdapter implements LoadUserPickPop
@CachePut(
cacheNames = USER_PICK_POPULAR_POSTS_CACHE_NAME,
key = USER_PICK_POPULAR_POSTS_CACHE_KEY_ALL)
public List<Post> getUserPickPopularPostCachePut() {
public List<Long> getUserPickPopularPostCachePut() {
return execute();
}

@Override
@Cacheable(
cacheNames = USER_PICK_POPULAR_POSTS_CACHE_NAME,
key = USER_PICK_POPULAR_POSTS_CACHE_KEY_ALL)
public List<Post> getUserPickPopularPost() {
public List<Long> getUserPickPopularPost() {
return execute();
}

public List<Post> execute() {
public List<Long> execute() {
// 최근 1개월 상위 4개 post id를 조회
LocalDateTime since = LocalDate.now().minusMonths(1).atStartOfDay();
List<Post> postList =
List<Long> postList =
loadPostPort.loadUserPickPopularPosts(FindUserPickPopularPostsQuery.of(since, 4));

if (postList.isEmpty()) return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.ftm.server.application.port.out.cache.LoadUserPickTopBookmarkPostsWithCachePort;
import com.ftm.server.application.port.out.persistence.post.LoadPostPort;
import com.ftm.server.application.query.FindTopPostsByBookmarkCountQuery;
import com.ftm.server.application.vo.post.PostWithIdAndAuthorVo;
import com.ftm.server.common.annotation.Adapter;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,20 +25,20 @@ public class LoadUserPickTopBookmarkPostsWithCacheAdapter
@Cacheable(
cacheNames = USER_PICK_TOP_BOOKMARK_POSTS_CACHE_NAME,
key = USER_PICK_TOP_BOOKMARK_POSTS_CACHE_KEY_ALL)
public List<PostWithIdAndAuthorVo> getTopBookmarkPosts() {
public List<Long> getTopBookmarkPosts() {
return execute();
}

@Override
@CachePut(
cacheNames = USER_PICK_TOP_BOOKMARK_POSTS_CACHE_NAME,
key = USER_PICK_TOP_BOOKMARK_POSTS_CACHE_KEY_ALL)
public List<PostWithIdAndAuthorVo> getTopBookmarkPostsCachePut() {
public List<Long> getTopBookmarkPostsCachePut() {
return execute();
}

private List<PostWithIdAndAuthorVo> execute() {
List<PostWithIdAndAuthorVo> posts =
private List<Long> execute() {
List<Long> posts =
loadPostPort.loadTopPostsByBookmarkCount(FindTopPostsByBookmarkCountQuery.of(4));
if (posts.isEmpty()) return List.of();
return posts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,18 @@ public List<Post> loadPostsByDeleteOption(FindPostByDeleteOptionQuery query) {
}

@Override
public List<Post> loadUserPickPopularPosts(FindUserPickPopularPostsQuery query) {
return postRepository
.findTopNPostsByViewCountAndLikeCount(query.getSince(), query.getLimit())
.stream()
.map(postMapper::toDomainEntity)
.toList();
public List<Long> loadUserPickPopularPosts(FindUserPickPopularPostsQuery query) {
return postRepository.findTopNPostsByViewCountAndLikeCount(
query.getSince(), query.getLimit());
}

@Override
public List<PostWithIdAndAuthorVo> loadUserPickBiblePosts(FindUserPickBiblePostsQuery query) {
public List<Long> loadUserPickBiblePosts(FindUserPickBiblePostsQuery query) {
return postRepository.findTopNPostsByLikeCount(query.getLimit());
}

@Override
public List<PostWithIdAndAuthorVo> loadTopPostsByBookmarkCount(
FindTopPostsByBookmarkCountQuery query) {
public List<Long> loadTopPostsByBookmarkCount(FindTopPostsByBookmarkCountQuery query) {
return postRepository.findTopNPostsByBookmarkCount(query.getLimit());
}

Expand All @@ -180,6 +176,11 @@ public List<BookmarkYnWrapperVo> loadUserPickAllPostsByLatest(
.toList();
}

@Override
public List<PostIdAndBookmarkYnVo> loadPostIdAndBookmarkYn(FindByPostIdsAndUserQuery query) {
return postRepository.findPostIdWithBookmarkYn(query);
}

@Override
public List<PostWithUserAndBookmarkCountVo> loadPostWithUserAndBookmarkCount(
FindByIdsQuery query) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.ftm.server.adapter.out.persistence.repository;

import com.ftm.server.adapter.out.persistence.model.PostJpaEntity;
import com.ftm.server.application.query.FindPostByDeleteOptionQuery;
import com.ftm.server.application.query.FindPostsByCreatedDateQuery;
import com.ftm.server.application.query.FindPostsByPagingQuery;
import com.ftm.server.application.query.FindUserPickLatestPostsByCursorQuery;
import com.ftm.server.application.query.*;
import com.ftm.server.application.vo.post.BookmarkYnWrapperVo;
import com.ftm.server.application.vo.post.PostIdAndBookmarkYnVo;
import com.querydsl.core.Tuple;
import java.util.List;
import org.springframework.data.domain.Slice;
Expand All @@ -19,4 +17,6 @@ public interface PostCustomRepository {
List<Tuple> findAllByCreatedDateInOneWeekAndUserGrouping(FindPostsByCreatedDateQuery query);

List<BookmarkYnWrapperVo> findPostsByLatestCursor(FindUserPickLatestPostsByCursorQuery query);

List<PostIdAndBookmarkYnVo> findPostIdWithBookmarkYn(FindByPostIdsAndUserQuery query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import static com.ftm.server.adapter.out.persistence.model.QPostJpaEntity.postJpaEntity;

import com.ftm.server.adapter.out.persistence.model.PostJpaEntity;
import com.ftm.server.application.query.FindPostByDeleteOptionQuery;
import com.ftm.server.application.query.FindPostsByCreatedDateQuery;
import com.ftm.server.application.query.FindPostsByPagingQuery;
import com.ftm.server.application.query.FindUserPickLatestPostsByCursorQuery;
import com.ftm.server.application.query.*;
import com.ftm.server.application.vo.post.BookmarkYnWrapperVo;
import com.ftm.server.application.vo.post.PostIdAndBookmarkYnVo;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Projections;
Expand Down Expand Up @@ -129,4 +127,27 @@ public List<BookmarkYnWrapperVo> findPostsByLatestCursor(
.limit(query.getLimit() + 1) // hasNext 체크를 위해 +1
.fetch();
}

@Override
public List<PostIdAndBookmarkYnVo> findPostIdWithBookmarkYn(FindByPostIdsAndUserQuery query) {

return queryFactory
.select(
Projections.constructor(
PostIdAndBookmarkYnVo.class,
postJpaEntity.id,
bookmarkJpaEntity.id.isNotNull()))
.from(postJpaEntity)
.leftJoin(bookmarkJpaEntity)
.on(
bookmarkJpaEntity
.post
.eq(postJpaEntity)
.and(
bookmarkJpaEntity.user.id.eq(
query.getUserId())) // 특정 user 북마크 여부 확인
)
.where(postJpaEntity.id.in(query.getPostIds()))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.ftm.server.adapter.out.persistence.model.PostJpaEntity;
import com.ftm.server.application.vo.post.PostAndBookmarkCountVo;
import com.ftm.server.application.vo.post.PostWithIdAndAuthorVo;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -29,7 +28,7 @@ public interface PostRepository
@Query(
value =
"""
SELECT *
SELECT id
FROM post p
WHERE p.created_at >= :since
ORDER BY
Expand All @@ -39,12 +38,11 @@ public interface PostRepository
LIMIT :limit
""",
nativeQuery = true)
List<PostJpaEntity> findTopNPostsByViewCountAndLikeCount(
List<Long> findTopNPostsByViewCountAndLikeCount(
@Param("since") LocalDateTime since, @Param("limit") int limit);

@Query(
"select new com.ftm.server.application.vo.post.PostWithIdAndAuthorVo(p.id) from PostJpaEntity p order by p.likeCount DESC")
List<PostWithIdAndAuthorVo> findTopNPostsByLikeCount(@Param("limit") int limit);
@Query("select p.id from PostJpaEntity p order by p.likeCount DESC")
List<Long> findTopNPostsByLikeCount(@Param("limit") int limit);

@Query(
"""
Expand Down
Loading
Loading