Skip to content

Commit

Permalink
fix: 입찰 이력이 없을 때 입찰 가능 횟수가 0으로 표시되는 문제 수정 (#70)
Browse files Browse the repository at this point in the history
* fix: 로그인 한 상태에서 입찰 가능 횟수 버그 수정

- 한번도 입찰 안한상태에서 입찰 횟수가 0으로 나오는 버그 해결
- default 값을 0에서 3으로 변경

CHZZ-118

* test: 로그인 한 상태에서 입찰 가능 횟수 버그 수정으로 인한 테스트코드 수정

- 비로그인 상태에서 호출시 테스트 코드 추가
- 기존 테스트 코드에서 remainingBidCount 검증 추가

CHZZ-118

* chore: Redis 자동 구성을 제외하고 RedisConfig 설정 수정

CHZZ-118

* chore: .yml Redis 리포지토리 비활성화 추가

CHZZ-118

* feat: 경매 종료 임시 테스트 API 작성

CHZZ-118

* chore: branch Name feat/* 로만 허용

CHZZ-118

* refactor: BidOrder enum에서 'AMOUNT'의 name을 'bid-amount'로 변경

- bidAmount -> bid-amount 로 변경

CHZZ-118

* test: BidOrder enum에서 'AMOUNT'의 name 변경으로 인한 테스트 수정

- bidAmount -> bid-amount 로 변경

CHZZ-118
  • Loading branch information
junest66 authored Oct 3, 2024
1 parent 9a6b913 commit 2cc52a7
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-title-and-branch-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
else
echo "❌ Branch name does not follow the conventional pattern."
echo "Ensure your branch name follows one of these formats:"
echo "- feat/*, fix/*, docs/*, refactor/*, style/*, test/*, chore/*, design/*, move/*"
echo "- feat/*"
echo "- release/x.x.x (Semantic Versioning format)"
echo "- hotfix/x.x.x (Semantic Versioning format)"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/chzz/market/common/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.chzz.market.domain.notification.service.RedisSubscriber;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
Expand All @@ -15,6 +17,7 @@
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@EnableAutoConfiguration(exclude = RedisAutoConfiguration.class)
public class RedisConfig {
@Value("${spring.data.redis.host}")
private String host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.chzz.market.domain.auction.service.AuctionService;
import org.chzz.market.domain.auction.service.register.AuctionRegistrationService;
import org.chzz.market.domain.auction.type.AuctionViewType;
import org.chzz.market.domain.auction.type.TestService;
import org.chzz.market.domain.bid.service.BidService;
import org.chzz.market.domain.product.entity.Product.Category;
import org.springframework.data.domain.Page;
Expand All @@ -42,6 +43,7 @@
public class AuctionController {
private final AuctionService auctionService;
private final BidService bidService;
private final TestService testService;
private final AuctionRegistrationServiceFactory registrationServiceFactory;

/**
Expand Down Expand Up @@ -166,4 +168,16 @@ public ResponseEntity<StartAuctionResponse> startAuction(@LoginUser Long userId,
log.info("경매 상품으로 성공적으로 전환되었습니다. 상품 ID: {}", response.productId());
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

// ---------------------------------------------------------------------------------------

/**
* 경매 종료 테스트 API (삭제 필요)
*/
@PostMapping("/test")
public ResponseEntity<?> testEndAuction(@LoginUser Long userId,
@RequestParam("minutes") int minutes) {
testService.test(userId, minutes);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Optional<AuctionDetailsResponse> findAuctionDetailsById(Long auctionId, L
bid.id.isNotNull(),
bid.id,
bid.amount.coalesce(0L),
bid.count.coalesce(0)
bid.count.coalesce(3)
))
.from(auction)
.join(auction.product, product)
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/org/chzz/market/domain/auction/type/TestService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.chzz.market.domain.auction.type;

import jakarta.transaction.Transactional;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;
import lombok.RequiredArgsConstructor;
import org.chzz.market.domain.auction.entity.Auction;
import org.chzz.market.domain.auction.repository.AuctionRepository;
import org.chzz.market.domain.image.entity.Image;
import org.chzz.market.domain.image.repository.ImageRepository;
import org.chzz.market.domain.product.entity.Product;
import org.chzz.market.domain.product.entity.Product.Category;
import org.chzz.market.domain.product.repository.ProductRepository;
import org.chzz.market.domain.user.entity.User;
import org.chzz.market.domain.user.repository.UserRepository;
import org.springframework.stereotype.Service;

/**
* 경매종료 테스트 서비스 삭제필요
*/
@Service
@RequiredArgsConstructor
public class TestService {
private final AuctionRepository auctionRepository;
private final ProductRepository productRepository;
private final ImageRepository imageRepository;
private final UserRepository userRepository;

@Transactional
public void test(Long userId, int minutes) {
Random random = new Random();
int randomIndex = random.nextInt(1000) + 1; // 1부터 1000까지 랜덤 숫자 생성
int randomIndex1 = random.nextInt(1000) + 1; // 1부터 1000까지 랜덤 숫자 생성
User user = userRepository.findById(userId).get();
Product product = Product.builder()
.name("테스트" + randomIndex)
.description("test")
.category(Category.ELECTRONICS)
.user(user)
.minPrice(10000)
.build();
productRepository.save(product);

Image image1 = Image.builder()
.cdnPath("https://picsum.photos/id/" + randomIndex + "/200/200")
.product(product)
.build();
Image image2 = Image.builder()
.cdnPath("https://picsum.photos/id/" + randomIndex1 + "/200/200")
.product(product)
.build();
imageRepository.save(image1);
imageRepository.save(image2);
product.addImages(List.of(image1, image2));
auctionRepository.save(Auction.builder()
.status(AuctionStatus.PROCEEDING)
.endDateTime(LocalDateTime.now().plusMinutes(minutes))
.product(product)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static NumberExpression<Integer> timeRemaining() {
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum BidOrder implements QuerydslOrder {
AMOUNT("bidAmount", bid.amount.asc()),
AMOUNT("bid-amount", bid.amount.asc()),
TIME_REMAINING("time-remaining", auction.endDateTime.desc());

private final String name;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ spring:
redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
repositories:
enabled: false

security:
oauth2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void testFindAuctionDetailsById_OtherUser_NotParticipating() throws Excep
assertThat(result.get().getBidAmount()).isEqualTo(0);
assertThat(result.get().getIsParticipated()).isFalse();
assertThat(result.get().getBidId()).isNull();
assertThat(result.get().getRemainingBidCount()).isEqualTo(3);
}

@Test
Expand All @@ -233,6 +234,7 @@ public void testFindAuctionDetailsById_OtherUser_Participating() throws Exceptio
assertThat(result.get().getBidAmount()).isEqualTo(6000L);
assertThat(result.get().getIsParticipated()).isTrue();
assertThat(result.get().getBidId()).isEqualTo(bid4.getId());
assertThat(result.get().getRemainingBidCount()).isEqualTo(2);
}

@Test
Expand All @@ -249,6 +251,26 @@ public void testFindAuctionDetailsById_NonExistentAuction() throws Exception {
assertThat(result).isNotPresent();
}

@Test
@DisplayName("경매 상세 조회 - 비로그인 상태에서 조회 할 경우")
public void testAuctionDetailsWhenUserIdIsNull() throws Exception {
//given
Long auctionId = auction2.getId();
Long userId = null;

//when
Optional<AuctionDetailsResponse> result = auctionRepository.findAuctionDetailsById(auctionId, userId);

//then
assertThat(result).isPresent();
assertThat(result.get().getProductId()).isEqualTo(product2.getId());
assertThat(result.get().getIsSeller()).isFalse();
assertThat(result.get().getBidAmount()).isEqualTo(0L);
assertThat(result.get().getIsParticipated()).isFalse();
assertThat(result.get().getBidId()).isNull();
assertThat(result.get().getRemainingBidCount()).isEqualTo(3);
}

@Test
@DisplayName("특정 유저의 경매 목록 조회 - 최신순")
public void testFindMyAuctionsWithNewest() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void testFindBidsByAuctionIdWithWinner() {
bidRepository.saveAll(List.of(bid5, bid6, cancelledBid3));

// given
Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "bidAmount"));
Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "bid-amount"));

// when
Page<BidInfoResponse> bidsForAuction4 = bidRepository.findBidsByAuctionId(auction4.getId(), pageable);
Expand Down

0 comments on commit 2cc52a7

Please sign in to comment.