Skip to content

Commit

Permalink
Merge pull request #71 from wafflestudio/feat/auction
Browse files Browse the repository at this point in the history
경매 기능 수정사항
  • Loading branch information
ws11222 authored Jan 26, 2025
2 parents 0258994 + 6a6392d commit bfe0bfe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ 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,
msg = "Over auction time",
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +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 @@ -32,15 +34,21 @@ class AuctionService(
@Transactional
fun updatePrice(auctionMessage: AuctionMessage): AuctionMessage {
val auctionEntity = auctionRepository.findByIdOrNull(auctionMessage.auctionId) ?: throw AuctionNotFoundException()
if (Instant.now().isAfter(auctionEntity.endTime)) {
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)

auctionEntity.currentPrice = auctionMessage.price
auctionEntity.bidder = bidder
if (ChronoUnit.MINUTES.between(auctionEntity.endTime, Instant.now()) <= 1) {
auctionEntity.endTime.plus(1, ChronoUnit.MINUTES)
auctionEntity.endTime = Instant.now().plus(1, ChronoUnit.MINUTES)
}

return auctionMessage
Expand Down

0 comments on commit bfe0bfe

Please sign in to comment.