diff --git a/Dockerfile b/Dockerfile index 6ba2ba0..9e51666 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/build.gradle b/build.gradle index afc6d8f..fecc255 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'freshtrash' -version = '1.1.1' +version = '1.1.2' java { sourceCompatibility = '17' diff --git a/src/main/java/freshtrash/freshtrashbackend/domain/auction/controller/AuctionController.java b/src/main/java/freshtrash/freshtrashbackend/domain/auction/controller/AuctionController.java index dab3725..64f4b3e 100644 --- a/src/main/java/freshtrash/freshtrashbackend/domain/auction/controller/AuctionController.java +++ b/src/main/java/freshtrash/freshtrashbackend/domain/auction/controller/AuctionController.java @@ -44,6 +44,7 @@ public ResponseEntity> getAuctions( @GetMapping("/{auctionId}") public ResponseEntity getAuction(@PathVariable Long auctionId) { AuctionResponse auctionResponse = AuctionResponse.fromEntity(auctionService.getAuction(auctionId)); + auctionService.updateViewCount(auctionId); return ResponseEntity.ok(auctionResponse); } diff --git a/src/main/java/freshtrash/freshtrashbackend/domain/auction/repository/AuctionRepository.java b/src/main/java/freshtrash/freshtrashbackend/domain/auction/repository/AuctionRepository.java index e4b09db..d57035c 100644 --- a/src/main/java/freshtrash/freshtrashbackend/domain/auction/repository/AuctionRepository.java +++ b/src/main/java/freshtrash/freshtrashbackend/domain/auction/repository/AuctionRepository.java @@ -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); } diff --git a/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java b/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java index 8656a5a..7e8579d 100644 --- a/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java +++ b/src/main/java/freshtrash/freshtrashbackend/domain/auction/service/AuctionService.java @@ -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}, diff --git a/src/main/java/freshtrash/freshtrashbackend/domain/product/controller/ProductController.java b/src/main/java/freshtrash/freshtrashbackend/domain/product/controller/ProductController.java index 8afb6ff..e3df457 100644 --- a/src/main/java/freshtrash/freshtrashbackend/domain/product/controller/ProductController.java +++ b/src/main/java/freshtrash/freshtrashbackend/domain/product/controller/ProductController.java @@ -39,8 +39,8 @@ public class ProductController { */ @GetMapping("/{productId}") public ResponseEntity getProduct(@PathVariable Long productId) { - productService.updateViewCount(productId); ProductResponse productResponse = ProductResponse.fromEntity(productService.getProduct(productId)); + productService.updateViewCount(productId); return ResponseEntity.ok(productResponse); } diff --git a/src/test/java/freshtrash/freshtrashbackend/controller/AuctionControllerTest.java b/src/test/java/freshtrash/freshtrashbackend/controller/AuctionControllerTest.java index ff9accf..4c3efef 100644 --- a/src/test/java/freshtrash/freshtrashbackend/controller/AuctionControllerTest.java +++ b/src/test/java/freshtrash/freshtrashbackend/controller/AuctionControllerTest.java @@ -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()) diff --git a/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java b/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java index 012c356..52d3320 100644 --- a/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java +++ b/src/test/java/freshtrash/freshtrashbackend/service/AuctionServiceTest.java @@ -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 + } } \ No newline at end of file