apollo-backend/internal/api/devices.go

26 lines
524 B
Go
Raw Normal View History

package api
2021-05-10 00:51:15 +00:00
import (
"encoding/json"
"net/http"
"github.com/julienschmidt/httprouter"
2021-07-05 23:22:24 +00:00
"github.com/christianselig/apollo-backend/internal/data"
2021-05-10 00:51:15 +00:00
)
func (a *api) upsertDeviceHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
2021-05-10 00:51:15 +00:00
d := &data.Device{}
if err := json.NewDecoder(r.Body).Decode(d); err != nil {
a.errorResponse(w, r, 500, err.Error())
2021-05-10 00:51:15 +00:00
return
}
if err := a.models.Devices.Upsert(d); err != nil {
a.errorResponse(w, r, 500, err.Error())
2021-05-10 00:51:15 +00:00
return
}
w.WriteHeader(http.StatusOK)
}