crates/server: add jobset input CRUD API routes
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic43064296a4a7eb5a7ee4f52529dae2f6a6a6964
This commit is contained in:
parent
c0df24c6e1
commit
000fb8994f
1 changed files with 65 additions and 5 deletions
|
|
@ -3,7 +3,8 @@ use axum::{
|
|||
extract::{Path, State},
|
||||
routing::get,
|
||||
};
|
||||
use fc_common::{Jobset, UpdateJobset, Validate};
|
||||
use fc_common::{Jobset, JobsetInput, UpdateJobset, Validate};
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::auth_middleware::RequireAdmin;
|
||||
|
|
@ -46,9 +47,68 @@ async fn delete_jobset(
|
|||
Ok(Json(serde_json::json!({ "deleted": true })))
|
||||
}
|
||||
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new().route(
|
||||
"/projects/{project_id}/jobsets/{id}",
|
||||
get(get_jobset).put(update_jobset).delete(delete_jobset),
|
||||
)
|
||||
// --- Jobset input routes ---
|
||||
|
||||
async fn list_jobset_inputs(
|
||||
State(state): State<AppState>,
|
||||
Path((_project_id, jobset_id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<Vec<JobsetInput>>, ApiError> {
|
||||
let inputs = fc_common::repo::jobset_inputs::list_for_jobset(&state.pool, jobset_id)
|
||||
.await
|
||||
.map_err(ApiError)?;
|
||||
Ok(Json(inputs))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CreateJobsetInputRequest {
|
||||
name: String,
|
||||
input_type: String,
|
||||
value: String,
|
||||
revision: Option<String>,
|
||||
}
|
||||
|
||||
async fn create_jobset_input(
|
||||
_auth: RequireAdmin,
|
||||
State(state): State<AppState>,
|
||||
Path((_project_id, jobset_id)): Path<(Uuid, Uuid)>,
|
||||
Json(body): Json<CreateJobsetInputRequest>,
|
||||
) -> Result<Json<JobsetInput>, ApiError> {
|
||||
let input = fc_common::repo::jobset_inputs::create(
|
||||
&state.pool,
|
||||
jobset_id,
|
||||
&body.name,
|
||||
&body.input_type,
|
||||
&body.value,
|
||||
body.revision.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map_err(ApiError)?;
|
||||
Ok(Json(input))
|
||||
}
|
||||
|
||||
async fn delete_jobset_input(
|
||||
_auth: RequireAdmin,
|
||||
State(state): State<AppState>,
|
||||
Path((_project_id, _jobset_id, input_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
fc_common::repo::jobset_inputs::delete(&state.pool, input_id)
|
||||
.await
|
||||
.map_err(ApiError)?;
|
||||
Ok(Json(serde_json::json!({ "deleted": true })))
|
||||
}
|
||||
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route(
|
||||
"/projects/{project_id}/jobsets/{id}",
|
||||
get(get_jobset).put(update_jobset).delete(delete_jobset),
|
||||
)
|
||||
.route(
|
||||
"/projects/{project_id}/jobsets/{jobset_id}/inputs",
|
||||
get(list_jobset_inputs).post(create_jobset_input),
|
||||
)
|
||||
.route(
|
||||
"/projects/{project_id}/jobsets/{jobset_id}/inputs/{input_id}",
|
||||
axum::routing::delete(delete_jobset_input),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue