Skip to content

Commit

Permalink
🔨 Add a minimum unit constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
wonseok committed Jan 25, 2025
1 parent 6b6568c commit 6a6392d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ class AuctionPermissionDeniedException : AuctionException(
msg = "Permission denied",
)

class AuctionBadPriceException : AuctionException(
class AuctionTooLowPriceException : AuctionException(
errorCode = 0,
httpStatusCode = HttpStatus.BAD_REQUEST,
msg = "Your price is lower than current price",
)

class AuctionTooFineUnitExceptions : AuctionException(
errorCode = 0,
httpStatusCode = HttpStatus.BAD_REQUEST,
msg = "Minimum unit is 5% of the start price",
)

class AuctionOverException : AuctionException(
errorCode = 0,
httpStatusCode = HttpStatus.BAD_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.toyProject7.karrot.auction.service

import com.toyProject7.karrot.article.ArticlePermissionDeniedException
import com.toyProject7.karrot.article.controller.UpdateStatusRequest
import com.toyProject7.karrot.auction.AuctionBadPriceException
import com.toyProject7.karrot.auction.AuctionNotFoundException
import com.toyProject7.karrot.auction.AuctionOverException
import com.toyProject7.karrot.auction.AuctionPermissionDeniedException
import com.toyProject7.karrot.auction.AuctionTooFineUnitExceptions
import com.toyProject7.karrot.auction.AuctionTooLowPriceException
import com.toyProject7.karrot.auction.controller.Auction
import com.toyProject7.karrot.auction.controller.AuctionMessage
import com.toyProject7.karrot.auction.controller.PostAuctionRequest
Expand Down Expand Up @@ -37,7 +38,10 @@ class AuctionService(
throw AuctionOverException()
}
if (auctionEntity.currentPrice >= auctionMessage.price) {
throw AuctionBadPriceException()
throw AuctionTooLowPriceException()
}
if ((auctionMessage.price - auctionEntity.currentPrice) % (auctionEntity.startingPrice * 0.05).toInt() != 0) {
throw AuctionTooFineUnitExceptions()
}
val bidder = userService.getUserEntityByNickname(auctionMessage.senderNickname)

Expand Down

0 comments on commit 6a6392d

Please sign in to comment.