Skip to content

Task 2-1: Document và Chuẩn hóa Admin Fee Config

Phase: 2 - Validation Priority: Medium Depends on: Không có Reference: docs/BountyHunter-Backend/details/feature-nft-management/SPEC.md

Background

Admin fee khi renter confirm thuê NFT bị deduct nhưng không rõ fee được lấy từ đâu (hardcoded? config file? DB?). Nếu sai thì owner/renter bị thiệt.

Tasks

DI Note: Nếu chuyển sang config-based, NftRentalOrderService cần thêm @Value("${nft.rental.admin-fee-percent:10}") private int adminFeePercent; — đây là field injection với @Value, không cần constructor injection. Nếu dùng @ConfigurationProperties class thay thế, inject bean đó qua constructor.

  • [ ] Grep để tìm admin fee logic trong toàn bộ application-core/:

    grep -rn "admin_fee\|adminFee\|ADMIN_FEE\|adminFeePercent" application-core/
    

  • [ ] Xác định nguồn config hiện tại:

  • Option A: Hardcoded constant trong service (ví dụ: private static final int ADMIN_FEE_PERCENT = 10;)
  • Option B: Config trong application.yaml (đã externalized)
  • Option C: Lấy từ DB (system config table)

  • [ ] Nếu hardcoded (Option A) → externalize thành config:

    # application-common.yaml
    nft:
      rental:
        admin-fee-percent: 10  # 10% of rental fee; change requires redeploy (Option B) or DB (Option C)
    
    @Value("${nft.rental.admin-fee-percent:10}")
    private int adminFeePercent;
    
    // In confirmNftRental():
    // adminFeePercent được inject từ config — không hardcode
    BigDecimal adminFee = rentalFee.multiply(BigDecimal.valueOf(adminFeePercent))
                                   .divide(BigDecimal.valueOf(100));
    BigDecimal ownerReceives = rentalFee.subtract(adminFee);
    

  • [ ] Document formula trong code comment:

    // Admin fee = rentalFee * adminFeePercent / 100
    // Owner receives = rentalFee - adminFee
    // Renter pays = rentalFee (full amount)
    

  • [ ] Document trong SPEC.md section "Fee Calculation"

Verification / Acceptance Criteria

  • [ ] Không còn hardcoded fee percent trong NftRentalOrderService (hoặc bất kỳ service nào liên quan)
  • [ ] nft.rental.admin-fee-percent tồn tại trong application-common.yaml
  • [ ] Thay đổi config value → fee tính toán thay đổi tương ứng (không cần code change)
  • [ ] Formula rõ ràng trong code comment: owner nhận bao nhiêu, admin giữ bao nhiêu
  • [ ] Unit test: confirm với fee 10%, rentalFee 100 → adminFee = 10, ownerReceives = 90

Files to Modify

  • application-core/service/nft_rental/nft_rental_order/NftRentalOrderService.java
  • application-core/src/main/resources/application-common.yaml (nếu cần)