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

feat: 판매자는 경매 상품 목록에서 경매 식별자, 원가, 현재 판매가, 총 제고량, 현재 제고량, 시작시간, 종료시간을 확인할 수 있다. #186

Merged
merged 6 commits into from
Aug 15, 2024
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 종료 시간
*/
Comment on lines +5 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

목록에서 필요한 항목만 잘 정의된 것 같아요 ^_^

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())
);
}
}
Loading