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 @@ -867,6 +867,7 @@ "http", "once_cell", "rust-lib", + "serde", "tokio", "tracing", "tracing-subscriber", @@ -1708,6 +1709,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 @@ -15,6 +15,7 @@ clap = { version = "4.0", features = ["derive", "env"] } http = "0.2" once_cell = "1.17" +serde = { version = "1.0", features = ["derive"] } rust-lib = { path = "../rust-lib" } tokio = { version = "1.24", features = ["rt-multi-thread", "macros"]} tracing = "0.1" 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,27 +1,41 @@ use crate::config::CONFIG; use crate::database::{DatabaseClient, FeatureConfig, Platform}; -use actix_web::{web, App, HttpServer}; +use actix_web::{web, App, HttpResponse, HttpServer}; use rust_lib::database::Error; +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.to_owned())) + .service( + web::resource("/features") + .route(web::get().to(Self::features_handler)), + ) }) .bind(("localhost", 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, @@ -66,3 +80,11 @@ }) } } + +#[allow(dead_code)] +#[derive(Deserialize, Debug)] +struct FeatureQuery { + code_version: i32, + is_staff: bool, + platform: String, +}