Skip to content

Commit

Permalink
Add PUT handler for /admin/cidrs endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
skywhale committed Apr 18, 2024
1 parent 3c57bad commit 99dd1ee
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/src/api/admin/cidr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,6 +48,18 @@ mod handlers {
json_status_response(cidr, StatusCode::CREATED)
}

pub async fn update(
id: i64,
form: CidrContents,
session: Session,
) -> Result<Response<Body>, 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<Response<Body>, ServerError> {
let conn = session.context.db.lock();
let cidrs = DatabaseCidr::list(&conn)?;
Expand Down

0 comments on commit 99dd1ee

Please sign in to comment.