mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-13 23:47:44 +00:00
25 lines
541 B
Go
25 lines
541 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
"github.com/christianselig/apollo-backend/internal/data"
|
|
)
|
|
|
|
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)
|
|
}
|