Skip to content

feat: add listings endpoint with pagination, filters, and tests#20

Merged
jaykayudo merged 3 commits intoTrajectfi:mainfrom
daveylupes:feat/listings-endpoint-with-pagination-filters-tests
Apr 30, 2025
Merged

feat: add listings endpoint with pagination, filters, and tests#20
jaykayudo merged 3 commits intoTrajectfi:mainfrom
daveylupes:feat/listings-endpoint-with-pagination-filters-tests

Conversation

@daveylupes
Copy link
Contributor

@daveylupes daveylupes commented Apr 30, 2025

Description

Implement the GET /listings endpoint to fetch all active collateral listings in the lending protocol. This endpoint supports pagination and filtering by collateral_contract and borrower_address. Returned fields include listing_id, collateral_contract, collateral_id, borrower_address, loan_amount, loan_duration, created_at, and status.

Related Issue

Fixes #19

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement
  • Code refactoring
  • Documentation update
  • Test coverage improvement
  • CI/CD related changes

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual testing

Tests are located in core/tests/test_listings.py and include:

  • Listing only active records.
  • Filtering by collateral_contract.
  • Filtering by borrower_address.

Run this command for single test of the function implemented;

docker compose run --rm trajectfi pytest core/tests/test_listings.py::test_list_active_listings

Python Dependencies

# New dependencies:
pytest-django = "^4.11.1"

Starknet-Specific Considerations

N/A

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Security Considerations

  • This PR introduces no security concerns
  • This PR modifies authentication/authorization
  • This PR handles sensitive data
  • This PR modifies financial transaction logic

Performance Impact

  • This PR has no significant performance impact
  • This PR improves performance
  • This PR may impact performance negatively (explain why it's necessary)

Copy link
Contributor

@jaykayudo jaykayudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daveylupes Great job so far.
Please attend to the review changes and then this PR is ready to be merged

Comment on lines 241 to 248
listing_id = serializers.UUIDField(source="id", read_only=True)
collateral_contract = serializers.CharField(
source="nft_contract_address", read_only=True
)
collateral_id = serializers.IntegerField(source="nft_token_id", read_only=True)
borrower_address = serializers.CharField(source="user.public_key", read_only=True)
loan_amount = serializers.IntegerField(source="borrow_amount", read_only=True)
loan_duration = serializers.IntegerField(source="duration", read_only=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these attributes. simply defining them in the Meta class fields attribute is okay.

class Meta:
model = Listing
fields = [
"listing_id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lisiting id does not exist in the model. use id instead.

Copy link
Contributor

@jaykayudo jaykayudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me!
Thank you for contributing to this project.

@jaykayudo jaykayudo merged commit 68c5974 into Trajectfi:main Apr 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Endpoint to List Active Collateral Listings

2 participants