Skip to content

Task 1-1: Guard / Remove Test Endpoints

Phase: 1 Priority: High Module: webmarketplace Depends on: Không có Reference: docs/BountyHunter-Backend/details/feature-nft-management/SPEC.md

Background

NftRentalController có 2 test endpoints không nên tồn tại trên production: 1. PUT /api/nft-rental/finish-rental-order/{id} - manually finish rental (bỏ qua business logic) 2. POST /api/nft-rental/test-change-owner - thay đổi ownership NFT tùy ý

Tasks

DI Note: NftRentalController đã inject NftRentalOrderService (hoặc tương đương) để xử lý requests. @Profile("!main") là Spring annotation — không cần thêm dependency. Chỉ cần import org.springframework.context.annotation.Profile.

File: webmarketplace/controllers/nft_rental/NftRentalController.java

  • [ ] Xác nhận tên Spring profile dùng trên production: thường là main, prod, hoặc production — grep spring.profiles.active trong deployment config hoặc application.yaml để xác nhận
  • [ ] Thêm @Profile("!main") guard cho cả 2 endpoints (thay main bằng profile production thực tế):

    @Profile("!main")  // Chỉ active trên non-production environments
    @PutMapping("/finish-rental-order/{id}")
    public Result<NftRentalOrderModel> finishRental(@PathVariable String id) { ... }
    
    @Profile("!main")  // Chỉ active trên non-production environments
    @PostMapping("/test-change-owner")
    public Result<?> testChangeOwner(...) { ... }
    

  • [ ] Nếu cần trên prod cho admin: move sang admin module với proper admin auth (tách thành task riêng)

  • [ ] Thêm comment giải thích lý do guard:
    // TEST ONLY: Not active on production profile "main"
    @Profile("!main")
    

Verification / Acceptance Criteria

  • [ ] Với spring.profiles.active=mainPUT /api/nft-rental/finish-rental-order/{id} trả 404
  • [ ] Với spring.profiles.active=mainPOST /api/nft-rental/test-change-owner trả 404
  • [ ] Với spring.profiles.active=dev (hoặc non-main) → cả 2 endpoints vẫn hoạt động bình thường
  • [ ] Application khởi động với profile main không lỗi
  • [ ] Code review: không còn test endpoint nào exposed trên production profile

Files to Modify

  • webmarketplace/src/main/java/com/figpop/webmarketplace/controllers/nft_rental/NftRentalController.java