Skip to content
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

Nabi 186 junhyuk feat get my card list #28

Merged
merged 2 commits into from
Nov 11, 2023
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 @@ -91,6 +91,23 @@ public ResponseEntity<SingleResult<CardListResponseDTO<SuggestionAvailableCardRe
return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListResponseDTO));
}

@GetMapping("/{status}/my-cards")
public ResponseEntity<SingleResult<CardListReadPagingResponseDTO>> getMyCardsByStatus(
@RequestHeader(name = "authorization") String token,
@PathVariable CardStatus status,
@RequestParam(required = false) String cursorId,
@RequestParam Integer size
) {
CardListReadPagingResponseDTO cardListReadPagingResponseDTO = cardService.getMyCardsByStatus(
token,
status,
cursorId,
size
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListReadPagingResponseDTO));
}

@DeleteMapping("/{cardId}")
public ResponseEntity<CommonResult> deleteCardById(
@RequestHeader(name = "authorization") String token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.prgrms.nabimarketbe.domain.card.entity.CardStatus;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;
import org.prgrms.nabimarketbe.domain.user.entity.User;

import java.util.List;

Expand All @@ -18,6 +19,13 @@ CardListReadPagingResponseDTO getCardsByCondition(
Integer size
);

CardListReadPagingResponseDTO getMyCardsByStatus(
User user,
CardStatus status,
String cursorId,
Integer size
);

List<SuggestionAvailableCardResponseDTO> getSuggestionAvailableCards(
Long userId,
PriceRange priceRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType;
import org.prgrms.nabimarketbe.domain.user.entity.User;

import java.util.List;

Expand Down Expand Up @@ -65,6 +66,41 @@ public CardListReadPagingResponseDTO getCardsByCondition(
return new CardListReadPagingResponseDTO(cardList, nextCursor);
}

@Override
public CardListReadPagingResponseDTO getMyCardsByStatus(
User user,
CardStatus status,
String cursorId,
Integer size
) {
List<CardListReadResponseDTO> cardList = jpaQueryFactory.select(
Projections.fields(
CardListReadResponseDTO.class,
card.cardId,
card.cardTitle,
item.itemName,
item.priceRange,
card.thumbNailImage.as("thumbNail"),
card.status,
card.createdDate.as("createdAt"),
card.modifiedDate.as("modifiedAt")
)
)
.from(card)
.leftJoin(item).on(card.item.itemId.eq(item.itemId))
.where(
cursorId(cursorId),
card.status.eq(status)
)
.orderBy(card.createdDate.desc()) // 디폴트는 생성일자 최신순 정렬
.limit(size)
.fetch();

String nextCursor = cardList.size() < size ? null : generateCursor(cardList.get(cardList.size() - 1));

return new CardListReadPagingResponseDTO(cardList, nextCursor);
}

@Override
public List<SuggestionAvailableCardResponseDTO> getSuggestionAvailableCards(
Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ public CardListResponseDTO<SuggestionAvailableCardResponseDTO> getSuggestionAvai
return new CardListResponseDTO<>(cardListResponse);
}

@Transactional(readOnly = true)
public CardListReadPagingResponseDTO getMyCardsByStatus(
String token,
CardStatus status,
String cursorId,
Integer size
) {
User user = userRepository.findById(checkService.parseToken(token))
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

return cardRepository.getMyCardsByStatus(
user,
status,
cursorId,
size
);
}

@Transactional
public void deleteCardById(
String token,
Expand Down
Loading