From 494c54357d98ac70bb115fac54d15795fd7f4d69 Mon Sep 17 00:00:00 2001 From: wonseok Date: Sat, 25 Jan 2025 22:52:34 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=90=9B=20Fix=20endTime=20updating?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/toyProject7/karrot/auction/service/AuctionService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt index 37928ea..275d1cb 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt @@ -40,7 +40,7 @@ class AuctionService( 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 From 6b6568c925ca9c92a494d618e586b269888e462d Mon Sep 17 00:00:00 2001 From: wonseok Date: Sat, 25 Jan 2025 22:56:34 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=A8=20Add=20AuctionOverException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/toyProject7/karrot/auction/AuctionException.kt | 6 ++++++ .../toyProject7/karrot/auction/service/AuctionService.kt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt b/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt index 46e0d2a..72eb46f 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt @@ -28,3 +28,9 @@ class AuctionBadPriceException : AuctionException( httpStatusCode = HttpStatus.BAD_REQUEST, msg = "Your price is lower than current price", ) + +class AuctionOverException : AuctionException( + errorCode = 0, + httpStatusCode = HttpStatus.BAD_REQUEST, + msg = "Over auction time", +) diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt index 275d1cb..a609ad6 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt @@ -4,6 +4,7 @@ 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.controller.Auction import com.toyProject7.karrot.auction.controller.AuctionMessage @@ -32,6 +33,9 @@ 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() } From 6a6392d2534fb10b7574800a34f8673f6f2ee23e Mon Sep 17 00:00:00 2001 From: wonseok Date: Sat, 25 Jan 2025 23:15:08 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=94=A8=20Add=20a=20minimum=20unit=20c?= =?UTF-8?q?onstraint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/toyProject7/karrot/auction/AuctionException.kt | 8 +++++++- .../toyProject7/karrot/auction/service/AuctionService.kt | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt b/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt index 72eb46f..ece7a16 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/AuctionException.kt @@ -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, diff --git a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt index a609ad6..b1cca54 100644 --- a/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/auction/service/AuctionService.kt @@ -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 @@ -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) From 60690841734377e7f259f8a6951e8c62aa0be110 Mon Sep 17 00:00:00 2001 From: wonseok Date: Sun, 26 Jan 2025 13:39:58 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=94=A8=20Fix=20postReview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/controller/ReviewController.kt | 12 +++---- .../karrot/review/service/ReviewService.kt | 32 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/review/controller/ReviewController.kt b/src/main/kotlin/com/toyProject7/karrot/review/controller/ReviewController.kt index a5c1aec..1097603 100644 --- a/src/main/kotlin/com/toyProject7/karrot/review/controller/ReviewController.kt +++ b/src/main/kotlin/com/toyProject7/karrot/review/controller/ReviewController.kt @@ -1,10 +1,7 @@ package com.toyProject7.karrot.review.controller import com.toyProject7.karrot.review.service.ReviewService -import com.toyProject7.karrot.user.AuthUser -import com.toyProject7.karrot.user.controller.User import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController @@ -13,13 +10,11 @@ import org.springframework.web.bind.annotation.RestController class ReviewController( private val reviewService: ReviewService, ) { - @PostMapping("/api/{sellerNickname}/review") + @PostMapping("/api/review/post") fun createReview( @RequestBody request: ReviewCreateRequest, - @PathVariable sellerNickname: String, - @AuthUser user: User, ): ResponseEntity { - val review = reviewService.createReview(sellerNickname, user.nickname, request.content, request.location) + val review = reviewService.createReview(request) return ResponseEntity.status(201).body(review) } } @@ -27,6 +22,9 @@ class ReviewController( data class ReviewCreateRequest( val content: String, val location: String, + val isWritedByBuyer: Boolean, + val sellerId: String, + val buyerId: String, ) typealias ReviewCreateResponse = Review diff --git a/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt b/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt index bc74bcd..4b754cd 100644 --- a/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt @@ -3,9 +3,9 @@ package com.toyProject7.karrot.review.service import com.toyProject7.karrot.profile.service.ProfileService import com.toyProject7.karrot.review.ReviewContentLengthOutOfRangeException import com.toyProject7.karrot.review.controller.Review +import com.toyProject7.karrot.review.controller.ReviewCreateRequest import com.toyProject7.karrot.review.persistence.ReviewEntity import com.toyProject7.karrot.review.persistence.ReviewRepository -import com.toyProject7.karrot.user.controller.User import com.toyProject7.karrot.user.service.UserService import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -18,36 +18,32 @@ class ReviewService( private val profileService: ProfileService, ) { @Transactional - fun createReview( - sellerNickname: String, - buyerNickname: String, - content: String, - location: String, - ): Review { - validateContent(content) + fun createReview(request: ReviewCreateRequest): Review { + validateContent(request.content) - val sellerEntity = userService.getUserEntityByNickname(sellerNickname) - val seller = User.fromEntity(sellerEntity) - val sellerProfileEntity = profileService.getProfileEntityByUserId(seller.id) + val sellerEntity = userService.getUserEntityById(request.sellerId) + val sellerProfileEntity = profileService.getProfileEntityByUserId(request.sellerId) - val buyerEntity = userService.getUserEntityByNickname(buyerNickname) - val buyer = User.fromEntity(buyerEntity) - val buyerProfileEntity = profileService.getProfileEntityByUserId(buyer.id) + val buyerEntity = userService.getUserEntityById(request.buyerId) + val buyerProfileEntity = profileService.getProfileEntityByUserId(request.buyerId) val reviewEntity = ReviewEntity( seller = sellerEntity, buyer = buyerEntity, - content = content, - location = location, + content = request.content, + location = request.location, createdAt = Instant.now(), updatedAt = Instant.now(), ).let { reviewRepository.save(it) } - sellerProfileEntity.reviews += reviewEntity - buyerProfileEntity.reviews += reviewEntity + if (request.isWritedByBuyer) { + sellerProfileEntity.reviews += reviewEntity + } else { + buyerProfileEntity.reviews += reviewEntity + } return Review.fromEntity(reviewEntity) } From a438b32bc0ce664c9ae2f8a242af0c7459e0f45e Mon Sep 17 00:00:00 2001 From: wonseok Date: Sun, 26 Jan 2025 14:01:36 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=94=A8=20Fix=20gerPreviousReviews=20i?= =?UTF-8?q?n=20ProfileService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../karrot/profile/service/ProfileService.kt | 9 ++++++++- .../karrot/review/service/ReviewService.kt | 11 ----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt b/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt index ade0f9b..657c8b8 100644 --- a/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt @@ -122,7 +122,14 @@ class ProfileService( nickname: String, reviewId: Long, ): List { - return reviewService.getPreviousReviews(nickname, reviewId) + val userEntity = userService.getUserEntityByNickname(nickname) + val profileEntity = profileRepository.findByUserId(userEntity.id!!) ?: throw ProfileNotFoundException() + + return profileEntity.reviews + .filter { it.id!! < reviewId } + .sortedByDescending { it.createdAt } + .take(10) + .map { Review.fromEntity(it) } } fun getItemCount(id: String): Int { diff --git a/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt b/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt index 4b754cd..8b84c84 100644 --- a/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/review/service/ReviewService.kt @@ -48,17 +48,6 @@ class ReviewService( return Review.fromEntity(reviewEntity) } - @Transactional - fun getPreviousReviews( - nickname: String, - reviewId: Long, - ): List { - return reviewRepository.findTop10BySellerNicknameOrBuyerNicknameAndIdBeforeOrderByCreatedAtDesc(nickname, nickname, reviewId).map { - reviewEntity -> - Review.fromEntity(reviewEntity) - } - } - private fun validateContent(content: String) { if (content.isBlank()) { throw ReviewContentLengthOutOfRangeException() From 7e6ac607a0d12dbd3d909b5630f31f7c9c98a210 Mon Sep 17 00:00:00 2001 From: wonseok Date: Sun, 26 Jan 2025 14:06:27 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=94=A8=20Fix=20ChatRoomResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../karrot/chatRoom/controller/ChatRoomController.kt | 3 +-- .../com/toyProject7/karrot/chatRoom/service/ChatRoomService.kt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/chatRoom/controller/ChatRoomController.kt b/src/main/kotlin/com/toyProject7/karrot/chatRoom/controller/ChatRoomController.kt index a59256e..e60745e 100644 --- a/src/main/kotlin/com/toyProject7/karrot/chatRoom/controller/ChatRoomController.kt +++ b/src/main/kotlin/com/toyProject7/karrot/chatRoom/controller/ChatRoomController.kt @@ -1,6 +1,5 @@ package com.toyProject7.karrot.chatRoom.controller -import com.toyProject7.karrot.article.controller.Article import com.toyProject7.karrot.chatRoom.service.ChatRoomService import com.toyProject7.karrot.user.AuthUser import com.toyProject7.karrot.user.controller.User @@ -54,6 +53,6 @@ data class CreateChatRoomRequest( ) data class ChatRoomResponse( - val article: Article, + val chatRoom: ChatRoom, val messages: List, ) diff --git a/src/main/kotlin/com/toyProject7/karrot/chatRoom/service/ChatRoomService.kt b/src/main/kotlin/com/toyProject7/karrot/chatRoom/service/ChatRoomService.kt index d48f556..6119a59 100644 --- a/src/main/kotlin/com/toyProject7/karrot/chatRoom/service/ChatRoomService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/chatRoom/service/ChatRoomService.kt @@ -74,7 +74,7 @@ class ChatRoomService( ) val messages = chatMessageEntities.map { chatMessageEntity -> ChatMessage.fromEntity(chatMessageEntity) } return ChatRoomResponse( - article = chatRoom.article, + chatRoom = chatRoom, messages = messages, ) }