Skip to content

Commit

Permalink
Merge pull request #202 from fresh-trash-project/feature/#201-get-sin…
Browse files Browse the repository at this point in the history
…gle-product-auction
  • Loading branch information
JadeKim042386 authored Aug 19, 2024
2 parents de4c110 + 822c2cd commit 940f25d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM amazoncorretto:17
RUN mkdir -p deploy/imgs
WORKDIR /deploy
COPY ./build/libs/fresh-trash-backend-1.1.1.jar api.jar
COPY ./build/libs/fresh-trash-backend-1.1.2.jar api.jar
ENTRYPOINT ["java", "-jar", "/deploy/api.jar", "--spring.profiles.active=local", "--logging.level.root=error"]
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'freshtrash'
version = '1.1.1'
version = '1.1.2'

java {
sourceCompatibility = '17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public ResponseEntity<Page<AuctionResponse>> getAuctions(
@GetMapping("/{auctionId}")
public ResponseEntity<AuctionResponse> getAuction(@PathVariable Long auctionId) {
AuctionResponse auctionResponse = AuctionResponse.fromEntity(auctionService.getAuction(auctionId));
auctionService.updateViewCount(auctionId);
return ResponseEntity.ok(auctionResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ default void customize(QuerydslBindings bindings, QAuction root) {

@Query(nativeQuery = true, value = "update auctions a set a.auction_status = 'CANCEL' where a.id = ?1")
void cancelAuctionById(Long auctionId);

@Query(nativeQuery = true, value = "update auctions a set a.view_count = a.view_count + 1 where a.id = ?1")
void updateViewCount(Long auctionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void deleteAuction(Long auctionId) {
auctionRepository.deleteById(auctionId);
}

public void updateViewCount(Long auctionId) {
auctionRepository.updateViewCount(auctionId);
}

@Transactional
@Retryable(
value = {ObjectOptimisticLockingFailureException.class, CannotAcquireLockException.class},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class ProductController {
*/
@GetMapping("/{productId}")
public ResponseEntity<ProductResponse> getProduct(@PathVariable Long productId) {
productService.updateViewCount(productId);
ProductResponse productResponse = ProductResponse.fromEntity(productService.getProduct(productId));
productService.updateViewCount(productId);
return ResponseEntity.ok(productResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void given_auctionIdAndLoginUser_when_getAuction_then_returnSingleAuctionData()
// given
Auction auction = Fixture.createAuction();
given(auctionService.getAuction(auction.getId())).willReturn(auction);
willDoNothing().given(auctionService).updateViewCount(auction.getId());
// when
mvc.perform(get("/api/v1/auctions/" + auction.getId()))
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,15 @@ void given_memberIdAndMemberType_when_checkMemberType_then_returnAuctionResponse
// then
assertThat(auctionLogs.getTotalElements()).isEqualTo(1);
}

@DisplayName("경매 상세 정보를 조회하면 viewCount + 1을 해준다.")
@Test
void given_auctionId_when_getAuction_then_increaseViewCount() {
//given
Long auctionId = 1L;
willDoNothing().given(auctionRepository).updateViewCount(auctionId);
//when
auctionService.updateViewCount(auctionId);
//then
}
}

0 comments on commit 940f25d

Please sign in to comment.