-
Notifications
You must be signed in to change notification settings - Fork 2
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
[FEAT] 입찰 기능 추가 #13
[FEAT] 입찰 기능 추가 #13
Conversation
private final MemberRepository memberRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public List<BidResponse> findBidList(Long auction_id) { |
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.
코드 format 을 제꺼랑 맞추면 좋을 것 같아요. 파라미터 부분이요.
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.
public List<BidResponse> findBidList(
Long auction_id
) {
해당 형식으로 바꾸도록 하겠습니다. 감사합니다.
@Transactional(readOnly = true) | ||
public List<BidResponse> findBidList(Long auction_id) { | ||
|
||
AuctionEntity auctionEntity = auctionRepository.findById(auction_id).orElseThrow(); |
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.
예외 부분 제가 수정했으니, 나중에 제꺼 PR 받으면 추가하면 될 것 같아ㅛ.
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.
추후 작업이 더 필요한데 아직 진행하지 않은 사항에 대해서는 TODO를 붙이면 좋을 것 같습니다!
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.
넵 알겠습니다. 앞으로 붙이도록 하겠습니다.
|
||
} | ||
|
||
private boolean checkLastBid(MemberEntity memberEntity, Long bidPrice) { |
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.
DB에서 제일 위에 있는 가격을 꺼내오는 방법말고 더 좋은 방법이 존재할 것 같아요.
예를들어, AuctionEntity에 현재 가격을 저장한다. 이 방법은 저희가 월요일 멘토링 후 수정해야 할 것 같네요
} | ||
|
||
@Transactional | ||
public CreateBidResponse addBid(Long auction_id, Long buyerId, CreateBidRequest createBidRequest) { |
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.
입찰을 추가 할 때 하나의 로직을 더 추가하면 좋을 것 같아요.
AuctionStatus 가 현재 BIDDING 일 때만 addBid가 가능한 걸루
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.
동작하는 것만 생각하고 있었어서 그 부분은 생각을 못 했었네요.
수정에 반영하도록 하겠습니다. 감사합니다.
}) | ||
ResponseEntity<ResultDto<CreateBidResponse>> bidAdd( | ||
@Parameter(description = "입찰 할 경매") | ||
@PathVariable("auction_id") Long auctionId, |
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.
저는 @parameter만 추가했고 @PathVariable, @RequestBody는 Controller에 넣었어요.
만약 코드가 수정이 되면 BidApi, BidController 2군데 다 수정해야해서 불편하므로 Api에는 @parameter 부분만 넣는게 어떨까요
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.
Controller에 있는 대로 다 적어주어야하는 걸로 이해하고 있었는데 제가 잘못 이해하고 있었네요.
반영하도록 하겠습니다. 감사합니다.
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") |
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.
/api/v1/auction
이렇게 수정하면 어떨까요
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.
해당 컨트롤러의 경우 **Bid
**가 기능의 주체인 경우라서 /api/v1/bid로 가는게 어떨까 싶어요
아래의 GetMapping도 auction
이 따로 들어가지 않고 /{auction_id}만 받아서 처리할 수 있을것 같은데
한가지 걸리는건 auction_id가 bid의 자원이 아니라서 /api/v1/bid/{auction_id}로 처리해도 옳은건지가 헷갈리네요 ㅋㅋㅋ....
|
||
List<BidResponse> bidList = bidService.findBidList(auction_id); | ||
|
||
ResultDto<List<BidResponse>> resultDto = new ResultDto<>( |
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.
Response 하는 부분도 수정했으니 제가 월요일에 설명드리겠습니다
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.
넵 알겠습니다.
|
||
@Entity | ||
@Getter | ||
@Table(name = "bids") |
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.
@entity(name = "bids") 로 모든 Entity 를 통일하는게 어떨까요
@Getter | ||
@Table(name = "bids") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) |
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.
이건 뭔가요..?
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.
TimeTrackableEntity 를 상속 받을 필요는 없다고 생각해서
createdAt 필드를 만들고 자동으로 값을 넣어주기 위해 사용했습니다.
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.
create_at만 담당하는 추상 클래스를 만들어서 해당 클래스를 상속받도록 수정하면 좋을 것 같아요~
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.
넵 알겠습니다.
AuctionEntity auctionEntity = auctionRepository.findById(auction_id) | ||
.orElseThrow(() -> new RuntimeException("Auction not found")); | ||
|
||
if (!checkLastBid(memberEntity, createBidRequest.getBidPrice())) { |
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.
바로 이전에 내가 입찰을 했으면 입찰 연속으로 못하는 예외는 있나요?
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.
코드에 반영하도록 하겠습니다. 감사합니다.
@Column(name = "bid_price") | ||
private Long bidPrice; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) |
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.
Cascade 부분 설명 부탁드립니다!!
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.
AuctionEntity 해당 엔티티에 변경이 되면 관련된 BidEntity도 반영되어야 한다고 생각해서 했습니다.
수정
|
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.
리뷰 중간에 새로운 push가 들어와서 기존에 작성하던 내용 먼저 남깁니다~
확인 부탁드려요!
@Transactional(readOnly = true) | ||
public List<BidResponse> findBidList(Long auction_id) { | ||
|
||
AuctionEntity auctionEntity = auctionRepository.findById(auction_id).orElseThrow(); |
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.
추후 작업이 더 필요한데 아직 진행하지 않은 사항에 대해서는 TODO를 붙이면 좋을 것 같습니다!
return bidRepository.findALlByAuctionEntity(auctionEntity).stream() | ||
.sorted(Comparator.comparing(BidEntity::getCreatedAt).reversed()) | ||
.map(BidResponse::toDto) | ||
.toList(); |
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.
해당 부분을 service까지 끌고와서 sorting하지 않고 DB에서 처리해서 가져오기로 했던걸로 기억하는데 아직 수정이 안된걸까요?
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.
내부적으로는 그렇게 했었고 추후 멘토링과정에서 '변경이 있을까' 라는 생각에서 남겨두게 되었습니다.
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.
내부적으로는 DB단에서 하기로 했었습니다만 멘토링과정에서 다르게 될 여지도 있다고 생각해서 이후에 수정하는게 맞다고 생각했습니다.
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.
좋습니다! 오늘 멘토링 이후에 수정하도록 하죠!
BidEntity beforeBidEntity = bidRepository.findTopByMemberEntityOrderByBidPriceDesc(memberEntity); | ||
|
||
if (beforeBidEntity != null) { | ||
return beforeBidEntity.getBidPrice() < bidPrice; | ||
} |
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.
repository에서 데이터를 조회하는 경우 null이 존재할 수 있다면 entity를 바로 가져오는 것보다는 Optional로 감싸서 받아오는게 좋다고 생각합니다.
현재 로직은 간단해서 문제가 되지 않지만 추후 로직이 복잡해진다면 사람이 실수할 수 있는 내용이라서요!
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
LocalDateTime createdAt | ||
) { | ||
public static BidResponse toDto(BidEntity bidEntity) { |
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.
public static BidResponse toDto(BidEntity bidEntity) {
return new BidResponse(
bidEntity.getMemberEntity().getMemberId(),
bidEntity.getBidPrice(),
bidEntity.getCreatedAt()
);
}
해당 코드는 매개변수가 한 눈에 들어올수 있도록 이런식으로 수정하면 좋을 것 같아요!
Long bidPrice, | ||
LocalDateTime createAt | ||
) { | ||
public static CreateBidResponse toDto(BidEntity bidEntity) { |
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.
위의 리뷰과 마찬가지 입니다~
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") |
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.
해당 컨트롤러의 경우 **Bid
**가 기능의 주체인 경우라서 /api/v1/bid로 가는게 어떨까 싶어요
아래의 GetMapping도 auction
이 따로 들어가지 않고 /{auction_id}만 받아서 처리할 수 있을것 같은데
한가지 걸리는건 auction_id가 bid의 자원이 아니라서 /api/v1/bid/{auction_id}로 처리해도 옳은건지가 헷갈리네요 ㅋㅋㅋ....
What is this PR? 🔍
Changes 📝
DateTimeFormat -> JsonFormat
Precaution
✔️ Please check if the PR fulfills these requirements
develop
branch unconditionally?main
?