flagrant-api 0.0.2

CLI powered feature-flagging
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use axum::{extract::{Path, State}, Json};
use flagrant::{distributor, models::{environment, feature}};
use flagrant_types::FeatureValue;
use sqlx::SqlitePool;

use crate::errors::ServiceError;

pub async fn get_feature(
    State(pool): State<SqlitePool>,
    Path((environment_id, _ident, feature_name)): Path<(u16, String, String)>,
) -> Result<Json<FeatureValue>, ServiceError> {
    let env = environment::fetch(&pool, environment_id).await?;
    let feature = feature::fetch_by_name(&pool, &env, feature_name).await?;
    let value_type = feature.value_type.clone();
    let variant = distributor::Distributor::new(feature).distribute(&pool, &env).await?;

    Ok(Json(FeatureValue(variant.value, value_type)))
}