Skip to content

Commit

Permalink
feat: 판매자는 경매 상품 목록에서 경매 식별자, 원가, 현재 판매가, 총 제고량, 현재 제고량, 시작시간, 종료시간을 …
Browse files Browse the repository at this point in the history
…확인할 수 있다. (#186)

* feat: 판매자 경매 목록 조회 DTO 생성

* feat: Auction to SellerAuctionSimpleInfo Mapper 변환 메서드 구현

- Mapper#convertToSellerAuctionSimpleInfo 구현
- Mapper#convertToSellerAuctionSimpleInfo 테스트 구현

* feat: SellerAuctionSearchCondition 생성

판매자 경매 상품 목록 조회 SQL 조건 dto

* feat: AuctionRepository#findAllBy 구현

- @param SellerAuctionSearchCondition을 가지는 메서드 정의
- FakeAuctionRepository#findAllBy 구현

* feat: AuctionService#getSellerAuctionSimpleInfos 구현

* docs: AuctionService#getSellerAuctionSimpleInfos 주석 추가
  • Loading branch information
yudonggeun authored Aug 15, 2024
1 parent 30e288c commit 2548397
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.wootecam.luckyvickyauction.core.auction.dto;

public record SellerAuctionSearchCondition() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.wootecam.luckyvickyauction.core.auction.dto;

import java.time.ZonedDateTime;

/**
* 판매자 경매 목록 조회시 사용되는 Auction 정보입니다.
*
* @param id 경매 식별자
* @param title 경매 노출 제목
* @param originPrice 원가
* @param currentPrice 현재 가격
* @param totalStock 총 재고
* @param currentStock 현재 남은 재고
* @param startedAt 시작 시간
* @param finishedAt 종료 시간
*/
public record SellerAuctionSimpleInfo(
long id,
String title,
long originPrice,
long currentPrice,
long totalStock,
long currentStock,
ZonedDateTime startedAt,
ZonedDateTime finishedAt
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.wootecam.luckyvickyauction.core.auction.domain.Auction;
import com.wootecam.luckyvickyauction.core.auction.dto.AuctionSearchCondition;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionSearchCondition;
import java.util.List;
import java.util.Optional;

Expand All @@ -13,4 +14,6 @@ public interface AuctionRepository {
void deleteById(long id);

List<Auction> findAllBy(AuctionSearchCondition condition);

List<Auction> findAllBy(SellerAuctionSearchCondition condition);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.wootecam.luckyvickyauction.core.auction.dto.CancelAuctionCommand;
import com.wootecam.luckyvickyauction.core.auction.dto.CreateAuctionCommand;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionInfo;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionSearchCondition;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionSimpleInfo;
import com.wootecam.luckyvickyauction.core.auction.dto.UpdateAuctionCommand;
import com.wootecam.luckyvickyauction.core.auction.dto.UpdateAuctionStockCommand;
import com.wootecam.luckyvickyauction.core.auction.infra.AuctionRepository;
Expand Down Expand Up @@ -134,6 +136,18 @@ public List<BuyerAuctionSimpleInfo> getBuyerAuctionSimpleInfos(AuctionSearchCond
.toList();
}

/**
* 판매자용 경매 목록 조회
*
* @param condition
* @return 판매자용 경매 목록
*/
public List<SellerAuctionSimpleInfo> getSellerAuctionSimpleInfos(SellerAuctionSearchCondition condition) {
return auctionRepository.findAllBy(condition).stream()
.map(Mapper::convertToSellerAuctionSimpleInfo)
.toList();
}

public void changeStock(SignInInfo signInInfo, UpdateAuctionStockCommand command) {
if (!signInInfo.isType(Role.SELLER)) {
throw new UnauthorizedException("판매자만 재고를 수정할 수 있습니다.", ErrorCode.A017);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.wootecam.luckyvickyauction.core.auction.dto.BuyerAuctionInfo;
import com.wootecam.luckyvickyauction.core.auction.dto.BuyerAuctionSimpleInfo;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionInfo;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionSimpleInfo;
import com.wootecam.luckyvickyauction.core.payment.domain.BidHistory;
import com.wootecam.luckyvickyauction.core.payment.dto.BidHistoryInfo;
import com.wootecam.luckyvickyauction.core.payment.dto.BuyerReceiptSimpleInfo;
Expand Down Expand Up @@ -119,4 +120,17 @@ public static BuyerAuctionSimpleInfo convertToBuyerAuctionSimpleInfo(Auction auc
auction.getFinishedAt()
);
}

public static SellerAuctionSimpleInfo convertToSellerAuctionSimpleInfo(Auction auction) {
return new SellerAuctionSimpleInfo(
auction.getId(),
auction.getProductName(),
auction.getOriginPrice(),
auction.getCurrentPrice(),
auction.getOriginStock(),
auction.getCurrentStock(),
auction.getStartedAt(),
auction.getFinishedAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.wootecam.luckyvickyauction.core.auction.domain.Auction;
import com.wootecam.luckyvickyauction.core.auction.dto.AuctionSearchCondition;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionSearchCondition;
import com.wootecam.luckyvickyauction.core.auction.infra.AuctionRepository;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -82,4 +83,12 @@ public List<Auction> findAllBy(AuctionSearchCondition condition) {
.filter(auction -> true)
.toList();
}

// TODO: [SellerAuctionSearchCondition 조건 이후 변경 사항 : FakeRepository의 구현이 condition이 변경되면 수정되어야 합니다.] [writeAt: 2024/08/15/16:30] [writeBy: yudonggeun]
@Override
public List<Auction> findAllBy(SellerAuctionSearchCondition condition) {
return auctions.values().stream()
.filter(auction -> true)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.wootecam.luckyvickyauction.core.auction.domain.Auction;
import com.wootecam.luckyvickyauction.core.auction.domain.PricePolicy;
import com.wootecam.luckyvickyauction.core.auction.dto.BuyerAuctionSimpleInfo;
import com.wootecam.luckyvickyauction.core.auction.dto.SellerAuctionSimpleInfo;
import com.wootecam.luckyvickyauction.core.member.domain.Member;
import com.wootecam.luckyvickyauction.core.payment.domain.BidHistory;
import com.wootecam.luckyvickyauction.core.payment.dto.BuyerReceiptSimpleInfo;
Expand Down Expand Up @@ -77,4 +78,35 @@ class MapperTest {
() -> assertEquals(auction.getFinishedAt(), dto.finishedAt())
);
}

@Test
public void 경매_entity를_SellerAuctionSimpleInfo로_변환하면_도메인의_정보가_동일하게_전달된다() {
// given
Auction auction = Auction.builder()
.id(1L)
.sellerId(1L)
.productName("상품 이름")
.originPrice(1000L)
.currentPrice(1000L)
.currentStock(10L)
.maximumPurchaseLimitCount(1L)
.isShowStock(true)
.pricePolicy(PricePolicy.createConstantPricePolicy(100))
.build();

// when
SellerAuctionSimpleInfo dto = Mapper.convertToSellerAuctionSimpleInfo(auction);

// then
assertAll(
() -> assertEquals(auction.getId(), dto.id()),
() -> assertEquals(auction.getProductName(), dto.title()),
() -> assertEquals(auction.getOriginPrice(), dto.originPrice()),
() -> assertEquals(auction.getCurrentPrice(), dto.currentPrice()),
() -> assertEquals(auction.getOriginStock(), dto.totalStock()),
() -> assertEquals(auction.getCurrentStock(), dto.currentStock()),
() -> assertEquals(auction.getStartedAt(), dto.startedAt()),
() -> assertEquals(auction.getFinishedAt(), dto.finishedAt())
);
}
}

0 comments on commit 2548397

Please sign in to comment.