From 99dd1ee6a81b9013ac36a96501fb658ddabc1674 Mon Sep 17 00:00:00 2001 From: Ryo Kawaguchi Date: Thu, 18 Apr 2024 23:37:10 +0900 Subject: [PATCH] Add PUT handler for /admin/cidrs endpoint --- server/src/api/admin/cidr.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/src/api/admin/cidr.rs b/server/src/api/admin/cidr.rs index 5716249..74b6d6d 100644 --- a/server/src/api/admin/cidr.rs +++ b/server/src/api/admin/cidr.rs @@ -19,6 +19,11 @@ pub async fn routes( let form = form_body(req).await?; handlers::create(form, session).await }, + (&Method::PUT, Some(id)) => { + let id: i64 = id.parse().map_err(|_| ServerError::NotFound)?; + let form = form_body(req).await?; + handlers::update(id, form, session).await + }, (&Method::DELETE, Some(id)) => { let id: i64 = id.parse().map_err(|_| ServerError::NotFound)?; handlers::delete(id, session).await @@ -43,6 +48,18 @@ mod handlers { json_status_response(cidr, StatusCode::CREATED) } + pub async fn update( + id: i64, + form: CidrContents, + session: Session, + ) -> Result, ServerError> { + let conn = session.context.db.lock(); + let cidr = DatabaseCidr::get(&conn, id)?; + DatabaseCidr::from(cidr).update(&conn, form)?; + + status_response(StatusCode::NO_CONTENT) + } + pub async fn list(session: Session) -> Result, ServerError> { let conn = session.context.db.lock(); let cidrs = DatabaseCidr::list(&conn)?;