Skip to content

Commit

Permalink
Merge pull request #228 from Team-BC-1/refactor/set-transactional-to-…
Browse files Browse the repository at this point in the history
…class-levels

@transactional 클래스레벨로 리팩토링
  • Loading branch information
vanillacake369 authored Feb 3, 2024
2 parents 0ea114d + 347b618 commit f310c89
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@Service
@RequiredArgsConstructor
@Transactional
public class BuyCommandService {

private final BuyRepository buyRepository;
Expand All @@ -25,16 +26,14 @@ public void deleteBuyByIdAndUser(Buy buy, User buyer) {
buyRepository.delete(buy);
}

public boolean isBuyerLoggedInUser(Buy buy, User user) {
private boolean isBuyerLoggedInUser(Buy buy, User user) {
return buy.getUser().getLoginId().equals(user.getLoginId());
}

@Transactional
public void delete(Buy buy) {
buyRepository.delete(buy);
}

@Transactional
public void deleteBuysOfDeadlineBefore(LocalDateTime dateTime) {
buyRepository.deleteBuysOfDeadlineBefore(dateTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class BuyQueryService {

private final BuyRepository buyRepository;
Expand All @@ -39,7 +40,6 @@ public Buy findBuyById(Long buyId) {
* @param pageable 페이징 요청 데이터
* @return 구매입찰가 내역 페이징 데이터
*/
@Transactional(readOnly = true)
public Page<BuyPriceToQuantityResponseDto> findAllBuyBidsOf(Product product, Pageable pageable) {
return buyRepository.findAllPriceToQuantityOf(product, pageable);
}
Expand All @@ -51,7 +51,6 @@ public Page<BuyPriceToQuantityResponseDto> findAllBuyBidsOf(Product product, Pag
* @param price 구매를 원하는 상품 가격
* @return 구매입찰
*/
@Transactional(readOnly = true)
public Buy getRecentBuyBidOf(Long productId, Long price) {
return buyRepository.findByProductIdAndPrice(productId, price)
.orElseThrow(() -> new GlobalException(BUY_BID_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import bc1.gream.domain.user.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class CouponCommandService {

private final CouponRepository couponRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public List<Coupon> unavailableCouponList(UserDetailsImpl userDetails) {
return couponRepository.unavailable(user);
}

@Transactional(readOnly = true)
public Coupon findCouponById(Long couponId, User user) {
Coupon coupon = couponRepository.findById(couponId).orElseThrow(
() -> new GlobalException(COUPON_NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@

@Service
@RequiredArgsConstructor
@Transactional
public class GifticonCommandService {

private final GifticonRepository gifticonRepository;

@Transactional
public Gifticon saveGifticon(String gifticonUrl, Order order) {
Gifticon gifticon = Gifticon.builder()
.gifticonUrl(gifticonUrl)
.order(order)
.build();
return gifticonRepository.save(gifticon);
}

@Transactional

public void delete(Gifticon gifticon) {
gifticonRepository.delete(gifticon);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GifticonQueryService {

private final GifticonRepository gifticonRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class OrderCommandService {
* @param coupon 쿠폰
* @return 새로운 주문
*/
@Transactional
public Order saveOrderOfBuy(Buy buy, User seller, Coupon coupon) {
Long finalPrice = CouponCalculator.calculateDiscount(coupon, buy.getPrice());
Order order = Order.builder()
Expand All @@ -39,7 +38,6 @@ public Order saveOrderOfBuy(Buy buy, User seller, Coupon coupon) {
return orderRepository.save(order);
}

@Transactional
public Order saveOrderOfBuyNotCoupon(Buy buy, User seller) {

Long finalPrice = buy.getPrice();
Expand All @@ -51,12 +49,10 @@ public Order saveOrderOfBuyNotCoupon(Buy buy, User seller) {
.finalPrice(finalPrice)
.expectedPrice(buy.getPrice())
.build();

return orderRepository.save(order);
}


@Transactional
public Order saveOrderOfSell(Sell sell, User buyer, Coupon coupon) {
Long finalPrice = CouponCalculator.calculateDiscount(coupon, sell.getPrice());

Expand All @@ -71,7 +67,6 @@ public Order saveOrderOfSell(Sell sell, User buyer, Coupon coupon) {
return orderRepository.save(order);
}

@Transactional
public Order saveOrderOfSellNotCoupon(Sell sell, User buyer) {

Long finalPrice = sell.getPrice();
Expand Down

0 comments on commit f310c89

Please sign in to comment.