Update some of the types

This commit is contained in:
J H
2024-03-11 15:37:04 -06:00
parent 4a285225db
commit 99bb55af73
4 changed files with 122 additions and 21 deletions

View File

@@ -530,12 +530,12 @@ pub struct ExposedDependent {
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
#[model = "Model<Self>"]
pub struct ExposedUI {
path: Vec<JsonPointer>,
title: String,
description: Option<String>,
masked: Option<bool>,
copyable: Option<bool>,
qr: Option<bool>,
pub path: JsonPointer,
pub title: String,
pub description: Option<String>,
pub masked: Option<bool>,
pub copyable: Option<bool>,
pub qr: Option<bool>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]

View File

@@ -1,16 +1,41 @@
use clap::Parser;
use imbl_value::{json, Value};
use models::PackageId;
use rpc_toolkit::command;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::context::RpcContext;
use crate::prelude::*;
use crate::Error;
use crate::{context::RpcContext, db::model::ExposedUI};
pub fn display_properties(response: Value) {
println!("{}", response);
}
trait IntoProperties {
fn into_properties(self, store: &Value) -> Value;
}
impl IntoProperties for Vec<ExposedUI> {
fn into_properties(self, store: &Value) -> Value {
let mut data = json!({});
for ui in self {
let value = ui.path.get(store);
data[ui.title] = json!({
"type": "string",
"description": ui.description,
"value": value.map(|x| x.to_string()).unwrap_or_default(),
"copyable": ui.copyable,
"qr": ui.qr,
"masked": ui.masked,
});
}
json!({
"version": 2,
"data": data
})
}
}
#[derive(Deserialize, Serialize, Parser)]
#[serde(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
@@ -22,5 +47,24 @@ pub async fn properties(
ctx: RpcContext,
PropertiesParam { id }: PropertiesParam,
) -> Result<Value, Error> {
Ok(todo!())
let peeked = ctx.db.peek().await;
let data = peeked
.as_public()
.as_package_data()
.as_idx(&id)
.or_not_found(&id)?
.as_installed()
.or_not_found(&id)?
.as_store()
.de()?;
Ok(peeked
.as_public()
.as_package_data()
.as_idx(&id)
.or_not_found(&id)?
.as_installed()
.or_not_found(&id)?
.as_store_exposed_ui()
.de()?
.into_properties(&data))
}