Skip to content

Commit

Permalink
Merge pull request #138 from daadaadaah/fix/add-validationAmountIsPos…
Browse files Browse the repository at this point in the history
…itive

`InventoryCommandRepository`에 amount 양수 검증 추가
  • Loading branch information
daadaadaah authored Jul 14, 2023
2 parents 1503ebb + 9b3ada0 commit 38eba97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hcommerce.heecommerce.inventory;

public class AmountIsNotPositiveException extends RuntimeException {
public AmountIsNotPositiveException() {
super("수량이 양수인지 확인해주세요");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ public void delete(UUID dealProductUuid) {
}

public int decreaseByAmount(UUID dealProductUuid, int amount) {
validationAmountIsPositive(amount);

String key = super.getRedisKey(dealProductUuid);

return (int) redisStringsRepository.decreaseByAmount(key, Long.valueOf(amount));
}

public void increaseByAmount(UUID dealProductUuid, int amount) {
validationAmountIsPositive(amount);

String key = super.getRedisKey(dealProductUuid);

redisStringsRepository.increaseByAmount(key, Long.valueOf(amount));
}

private void validationAmountIsPositive(int amount) {
if(amount <= 0) {
throw new AmountIsNotPositiveException();
}
}
}

0 comments on commit 38eba97

Please sign in to comment.