2021-05-10 00:51:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
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 (app *application) upsertDeviceHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
|
d := &data.Device{}
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(d); err != nil {
|
|
|
|
app.errorResponse(w, r, 500, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.models.Devices.Upsert(d); err != nil {
|
|
|
|
app.errorResponse(w, r, 500, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|