lfglabs-dev / api.starknet.quest

starknet.quest rust backend
7 stars 28 forks source link

Create New Admin Route `get_boost_winners` #324

Open Marchand-Nicolas opened 2 days ago

Marchand-Nicolas commented 2 days ago

Description 📹

Implement a new admin route get_boost_winners that retrieves the list of winners for a specific boost. This route will allow admin users to fetch the winners based on the boost_id provided. It should be secured using the existing authentication middleware to ensure only authorized admin users can access this information.

Proposed Actions 🛠️

Here’s a checklist of actions to follow for resolving this issue:

  1. Fork and Create Branch:
    Fork the repository and create a new branch using the issue number:

    git checkout -b fix-[issue-number]
  2. Implement Changes:

    • Create the Route: add a new handler in src/endpoints/admin/quest_boost: get_boost_winners.rs

    • Define Request Parameters:

      pub_struct!(Deserialize; GetBoostWinnersParams {
       boost_id: i64,
      });
    • Implement the Handler Logic, which should look something like that:

      #[route(get, "/admin/boosts/get_boost_winners", auth_middleware)]
      pub async fn get_boost_winners_handler(
       State(state): State<Arc<AppState>>,
       Extension(_sub): Extension<String>, // Assuming admin authentication is handled
       Query(params): Query<GetBoostWinnersParams>,
      ) -> impl IntoResponse {
       let collection = state.db.collection::<BoostDocument>("boosts");
      
       let filter = doc! { "id": params.boost_id };
      
       match collection.find_one(filter, None).await {
           Ok(Some(boost_doc)) => (
               StatusCode::OK,
               Json(json!({ "winners": boost_doc.winner })).into_response(),
           ),
           Ok(None) => get_error(format!("Boost with id {} not found", params.boost_id)),
           Err(e) => get_error(format!("Error fetching boost winners: {}", e)),
       }
      }
  3. Run Tests and Commit Changes:

    • Testing:

      • Verify the new route works as expected by testing with valid and invalid boost_id values.
      • Ensure that unauthorized access is correctly blocked by the auth_middleware.
    • Commit Changes:

      git commit -m "Fix: Implement get_boost_winners admin route"

Required 📋

To keep our workflow smooth, please make sure you follow these guidelines:

Thank you for your contribution 🙏

⚠️ WARNING: Failure to follow the requirements above may result in being added to the OnlyDust blacklist, affecting your ability to receive future rewards.

Benjtalkshow commented 2 days ago

Hey @Marchand-Nicolas Please can i work on this ? My ETA is 48hrs. Thanks

anonfedora commented 2 days ago

I'm Eleazar a fullstack Blockchain developer (backend heavy). Can handle this, ETA 72 Hours.