forge_core_server/routes/
containers.rs1use axum::{
2 Router,
3 extract::{Query, State},
4 response::Json as ResponseJson,
5 routing::get,
6};
7use forge_core_db::models::task_attempt::TaskAttempt;
8use forge_core_deployment::Deployment;
9use forge_core_utils::response::ApiResponse;
10use serde::{Deserialize, Serialize};
11use ts_rs_forge::TS;
12use uuid::Uuid;
13
14use crate::{DeploymentImpl, error::ApiError};
15
16#[derive(Debug, Serialize, TS)]
17pub struct ContainerInfo {
18 pub attempt_id: Uuid,
19 pub task_id: Uuid,
20 pub project_id: Uuid,
21}
22
23#[derive(Debug, Deserialize)]
24pub struct ContainerQuery {
25 #[serde(rename = "ref")]
26 pub container_ref: String,
27}
28
29pub async fn get_container_info(
30 Query(query): Query<ContainerQuery>,
31 State(deployment): State<DeploymentImpl>,
32) -> Result<ResponseJson<ApiResponse<ContainerInfo>>, ApiError> {
33 let pool = &deployment.db().pool;
34
35 let (attempt_id, task_id, project_id) =
36 TaskAttempt::resolve_container_ref(pool, &query.container_ref)
37 .await
38 .map_err(|e| match e {
39 sqlx::Error::RowNotFound => ApiError::Database(e),
40 _ => ApiError::Database(e),
41 })?;
42
43 let container_info = ContainerInfo {
44 attempt_id,
45 task_id,
46 project_id,
47 };
48
49 Ok(ResponseJson(ApiResponse::success(container_info)))
50}
51
52pub fn router(_deployment: &DeploymentImpl) -> Router<DeploymentImpl> {
53 Router::new().route("/containers/info", get(get_container_info))
54}