feat: Implement module update functionality with a new API endpoint, client method, and @hello-pangea/dnd dependency.
This commit is contained in:
@@ -880,3 +880,33 @@ pub async fn get_course_outline(
|
||||
modules: modules_with_lessons,
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn update_module(
|
||||
claims: common::auth::Claims,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(payload): Json<serde_json::Value>,
|
||||
) -> Result<Json<Module>, StatusCode> {
|
||||
let title = payload.get("title").and_then(|t| t.as_str());
|
||||
let position = payload.get("position").and_then(|v| v.as_i64()).map(|v| v as i32);
|
||||
|
||||
let updated_module = sqlx::query_as::<_, Module>(
|
||||
"UPDATE modules
|
||||
SET title = COALESCE($1, title),
|
||||
position = COALESCE($2, position)
|
||||
WHERE id = $3 RETURNING *"
|
||||
)
|
||||
.bind(title)
|
||||
.bind(position)
|
||||
.bind(id)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!("Update module failed: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
log_action(&pool, claims.sub, "UPDATE", "Module", id, json!(payload)).await;
|
||||
|
||||
Ok(Json(updated_module))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
pub async fn update_module(
|
||||
claims: common::auth::Claims,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(payload): Json<serde_json::Value>,
|
||||
) -> Result<Json<Module>, StatusCode> {
|
||||
let title = payload.get("title").and_then(|t| t.as_str());
|
||||
let position = payload.get("position").and_then(|v| v.as_i64()).map(|v| v as i32);
|
||||
|
||||
let updated_module = sqlx::query_as::<_, Module>(
|
||||
"UPDATE modules
|
||||
SET title = COALESCE($1, title),
|
||||
position = COALESCE($2, position)
|
||||
WHERE id = $3 RETURNING *"
|
||||
)
|
||||
.bind(title)
|
||||
.bind(position)
|
||||
.bind(id)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!("Update module failed: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
log_action(&pool, claims.sub, "UPDATE", "Module", id, json!(payload)).await;
|
||||
|
||||
Ok(Json(updated_module))
|
||||
}
|
||||
@@ -42,6 +42,7 @@ async fn main() {
|
||||
.route("/courses/{id}/outline", get(handlers::get_course_outline))
|
||||
.route("/courses/{id}/analytics", get(handlers::get_course_analytics))
|
||||
.route("/modules", get(handlers::get_modules).post(handlers::create_module))
|
||||
.route("/modules/{id}", axum::routing::put(handlers::update_module))
|
||||
.route("/lessons", get(handlers::get_lessons).post(handlers::create_lesson))
|
||||
.route("/lessons/{id}", get(handlers::get_lesson).put(handlers::update_lesson))
|
||||
.route("/lessons/{id}/transcribe", post(handlers::process_transcription))
|
||||
|
||||
Reference in New Issue
Block a user