-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/12 : 구매 완료 상품, 판매 완료 상품 조회 #20
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -2,28 +2,59 @@ package com.get_offer.auction.service | |
|
||
import com.get_offer.auction.controller.repository.AuctionResultRepository | ||
import com.get_offer.common.exception.NotFoundException | ||
import com.get_offer.common.exception.UnAuthorizationException | ||
import com.get_offer.product.repository.ProductRepository | ||
import com.get_offer.user.repository.UserRepository | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class AuctionService( | ||
private val productRepository: ProductRepository, | ||
private val auctionRepository: AuctionResultRepository, | ||
private val userRepository: UserRepository, | ||
) { | ||
fun getSellHistory(userId: Long): List<SellProductListDto> { | ||
fun getSellHistory(userId: Long): List<SellAuctionDto> { | ||
val productList = productRepository.findAllByWriterIdOrderByEndDateDesc(userId) | ||
|
||
return productList.map { SellProductListDto.of(it, userId) } | ||
return productList.map { SellAuctionDto.of(it, userId) } | ||
} | ||
|
||
fun getBuyHistory(userId: Long): List<BuyProductListDto> { | ||
fun getBuyHistory(userId: Long): List<BuyAuctionDto> { | ||
// 옥션 최종 정보에서 buyer가 나인걸 찾음 | ||
val auctionResults = auctionRepository.findAllByBuyerIdOrderByCreatedAtDesc(userId) | ||
// 해당 상품 정보를 찾음 | ||
return auctionResults.map { | ||
val product = productRepository.findById(it.productId) | ||
.orElseThrow { NotFoundException("${it.productId} 의 상품은 존재하지 않습니다.") } | ||
BuyProductListDto.of(it, product, userId) | ||
BuyAuctionDto.of(it, product) | ||
} | ||
} | ||
|
||
fun getSoldAuctionDetail(userId: Long, auctionId: Long): SellAuctionDetailDto { | ||
val auction = auctionRepository.findById(auctionId) | ||
.orElseThrow { NotFoundException("$auctionId 의 경매 내역은 존재하지 않습니다.") } | ||
|
||
val product = productRepository.findById(auction.productId) | ||
.orElseThrow { NotFoundException("${auction.productId} 의 상품은 존재하지 않습니다.") } | ||
if (userId != product.writerId) throw UnAuthorizationException() | ||
|
||
val buyer = userRepository.findById(auction.buyerId) | ||
.orElseThrow { NotFoundException("${auction.buyerId} 의 사용자는 존재하지 않습니다.") } | ||
|
||
return SellAuctionDetailDto.of(product, buyer, auction) | ||
} | ||
|
||
fun getBoughtAuctionDetail(userId: Long, auctionId: Long): BuyAuctionDetailDto { | ||
val auction = auctionRepository.findById(auctionId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getSoldAuctionDetail와 중복된 조회 로직은 줄여보시죠 |
||
.orElseThrow { NotFoundException("$auctionId 의 경매 내역은 존재하지 않습니다.") } | ||
if (userId != auction.buyerId) throw UnAuthorizationException() | ||
|
||
val product = productRepository.findById(auction.productId) | ||
.orElseThrow { NotFoundException("${auction.productId} 의 상품은 존재하지 않습니다.") } | ||
|
||
val seller = userRepository.findById(product.writerId) | ||
.orElseThrow { NotFoundException("${product.writerId} 의 사용자는 존재하지 않습니다.") } | ||
|
||
return BuyAuctionDetailDto.of(product, seller, auction) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/get_offer/auction/service/AuctionUserDto.kt
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,19 @@ | ||
package com.get_offer.auction.service | ||
|
||
import com.get_offer.user.domain.User | ||
|
||
data class AuctionUserDto( | ||
val id: Long, | ||
val profileImage: String, | ||
val nickname: String, | ||
) { | ||
companion object { | ||
fun of(user: User): AuctionUserDto { | ||
return AuctionUserDto( | ||
id = user.id, | ||
profileImage = user.image, | ||
nickname = user.nickname | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/get_offer/auction/service/BuyAuctionDetailDto.kt
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.get_offer.auction.service | ||
|
||
import com.get_offer.auction.domain.AuctionResult | ||
import com.get_offer.auction.domain.AuctionStatus | ||
import com.get_offer.product.domain.Product | ||
import com.get_offer.user.domain.User | ||
|
||
data class BuyAuctionDetailDto( | ||
val auctionId: Long, | ||
val auctionStatus: AuctionStatus, | ||
val product: AuctionProductUnitDto, | ||
val seller: AuctionUserDto, | ||
) { | ||
companion object { | ||
fun of(product: Product, seller: User, auction: AuctionResult): BuyAuctionDetailDto { | ||
return BuyAuctionDetailDto( | ||
auctionId = auction.id, | ||
auctionStatus = auction.auctionStatus, | ||
product = AuctionProductUnitDto.of(product), | ||
seller = AuctionUserDto.of(seller), | ||
) | ||
} | ||
} | ||
} |
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/kotlin/com/get_offer/auction/service/SellAuctionDetailDto.kt
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.get_offer.auction.service | ||
|
||
import com.get_offer.auction.domain.AuctionResult | ||
import com.get_offer.auction.domain.AuctionStatus | ||
import com.get_offer.product.domain.Product | ||
import com.get_offer.user.domain.User | ||
|
||
data class SellAuctionDetailDto( | ||
val auctionId: Long, | ||
val auctionStatus: AuctionStatus, | ||
val product: AuctionProductUnitDto, | ||
val buyer: AuctionUserDto, | ||
) { | ||
companion object { | ||
fun of(product: Product, buyer: User, auction: AuctionResult): SellAuctionDetailDto { | ||
return SellAuctionDetailDto( | ||
auctionId = auction.id, | ||
auctionStatus = auction.auctionStatus, | ||
product = AuctionProductUnitDto.of(product), | ||
buyer = AuctionUserDto.of(buyer), | ||
) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id보단 auctionId로 명시적으로 쓰는게 더 좋아보이네요