diff --git a/services/feature-flags/Cargo.lock b/services/feature-flags/Cargo.lock --- a/services/feature-flags/Cargo.lock +++ b/services/feature-flags/Cargo.lock @@ -789,6 +789,7 @@ "derive_more", "http", "once_cell", + "serde", "tokio", "tracing", "tracing-subscriber", @@ -1580,6 +1581,20 @@ version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" diff --git a/services/feature-flags/Cargo.toml b/services/feature-flags/Cargo.toml --- a/services/feature-flags/Cargo.toml +++ b/services/feature-flags/Cargo.toml @@ -16,6 +16,7 @@ derive_more = "0.99" http = "0.2" once_cell = "1.17" +serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.24", features = ["rt-multi-thread", "macros"]} tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"]} diff --git a/services/feature-flags/src/service.rs b/services/feature-flags/src/service.rs --- a/services/feature-flags/src/service.rs +++ b/services/feature-flags/src/service.rs @@ -1,26 +1,40 @@ use crate::config::CONFIG; use crate::database::{DatabaseClient, Error, FeatureConfig, Platform}; -use actix_web::{web, App, HttpServer}; +use actix_web::{web, App, HttpResponse, HttpServer}; +use serde::Deserialize; use std::collections::HashSet; pub struct FeatureFlagsService { - _db: DatabaseClient, + db: DatabaseClient, } impl FeatureFlagsService { pub fn new(db_client: DatabaseClient) -> Self { - FeatureFlagsService { _db: db_client } + FeatureFlagsService { db: db_client } } pub async fn start(&self) -> std::io::Result<()> { - HttpServer::new(|| { - App::new().service(web::resource("/").to(|| async { "HELLO" })) + let db_clone = self.db.clone(); + HttpServer::new(move || { + App::new() + .app_data(web::Data::new(db_clone.clone())) + .service( + web::resource("/features") + .route(web::get().to(Self::features_handler)), + ) }) .bind(("127.0.0.1", CONFIG.http_port))? .run() .await } + async fn features_handler( + _client: web::Data, + _query: web::Query, + ) -> Result { + Ok(HttpResponse::Ok().body("HELLO")) + } + async fn _enabled_features_set( db: &DatabaseClient, platform: Platform, @@ -65,3 +79,10 @@ }) } } + +#[derive(Deserialize, Debug)] +struct FeatureQuery { + _code_version: i32, + _is_staff: bool, + _platform: String, +}