Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit d283252

Browse files
merge: #3492
3492: feat(sdf, dal): Restore get_resource endpoint to the system r=stack72 a=stack72 This can't be merged yet because refresh operations overwrite the /root/resource prop which means this will always return an empty resource to the UI Co-authored-by: stack72 <public@paulstack.co.uk>
2 parents 8856b75 + 1ed98c2 commit d283252

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

lib/dal/src/component.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ pub enum ComponentError {
129129
Qualification(#[from] QualificationError),
130130
#[error("ordering node not found for qualifications map {0} and component {1}")]
131131
QualificationNoOrderingNode(AttributeValueId, ComponentId),
132+
#[error("resource attribute value not found for component: {0}")]
133+
ResourceAttributeValueNotFound(ComponentId),
132134
#[error("root attribute value not found for component: {0}")]
133135
RootAttributeValueNotFound(ComponentId),
134136
#[error("schema variant error: {0}")]

lib/dal/src/component/resource.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
33
use serde::{Deserialize, Serialize};
44
use serde_json::Value;
5+
56
use veritech_client::ResourceStatus;
67

8+
use crate::component::ComponentResult;
9+
use crate::func::backend::js_action::ActionRunResult;
10+
use crate::{Component, ComponentId, DalContext};
11+
712
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
813
#[serde(rename_all = "camelCase")]
914
pub struct ResourceView {
@@ -13,3 +18,30 @@ pub struct ResourceView {
1318
pub logs: Vec<String>,
1419
pub last_synced: Option<String>,
1520
}
21+
22+
impl ResourceView {
23+
pub async fn get_by_component_id(
24+
ctx: &DalContext,
25+
component_id: ComponentId,
26+
) -> ComponentResult<Self> {
27+
let component = Component::get_by_id(ctx, component_id).await?;
28+
29+
let resource = Self::assemble(component.resource(ctx).await?)?;
30+
Ok(resource)
31+
}
32+
33+
pub fn assemble(result: ActionRunResult) -> ComponentResult<Self> {
34+
let payload: Value = match result.payload {
35+
Some(payload) => serde_json::from_str::<Value>(&payload)?,
36+
None => Value::Null,
37+
};
38+
39+
Ok(Self {
40+
data: Some(payload),
41+
message: result.message,
42+
status: result.status,
43+
logs: result.logs,
44+
last_synced: result.last_synced,
45+
})
46+
}
47+
}

lib/sdf-server/src/server/service/component.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ use thiserror::Error;
1515
use crate::server::state::AppState;
1616

1717
pub mod delete_property_editor_value;
18+
pub mod get_actions;
1819
pub mod get_diff;
1920
pub mod get_property_editor_schema;
2021
pub mod get_property_editor_validations;
2122
pub mod get_property_editor_values;
22-
pub mod update_property_editor_value;
23-
// pub mod get_resource;
24-
pub mod get_actions;
23+
pub mod get_resource;
2524
pub mod insert_property_editor_value;
2625
pub mod json;
2726
pub mod list_qualifications;
27+
pub mod update_property_editor_value;
2828
// pub mod list_resources;
2929
// pub mod refresh;
3030
// pub mod resource_domain_diff;
@@ -159,6 +159,7 @@ pub fn routes() -> Router<AppState> {
159159
)
160160
.route("/get_code", get(get_code::get_code))
161161
.route("/get_diff", get(get_diff::get_diff))
162+
.route("/get_resource", get(get_resource::get_resource))
162163
.route(
163164
"/update_property_editor_value",
164165
post(update_property_editor_value::update_property_editor_value),

lib/sdf-server/src/server/service/component/get_resource.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use axum::{extract::Query, Json};
2-
use dal::{ComponentId, ResourceView, Visibility};
2+
use dal::component::resource::ResourceView;
3+
use dal::{ComponentId, Visibility};
34
use serde::{Deserialize, Serialize};
45

56
use super::ComponentResult;
@@ -26,6 +27,6 @@ pub async fn get_resource(
2627
) -> ComponentResult<Json<GetResourceResponse>> {
2728
let ctx = builder.build(request_ctx.build(request.visibility)).await?;
2829

29-
let resource = ResourceView::get_by_component_id(&ctx, &request.component_id).await?;
30+
let resource = ResourceView::get_by_component_id(&ctx, request.component_id).await?;
3031
Ok(Json(GetResourceResponse { resource }))
3132
}

0 commit comments

Comments
 (0)