Skip to content

Commit

Permalink
merge: #3089
Browse files Browse the repository at this point in the history
3089: fix(dal, sdf): Update sdf to return whether the component has codegen or not r=stack72 a=stack72



Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Dec 20, 2023
2 parents 1ad4bb8 + c80b626 commit bfa5a56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/dal/src/component/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Component {
pub async fn list_code_generated(
ctx: &DalContext,
component_id: ComponentId,
) -> ComponentResult<Vec<CodeView>> {
) -> ComponentResult<(Vec<CodeView>, bool)> {
let component = Self::get_by_id(ctx, &component_id)
.await?
.ok_or(ComponentError::NotFound(component_id))?;
Expand Down Expand Up @@ -94,8 +94,10 @@ impl Component {

code_views.push(CodeView::new(language, code, message));
}
} else {
return Ok((vec![], false));
}
Ok(code_views)
Ok((code_views, true))
}

// TODO(nick): big query potential.
Expand Down
2 changes: 1 addition & 1 deletion lib/dal/tests/integration_test/internal/component/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn add_code_generation_and_list_code_views(ctx: &DalContext) {
);

// Ensure the code view looks as we expect it to.
let mut code_views = Component::list_code_generated(ctx, *component.id())
let (mut code_views, _) = Component::list_code_generated(ctx, *component.id())
.await
.expect("could not list code generated for component");
let code_view = code_views.pop().expect("code views are empty");
Expand Down
8 changes: 6 additions & 2 deletions lib/sdf-server/src/server/service/component/get_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct GetCodeRequest {
#[serde(rename_all = "camelCase")]
pub struct GetCodeResponse {
pub code_views: Vec<CodeView>,
pub has_code: bool,
}

pub async fn get_code(
Expand All @@ -26,7 +27,10 @@ pub async fn get_code(
) -> ComponentResult<Json<GetCodeResponse>> {
let ctx = builder.build(request_ctx.build(request.visibility)).await?;

let code_views = Component::list_code_generated(&ctx, request.component_id).await?;
let (code_views, has_code) = Component::list_code_generated(&ctx, request.component_id).await?;

Ok(Json(GetCodeResponse { code_views }))
Ok(Json(GetCodeResponse {
code_views,
has_code,
}))
}

0 comments on commit bfa5a56

Please sign in to comment.