-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/58-auction-bid-validate-stock
- Loading branch information
Showing
14 changed files
with
371 additions
and
109 deletions.
There are no files selected for viewing
75 changes: 70 additions & 5 deletions
75
src/main/java/com/wootecam/luckyvickyauction/core/auction/dto/AuctionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,75 @@ | ||
package com.wootecam.luckyvickyauction.core.auction.dto; | ||
|
||
import com.wootecam.luckyvickyauction.global.exception.BadRequestException; | ||
import com.wootecam.luckyvickyauction.global.exception.ErrorCode; | ||
import lombok.Builder; | ||
|
||
/** | ||
* @param sellerId 판매자의 ID | ||
* @param productName 판매상품의 이름 | ||
* @param price 현재 단일 상품의 가격 | ||
* @param quantity 현재 경매에 구매할 수 있는 재고 개수 | ||
* @param sellerId 판매자의 ID | ||
* @param productName 판매상품의 이름 | ||
* @param originPrice 판매상품의 원래 가격 | ||
* @param currentPrice 현재 경매에 설정된 가격 | ||
* @param stock 현재 경매에 남은 재고 개수 | ||
* @param maximumPurchaseLimitCount 최대 구매 가능한 개수 | ||
* @param isShowStock 재고를 보여줄지 여부 | ||
*/ | ||
public record AuctionInfo(Long sellerId, String productName, long price, long quantity) { | ||
@Builder | ||
public record AuctionInfo(Long auctionId, Long sellerId, String productName, long originPrice, long currentPrice, int stock, | ||
int maximumPurchaseLimitCount, boolean isShowStock) { | ||
|
||
public static final String ERROR_PRODUCT_NAME = "상품 이름은 비어있을 수 없습니다."; | ||
public static final String ERROR_ORIGIN_PRICE = "상품 원가는 0보다 커야 합니다. 상품 원가: %d"; | ||
public static final String ERROR_CURRENT_PRICE = "현재 가격은 0보다 커야 합니다. 현재 가격: %d"; | ||
public static final String ERROR_STOCK = "재고는 0보다 작을 수 없습니다. 재고: %d"; | ||
public static final String ERROR_MAXIMUM_PURCHASE_LIMIT_COUNT = "최대 구매 수량 제한은 0보다 커야 합니다. 최대 구매 수량 제한: %d"; | ||
public static final String ERROR_NULL_VALUE = "%s는 Null일 수 없습니다."; | ||
|
||
public AuctionInfo { | ||
validateNotNull(auctionId, "경매 ID"); | ||
validateNotNull(sellerId, "판매자 ID"); | ||
validateNotNull(productName, "상품 이름"); | ||
|
||
validateProductName(productName); | ||
validateOriginPrice(originPrice); | ||
validateCurrentPrice(currentPrice); | ||
validateStock(stock); | ||
validateMaximumPurchaseLimitCount(maximumPurchaseLimitCount); | ||
} | ||
|
||
private void validateProductName(String productName) { | ||
if (productName.isEmpty()) { | ||
throw new BadRequestException(ERROR_PRODUCT_NAME, ErrorCode.A001); | ||
} | ||
} | ||
|
||
private void validateOriginPrice(long originPrice) { | ||
if (originPrice <= 0) { | ||
throw new BadRequestException(String.format(ERROR_ORIGIN_PRICE, originPrice), ErrorCode.A002); | ||
} | ||
} | ||
|
||
private void validateCurrentPrice(long currentPrice) { | ||
if (currentPrice <= 0) { | ||
throw new BadRequestException(String.format(ERROR_CURRENT_PRICE, currentPrice), ErrorCode.A013); | ||
} | ||
} | ||
|
||
private void validateStock(int stock) { | ||
if (stock < 0) { | ||
throw new BadRequestException(String.format(ERROR_STOCK, stock), ErrorCode.A000); | ||
} | ||
} | ||
|
||
private void validateMaximumPurchaseLimitCount(int maximumPurchaseLimitCount) { | ||
if (maximumPurchaseLimitCount <= 0) { | ||
throw new BadRequestException(String.format(ERROR_MAXIMUM_PURCHASE_LIMIT_COUNT, maximumPurchaseLimitCount), | ||
ErrorCode.A003); | ||
} | ||
} | ||
|
||
private void validateNotNull(Object value, String fieldName) { | ||
if (value == null) { | ||
throw new BadRequestException(String.format(ERROR_NULL_VALUE, fieldName), ErrorCode.A007); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/wootecam/luckyvickyauction/core/member/dto/SignInInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.wootecam.luckyvickyauction.core.member.dto; | ||
|
||
import com.wootecam.luckyvickyauction.core.member.domain.Role; | ||
import com.wootecam.luckyvickyauction.global.exception.BadRequestException; | ||
import com.wootecam.luckyvickyauction.global.exception.ErrorCode; | ||
import java.util.Objects; | ||
|
||
public record SignInInfo( | ||
Long id, | ||
Role role | ||
) { | ||
private static final String ERROR_NULL_VALUE = "%s는 Null일 수 없습니다."; | ||
|
||
public SignInInfo { | ||
validateNotNull(id, "로그인한 사용자의 식별자"); | ||
validateNotNull(role, "로그인한 사용자의 역할"); | ||
} | ||
|
||
private void validateNotNull(Object value, String fieldName) { | ||
if (Objects.isNull(value)) { | ||
throw new BadRequestException(String.format(ERROR_NULL_VALUE, fieldName), ErrorCode.G000); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/wootecam/luckyvickyauction/core/member/dto/SignInRequestInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.wootecam.luckyvickyauction.core.member.dto; | ||
|
||
import com.wootecam.luckyvickyauction.global.exception.BadRequestException; | ||
import com.wootecam.luckyvickyauction.global.exception.ErrorCode; | ||
import java.util.Objects; | ||
|
||
public record SignInRequestInfo( | ||
String signInId, | ||
String password | ||
) { | ||
|
||
private static final String ERROR_NULL_VALUE = "%s는 Null일 수 없습니다."; | ||
|
||
public SignInRequestInfo { | ||
validateNotNull(signInId, "로그인 ID"); | ||
validateNotNull(password, "로그인 패스워드"); | ||
} | ||
|
||
private void validateNotNull(Object value, String fieldName) { | ||
if (Objects.isNull(value)) { | ||
throw new BadRequestException(String.format(ERROR_NULL_VALUE, fieldName), ErrorCode.G000); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
src/test/java/com/wootecam/luckyvickyauction/core/auction/domain/ProductTest.java
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
src/test/java/com/wootecam/luckyvickyauction/core/auction/dto/AuctionInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.wootecam.luckyvickyauction.core.auction.dto; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import com.wootecam.luckyvickyauction.global.exception.BadRequestException; | ||
import com.wootecam.luckyvickyauction.global.exception.ErrorCode; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class AuctionInfoTest { | ||
static Stream<Arguments> auctionInfoDtoArguments() { | ||
return Stream.of( | ||
Arguments.of("상품 이름은 비어있을 수 없습니다.", ErrorCode.A001, 1L, 1L, "", 10000, 10000, 10, 10), | ||
Arguments.of("상품 원가는 0보다 커야 합니다. 상품 원가: 0", ErrorCode.A002, 1L, 1L, "상품이름", 0, 10000, 10, 10), | ||
Arguments.of("현재 가격은 0보다 커야 합니다. 현재 가격: 0", ErrorCode.A013, 1L, 1L, "상품이름", 10000, 0, 10, 10), | ||
Arguments.of("재고는 0보다 작을 수 없습니다. 재고: -1", ErrorCode.A000, 1L, 1L, "상품이름", 10000, 10000, -1, 10), | ||
Arguments.of("최대 구매 수량 제한은 0보다 커야 합니다. 최대 구매 수량 제한: 0", ErrorCode.A003, 1L, 1L, "상품이름", 10000, 10000, 10, 0) | ||
); | ||
} | ||
|
||
@Test | ||
void 경매_정보_생성_요청을_정상적으로_처리한다() { | ||
// given | ||
Long auctionId = 1L; | ||
Long sellerId = 1L; | ||
String productName = "상품이름"; | ||
long originPrice = 10000; | ||
long currentPrice = 10000; | ||
int stock = 10; | ||
int maximumPurchaseLimitCount = 10; | ||
|
||
// when | ||
AuctionInfo auctionInfo = new AuctionInfo( | ||
auctionId, sellerId, productName, originPrice, currentPrice, stock, maximumPurchaseLimitCount, true | ||
); | ||
|
||
// then | ||
assertAll( | ||
() -> assertThat(auctionInfo.sellerId()).isEqualTo(sellerId), | ||
() -> assertThat(auctionInfo.productName()).isEqualTo(productName), | ||
() -> assertThat(auctionInfo.originPrice()).isEqualTo(originPrice), | ||
() -> assertThat(auctionInfo.currentPrice()).isEqualTo(currentPrice), | ||
() -> assertThat(auctionInfo.stock()).isEqualTo(stock), | ||
() -> assertThat(auctionInfo.maximumPurchaseLimitCount()).isEqualTo(maximumPurchaseLimitCount), | ||
() -> assertThat(auctionInfo.isShowStock()).isTrue() | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("auctionInfoDtoArguments") | ||
void 경매_정보_생성_요청이_잘못된_경우_예외가_발생한다( | ||
String expectedMessage, | ||
ErrorCode expectedErrorCode, | ||
Long auctionId, | ||
Long sellerId, | ||
String productName, | ||
long originPrice, | ||
long currentPrice, | ||
int stock, | ||
int maximumPurchaseLimitCount | ||
) { | ||
// expect | ||
assertThatThrownBy(() -> new AuctionInfo( | ||
auctionId, sellerId, productName, originPrice, currentPrice, stock, | ||
maximumPurchaseLimitCount, true)) | ||
.isInstanceOf(BadRequestException.class) | ||
.satisfies(exception -> { | ||
assertThat(exception).hasFieldOrPropertyWithValue("errorCode", expectedErrorCode); | ||
}); | ||
} | ||
} |
Oops, something went wrong.