Skip to content

Commit

Permalink
[fix] fix get posts feature
Browse files Browse the repository at this point in the history
  • Loading branch information
minaamim committed Sep 5, 2023
1 parent 7a0e7f2 commit 66d99ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import com.nexters.buyornot.module.post.dao.poll.ParticipantRepository;
import com.nexters.buyornot.module.post.dao.poll.UnrecommendedRepository;
import com.nexters.buyornot.module.post.domain.model.PollStatus;
import com.nexters.buyornot.module.post.domain.model.PublicStatus;
import com.nexters.buyornot.module.post.domain.poll.Participant;
import com.nexters.buyornot.module.post.domain.poll.Unrecommended;
import com.nexters.buyornot.module.post.domain.post.PollItem;
import com.nexters.buyornot.module.post.domain.post.Post;
import com.nexters.buyornot.module.post.domain.model.PublicStatus;
import com.nexters.buyornot.module.post.api.dto.request.CreatePostReq;
import com.nexters.buyornot.module.post.api.dto.response.PostResponse;
import com.nexters.buyornot.module.user.dto.JwtUser;
Expand Down Expand Up @@ -145,7 +145,7 @@ public List<PostResponse> getPage(JwtUser user, final int page, final int count)
if(user.getRole().equals(Role.NON_MEMBER.getValue())) userId = NON_MEMBER + LocalDateTime.now();
else userId = user.getId().toString();

List<PostResponse> responseList = postRepository.findPageByIsPublishedOrderByIdDesc(true, PageRequest.of(page, count))
List<PostResponse> responseList = postRepository.findPageByIsPublishedAndPublicStatusOrderByIdDesc(true, PublicStatus.PUBLIC, PageRequest.of(page, count))
.stream()
.map(Post::newPostResponse)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.nexters.buyornot.module.post.dao;

import com.nexters.buyornot.module.post.domain.model.PollStatus;
import com.nexters.buyornot.module.post.domain.poll.Participant;
import com.nexters.buyornot.module.post.domain.post.Post;
import com.nexters.buyornot.module.post.domain.poll.Unrecommended;
import com.nexters.buyornot.module.post.domain.model.PublicStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

Expand All @@ -37,7 +33,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {

List<Post> findByUserIdAndPublicStatus(UUID userId, PublicStatus publicStatus);

Page<Post> findPageByIsPublishedOrderByIdDesc(boolean isPublished, Pageable pageable);
Page<Post> findPageByIsPublishedAndPublicStatusOrderByIdDesc(boolean isPublished, PublicStatus publicStatus, Pageable pageable);

List<Post> findByUserIdAndIsPublished(UUID id, boolean isPublished);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PostServiceTest {
@Test
@Transactional
void_작성() {

JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");

List<String> urls = new ArrayList<>();
Expand All @@ -59,6 +58,31 @@ class PostServiceTest {
log.info("response ->{}", response.getPollItemResponseList().get(0).getItemUrl());
}

@Test
@Transactional
void 메인화면() {
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");

List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");

CreatePostReq createPostReq1 = CreatePostReq.of("test", "test", PublicStatus.PUBLIC, true, urls);
CreatePostReq createPostReq2 = CreatePostReq.of("test", "test", PublicStatus.PRIVATE, true, urls);
postService.create(user, createPostReq1);
postService.create(user, createPostReq1);
postService.create(user, createPostReq1);
postService.create(user, createPostReq2);

List<PostResponse> list = postService.getPage(user, 0, 20);

for(PostResponse response : list) {
log.info("Id: " + response.getId() + " title: " + response.getTitle() + " status: " + response.getPublicStatus() + " isPublished: " + response.isPublished());
}

assertThat(list.size()).isEqualTo(5);
}

@Test
@Transactional
void get_temporaries() {
Expand Down

0 comments on commit 66d99ef

Please sign in to comment.