Skip to content

Commit

Permalink
Do not wrap the property in a json object
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero committed Feb 16, 2022
1 parent 8e1b148 commit 502656a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,8 @@ fn handle_get_property(req: HttpRequest, state: web::Data<AppState>) -> HttpResp
};

let thing = thing.read().unwrap();
if thing.has_property(&property_name.to_string()) {
HttpResponse::Ok()
.json(json!({property_name: thing.get_property(&property_name.to_string()).unwrap()}))
if let Some(property) = thing.get_property(property_name) {
HttpResponse::Ok().json(json!(property))
} else {
HttpResponse::NotFound().finish()
}
Expand Down Expand Up @@ -514,13 +513,11 @@ fn handle_put_property(
};

let mut thing = thing.write().unwrap();
if thing.has_property(&property_name.to_string()) {
if thing.has_property(property_name) {
let set_property_result = thing.set_property(property_name.to_string(), arg.clone());

match set_property_result {
Ok(()) => HttpResponse::Ok().json(
json!({property_name: thing.get_property(&property_name.to_string()).unwrap()}),
),
Ok(()) => HttpResponse::Ok().json(json!(thing.get_property(property_name).unwrap())),
Err(err) => HttpResponse::BadRequest().json(bad_request(err, Some(json!(args)))),
}
} else {
Expand Down

0 comments on commit 502656a

Please sign in to comment.