Skip to content

Commit

Permalink
feat: dev2 경매 실패 시 출력 로깅을 추가한다. (#340)
Browse files Browse the repository at this point in the history
* feat: 입찰 실패 시 로깅 메시지 추가

* remove: 사용하지 않는 config 삭제

* feat: ReceiptEntity에서 AuditingListener적용

* refactor: 생성 시간 내림차순으로 정렬하도록 변경

* test: lock시간 / 10 적용 (테스트)

* rollback: 락 시간 원래대로 되돌리기

* test: lock시간 / 10 적용 (테스트)

* feat: sql보이도록 변경

* chore: hibernate 로깅 추가

* remove: 하이버네이트 로깅 삭제
  • Loading branch information
HiiWee authored Aug 29, 2024
1 parent 70f4d4a commit 7ec6cbe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
@Configuration
public class RedisStreamConfig {

@Value("${spring.data.redis.host}")
private String redisHost;

@Value("${spring.data.redis.port}")
private String redisPort;

@Value("${spring.data.redis.password}")
private String redisPassword;

@Getter
@Value("${stream.key}")
private String streamKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private void refund(String messageType, Map<Object, Object> message, Runnable po
var objectMessage = objectMapper.readValue((String) message.get(messageType),
AuctionRefundRequestMessage.class);
auctioneer.refund(objectMessage, postProcess);
} catch (RuntimeException ex) {
log.info("Refund failed : message=" + message.get(messageType));
} catch (RuntimeException e) {
log.warn("Refund failed : message={}, exception={}", message.get(messageType), e.getMessage());
}
}

Expand All @@ -77,6 +77,8 @@ private void purchase(String messageType, Map<Object, Object> message, Runnable
try {
auctioneer.process(objectMessage, postProcess);
} catch (RuntimeException e) {
log.warn("Purchase failed : message={}, exception={}", message.get(messageType), e.getMessage());

// 경매 입찰(구매) 요청이 실패하면 구매 실패 거래 내역을 생성한다.
var command = CreateReceiptCommand.builder()
.requestId(objectMessage.getRequestId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaConfig {

@PersistenceContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.wootecam.luckyvickyauction.domain.entity.type.ReceiptStatus;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
Expand All @@ -11,10 +12,14 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
@Table(name = "RECEIPT")
@Getter
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReceiptEntity {
@Id
Expand All @@ -27,7 +32,9 @@ public class ReceiptEntity {
private long auctionId;
private Long sellerId;
private Long buyerId;
@CreatedDate
private LocalDateTime createdAt;
@LastModifiedDate
private LocalDateTime updatedAt;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public List<ReceiptEntity> findAllByBuyerId(Long buyerId, BuyerReceiptSearchCond
.select(receipt)
.from(receipt)
.where(receipt.buyerId.eq(buyerId))
.orderBy(receipt.id.desc())
.orderBy(receipt.createdAt.desc())
.limit(condition.size())
.offset(condition.offset())
.fetch();
Expand All @@ -35,7 +35,7 @@ public List<ReceiptEntity> findAllBySellerId(Long sellerId, SellerReceiptSearchC
.select(receipt)
.from(receipt)
.where(receipt.sellerId.eq(sellerId))
.orderBy(receipt.id.desc())
.orderBy(receipt.createdAt.desc())
.limit(condition.size())
.offset(condition.offset())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class 거래내역_저장_시에 {
.auctionId(1L)
.sellerId(1L)
.buyerId(2L)
.createdAt(LocalDateTime.now())
.updatedAt(LocalDateTime.now())
.build();

// when
Expand All @@ -98,9 +96,7 @@ class 거래내역_저장_시에 {
() -> assertThat(saved.getReceiptStatus()).isEqualTo(receipt.getReceiptStatus()),
() -> assertThat(saved.getAuctionId()).isEqualTo(receipt.getAuctionId()),
() -> assertThat(saved.getSellerId()).isEqualTo(receipt.getSellerId()),
() -> assertThat(saved.getBuyerId()).isEqualTo(receipt.getBuyerId()),
() -> assertThat(saved.getCreatedAt()).isEqualTo(receipt.getCreatedAt()),
() -> assertThat(saved.getUpdatedAt()).isEqualTo(receipt.getUpdatedAt())
() -> assertThat(saved.getBuyerId()).isEqualTo(receipt.getBuyerId())
);
}

Expand Down

0 comments on commit 7ec6cbe

Please sign in to comment.