@@ -470,9 +470,8 @@ async fn handle_get_property(req: HttpRequest, state: web::Data<AppState>) -> Ht
470470 } ;
471471
472472 let thing = thing. read ( ) . unwrap ( ) ;
473- if thing. has_property ( & property_name. to_string ( ) ) {
474- HttpResponse :: Ok ( )
475- . json ( json ! ( { property_name: thing. get_property( & property_name. to_string( ) ) . unwrap( ) } ) )
473+ if let Some ( property) = thing. get_property ( property_name) {
474+ HttpResponse :: Ok ( ) . json ( json ! ( property) )
476475 } else {
477476 HttpResponse :: NotFound ( ) . finish ( )
478477 }
@@ -494,33 +493,14 @@ async fn handle_put_property(
494493 None => return HttpResponse :: NotFound ( ) . finish ( ) ,
495494 } ;
496495
497- let args = match body. as_object ( ) {
498- Some ( args) => args,
499- None => {
500- return HttpResponse :: BadRequest ( ) . json ( bad_request (
501- "Parsing request failed" ,
502- Some ( body. into_inner ( ) ) ,
503- ) )
504- }
505- } ;
506-
507- let arg = if let Some ( arg) = args. get ( property_name) {
508- arg
509- } else {
510- return HttpResponse :: BadRequest ( ) . json ( bad_request (
511- "Request does not contain property key" ,
512- Some ( json ! ( args) ) ,
513- ) ) ;
514- } ;
496+ let args = body. into_inner ( ) ;
515497
516498 let mut thing = thing. write ( ) . unwrap ( ) ;
517- if thing. has_property ( & property_name. to_string ( ) ) {
518- let set_property_result = thing. set_property ( property_name. to_string ( ) , arg . clone ( ) ) ;
499+ if thing. has_property ( property_name) {
500+ let set_property_result = thing. set_property ( property_name. to_string ( ) , args . clone ( ) ) ;
519501
520502 match set_property_result {
521- Ok ( ( ) ) => HttpResponse :: Ok ( ) . json (
522- json ! ( { property_name: thing. get_property( & property_name. to_string( ) ) . unwrap( ) } ) ,
523- ) ,
503+ Ok ( ( ) ) => HttpResponse :: Ok ( ) . json ( json ! ( thing. get_property( property_name) . unwrap( ) ) ) ,
524504 Err ( err) => HttpResponse :: BadRequest ( ) . json ( bad_request ( err, Some ( json ! ( args) ) ) ) ,
525505 }
526506 } else {
0 commit comments