Skip to content

Conversation

@clintjeff2
Copy link

feat: Implement GET /projects endpoint with filtering, sorting and pagination

Closes #102

Summary

This PR implements a comprehensive project listing endpoint that allows users to retrieve projects from the platform with advanced filtering, sorting, and pagination capabilities. The endpoint is designed to serve multiple user types including project creators, researchers, and platform users.

Features Implemented

Core Functionality

  • GET /projects endpoint with comprehensive query parameter support
  • Maximum limit of 20 projects per request as specified
  • Default sorting by most recent projects (created_at DESC)

Filtering Options

  • owner_address: Filter projects by owner wallet address
  • active_only: Show only active (non-closed) projects
  • has_bounty: Filter projects with allocated bounties

Sorting Capabilities

  • sort_by: Support for created_at, bounty_amount, and name fields
  • sort_order: Ascending and descending order support
  • Smart default behavior (most recent first)

Pagination

  • limit: 1-20 projects per request with validation
  • offset: Skip mechanism for pagination
  • Proper boundary validation and error handling

Use Cases Covered

  1. Project Creators: View their own projects using owner_address filter
  2. Researchers (Active Projects): Find active projects using active_only=true
  3. Researchers (Bounty Projects): Search for bounty projects using has_bounty=true

Technical Implementation

Files Added/Modified

  • src/http/project/list_projects.rs - Main endpoint implementation
  • src/http/project/domain.rs - Data structures and validation logic
  • src/http/project/mod.rs - Module registration
  • tests/api/list_projects.rs - Comprehensive test suite
  • tests/api/main.rs - Test module registration

Database Integration

  • Optimized SQL queries with proper indexing considerations
  • Support for complex filtering and sorting combinations
  • Efficient pagination implementation

Validation & Error Handling

  • Starknet address validation for owner_address
  • Parameter boundary validation (limit 1-20)
  • Comprehensive error responses with proper HTTP status codes

Testing

Test Coverage

  • 11 comprehensive test cases covering all functionality
  • Validation error testing
  • Edge case handling
  • Database integration testing

How to Test

  1. Prerequisites:

    # Ensure database is set up
    sqlx database create
    sqlx migrate run
    cargo sqlx prepare
  2. Run Tests:

    Run all project listing tests

    cargo test test_list_projects

    Run full test suite

    cargo test

  3. Manual Testing Examples:

    Basic listing

    curl "http://localhost:8000/projects"

    With filtering and pagination

    curl "http://localhost:8000/projects?active_only=true&limit=10&offset=0"

    With sorting

    curl "http://localhost:8000/projects?sort_by=bounty_amount&sort_order=desc"

Quality Assurance

Build & Test Results

  • All tests passing (11/11)
  • Clean release build compilation
  • No warnings or errors
  • Full validation coverage

Code Quality

  • Comprehensive error handling
  • Proper input validation
  • Database transaction safety
  • Clean code architecture

Video Demonstration

Video Upload Area:

output.mp4

The video should demonstrate:

  • Clean build process (cargo build --release)
  • All tests passing (cargo test test_list_projects)
  • Code quality verification (cargo check)

Breaking Changes

None. This is a new endpoint addition with no impact on existing functionality.

Copy link
Contributor

@Abeeujah Abeeujah left a comment

Choose a reason for hiding this comment

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

Hey man, Great Job so far 👏

}
}
Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great Job with the Domain Modelling and Validation.

@@ -0,0 +1,185 @@
use crate::{AppState, Result};
use crate::http::project::{ListProjectsQuery, ListProjectsResponse, ProjectListItem};
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, But there's a CI complaint here, you should Lint and Format your code when you're done, it does you some good. 🪨

assert_eq!(response["projects"][0]["owner_address"], owner1);
assert!(!response["projects"][0]["bounty_amount"].is_null());
assert!(response["projects"][0]["closed_at"].is_null());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests are great, looks extensive enough, for the use cases the handler would cover

total_count,
has_next,
}))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as this goes, a couple of things could be reused, but it's off to a great start. 🪨

@clintjeff2
Copy link
Author

Thanks!

You seem to have taken care of the linting issues. I think it's ready for merge...

@ONEONUORA
Copy link
Contributor

@clintjeff2 Pls fix the conflict

1 similar comment
@ONEONUORA
Copy link
Contributor

@clintjeff2 Pls fix the conflict

@clintjeff2
Copy link
Author

@clintjeff2 Pls fix the conflict

Sorry just saw this. Fixing...

@clintjeff2
Copy link
Author

Fixed!

@ONEONUORA
Copy link
Contributor

Pls format your code

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.

List View For Projects

3 participants