Changeset View
Changeset View
Standalone View
Standalone View
services/feature-flags/src/service.rs
use crate::config::CONFIG; | use crate::config::CONFIG; | ||||
use crate::constants::{PLATFORM_ANDROID, PLATFORM_IOS}; | use crate::constants::{PLATFORM_ANDROID, PLATFORM_IOS}; | ||||
use crate::database::{DatabaseClient, FeatureConfig, Platform}; | use crate::database::{DatabaseClient, FeatureConfig, Platform}; | ||||
use actix_web::http::header::ContentType; | |||||
use actix_web::{web, App, HttpResponse, HttpServer}; | use actix_web::{web, App, HttpResponse, HttpServer}; | ||||
use comm_services_lib::database::Error; | use comm_services_lib::database::Error; | ||||
use serde::Deserialize; | use serde::{Deserialize, Serialize}; | ||||
use std::collections::HashSet; | use std::collections::HashSet; | ||||
pub struct FeatureFlagsService { | pub struct FeatureFlagsService { | ||||
db: DatabaseClient, | db: DatabaseClient, | ||||
} | } | ||||
impl FeatureFlagsService { | impl FeatureFlagsService { | ||||
pub fn new(db_client: DatabaseClient) -> Self { | pub fn new(db_client: DatabaseClient) -> Self { | ||||
Show All 28 Lines | match Self::enabled_features_set( | ||||
client.get_ref(), | client.get_ref(), | ||||
platform, | platform, | ||||
query.code_version, | query.code_version, | ||||
query.is_staff, | query.is_staff, | ||||
) | ) | ||||
.await | .await | ||||
{ | { | ||||
Ok(features) => { | Ok(features) => { | ||||
let response_body = features.into_iter().collect::<Vec<_>>().join(","); | let response_body = FeaturesResponse { | ||||
HttpResponse::Ok() | enabled_features: features, | ||||
.content_type(ContentType::plaintext()) | }; | ||||
.body(response_body) | HttpResponse::Ok().json(response_body) | ||||
} | } | ||||
_ => HttpResponse::InternalServerError().finish(), | _ => HttpResponse::InternalServerError().finish(), | ||||
} | } | ||||
} | } | ||||
async fn enabled_features_set( | async fn enabled_features_set( | ||||
db: &DatabaseClient, | db: &DatabaseClient, | ||||
platform: Platform, | platform: Platform, | ||||
Show All 34 Lines | feature_config | ||||
Some(feature_config.name) | Some(feature_config.name) | ||||
} else { | } else { | ||||
None | None | ||||
} | } | ||||
}) | }) | ||||
} | } | ||||
} | } | ||||
#[derive(Serialize)] | |||||
struct FeaturesResponse { | |||||
enabled_features: HashSet<String>, | |||||
} | |||||
#[derive(Deserialize, Debug)] | #[derive(Deserialize, Debug)] | ||||
struct FeatureQuery { | struct FeatureQuery { | ||||
code_version: i32, | code_version: i32, | ||||
is_staff: bool, | is_staff: bool, | ||||
platform: String, | platform: String, | ||||
} | } |