Skip to content

Commit

Permalink
[fix] 관심상품 목록 조회시 본인이 관심 등록한 상품 게시글만 조회하도록 구현 (#158)
Browse files Browse the repository at this point in the history
* #153 fix: 채팅창 목록 조회 문제 해결

- 채팅창만이 존재하고 채팅 로그가 없는 경우가 원인이었습니다.

* #153 fix: nextMessageId가 응답되도록 수정

* #153 fix: 필드멤버 명 변경

* #153 fix: 오타 수정

* #153 fix: 채팅 메시지 목록 조회시 새로운 메시지가 없는 경우 408 -> 200으로 변경

* #153 feat; 채팅방에 없는 회원이 채팅 메시지 목록 조회 요청시 인가 오류 구현

* #153 feat; equalItemId 조건절 별도의 메소드로 구현

* #153 fix: 관심상품 목록 조회시 본인이 관심 등록한 상품 게시글만 조회하도록 변경
  • Loading branch information
yonghwankim-dev authored Oct 5, 2023
1 parent c31afa2 commit a9c0522
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public ApiResponse<Void> wishStatus(@PathVariable Long itemId, @RequestParam Wis

@GetMapping
public ApiResponse<ItemResponses> findAll(@RequestParam(required = false) Long categoryId,
@RequestParam(required = false, defaultValue = "10") int size, @RequestParam(required = false) Long cursor) {
return ApiResponse.ok("관심상품 조회에 성공하였습니다.", wishItemService.findAll(categoryId, size, cursor));
@RequestParam(required = false, defaultValue = "10") int size, @RequestParam(required = false) Long cursor,
@AuthPrincipal Principal principal) {
return ApiResponse.ok("관심상품 조회에 성공하였습니다.", wishItemService.findAll(categoryId, size, cursor, principal));
}

@GetMapping("/categories")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ private void cancel(Long itemId) {
wishRepository.deleteByItemId(itemId);
}

public ItemResponses findAll(Long categoryId, int size, Long cursor) {
Slice<ItemResponse> itemResponses = wishPaginationRepository.findAll(categoryId, size, cursor);
public ItemResponses findAll(Long categoryId, int size, Long cursor, Principal principal) {
Long memberId = principal.getMemberId();
Slice<ItemResponse> itemResponses = wishPaginationRepository.findAll(categoryId, size, cursor, memberId);
return PaginationUtils.getItemResponses(itemResponses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public class WishPaginationRepository {

private final JPAQueryFactory queryFactory;
private final ItemRepository itemRepository;
private final WishRepository wishRepository;

public Slice<ItemResponse> findAll(Long categoryId, int size, Long cursor) {
public Slice<ItemResponse> findAll(Long categoryId, int size, Long cursor, Long memberId) {
List<ItemResponse> itemResponses = queryFactory.select(Projections.fields(ItemResponse.class,
item.id.as("itemId"),
item.thumbnailUrl,
Expand All @@ -38,7 +39,8 @@ public Slice<ItemResponse> findAll(Long categoryId, int size, Long cursor) {
.join(wish.item, item)
.on(wish.item.id.eq(item.id))
.where(itemRepository.lessThanItemId(cursor),
itemRepository.equalCategoryId(categoryId))
itemRepository.equalCategoryId(categoryId),
wishRepository.equalMemberId(memberId))
.orderBy(wish.createdAt.desc())
.limit(size + 1)
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.querydsl.core.types.dsl.BooleanExpression;

@Repository
public interface WishRepository extends JpaRepository<Wish, Long> {

default BooleanExpression equalMemberId(Long memberId) {
if (memberId == null) {
return null;
}
return QWish.wish.member.id.eq(memberId);
}

void deleteByItemId(Long itemId);

boolean existsByMemberIdAndItemId(Long memberId, Long itemId);

List<Wish> findAllByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -190,7 +191,8 @@ public void readMessagesWithTimeout() throws Exception {
// then
mockMvc.perform(asyncDispatch(asyncListener))
.andExpect(status().isOk())
.andExpect(jsonPath("statusCode").value(equalTo(408)))
.andExpect(jsonPath("message").value(equalTo("새로운 채팅 메시지가 존재하지 않습니다.")));
.andExpect(jsonPath("statusCode").value(equalTo(200)))
.andExpect(jsonPath("message").value(equalTo("새로운 채팅 메시지가 존재하지 않습니다.")))
.andExpect(jsonPath("data").value(equalTo(Collections.emptyList())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void wishListFindAll() {
// when
Long categoryId = null;
Long cursor = null;
ItemResponses responses = wishItemService.findAll(categoryId, 2, cursor);
ItemResponses responses = wishItemService.findAll(categoryId, 2, cursor, Principal.from(member));

// then
List<ItemResponse> contents = responses.getContents();
Expand Down Expand Up @@ -178,7 +178,7 @@ void wishListByCategoryTest() {
wishItemService.changeWishStatus(item3.getId(), member.getId(), WishStatus.YES);

// when
ItemResponses responses = wishItemService.findAll(category1.getId(), 10, null);
ItemResponses responses = wishItemService.findAll(category1.getId(), 10, null, Principal.from(member));

// then
assertThat(responses.getContents()).hasSize(2);
Expand Down

0 comments on commit a9c0522

Please sign in to comment.