Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Getting device name from user in URL instead of request body suring d…
Browse files Browse the repository at this point in the history
…evice edit.
  • Loading branch information
rishubhjain committed Aug 2, 2018
1 parent 05a2531 commit 4e15ee9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions plugins/device/api/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ type AddDeviceReq struct {

// EditDeviceReq structure
type EditDeviceReq struct {
DeviceName string `json:"device-name"`
State string `json:"state"`
State string `json:"state"`
}
8 changes: 7 additions & 1 deletion plugins/device/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) {
return
}

deviceName := r.URL.Query().Get("device")
if deviceName == "" {
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, "Device name not provided in URL")
return
}

txn, err := transaction.NewTxnWithLocks(ctx, peerID)
if err != nil {
status, err := restutils.ErrToStatusCode(err)
Expand All @@ -156,7 +162,7 @@ func deviceEditHandler(w http.ResponseWriter, r *http.Request) {
}
defer txn.Done()

err = deviceutils.SetDeviceState(peerID, req.DeviceName, req.State)
err = deviceutils.SetDeviceState(peerID, deviceName, req.State)
if err != nil {
logger.WithError(err).WithField("peerid", peerID).Error("Failed to update device state in store")
status, err := restutils.ErrToStatusCode(err)
Expand Down

0 comments on commit 4e15ee9

Please sign in to comment.