@@ -119,26 +119,22 @@ func updateSessionHandler(w http.ResponseWriter, r *http.Request) {
119119
120120 id := mux .Vars (r )["id" ]
121121
122- var data map [string ]any
123- if err := json .NewDecoder (r .Body ).Decode (& data ); err != nil {
124- jsonError (w , http .StatusBadRequest , errors .New ("invalid JSON" ))
125- return
122+ var data struct {
123+ Vehicle , Loadpoint * string
126124 }
127125
128- updates := map [string ]any {}
129- for _ , field := range []string {"vehicle" , "loadpoint" } {
130- if val , ok := data [field ]; ok {
131- updates [field ] = val
132- }
126+ if err := json .NewDecoder (r .Body ).Decode (& data ); err != nil {
127+ jsonError (w , http .StatusBadRequest , err )
128+ return
133129 }
134130
135- if len ( updates ) == 0 {
136- jsonError (w , http .StatusBadRequest , errors .New ("no valid fields to update" ))
131+ if data . Vehicle == nil && data . Loadpoint == nil {
132+ jsonError (w , http .StatusBadRequest , errors .New ("nothing to update" ))
137133 return
138134 }
139135
140136 // https://github.com/evcc-io/evcc/issues/13738#issuecomment-2094070362
141- if txn := db .Instance .Table ("sessions" ).Where ("id = ?" , id ).Updates (updates ); txn .Error != nil {
137+ if txn := db .Instance .Table ("sessions" ).Where ("id = ?" , id ).Updates (data ); txn .Error != nil {
142138 jsonError (w , http .StatusBadRequest , txn .Error )
143139 return
144140 }
0 commit comments