MCPcopy Create free account
hub / github.com/daodst/chat / UpdateDeviceByID

Function UpdateDeviceByID

clientapi/routing/device.go:120–160  ·  view source on GitHub ↗

UpdateDeviceByID handles PUT on /devices/{deviceID}

(
	req *http.Request, userAPI api.ClientUserAPI, device *api.Device,
	deviceID string,
)

Source from the content-addressed store, hash-verified

118
119// UpdateDeviceByID handles PUT on /devices/{deviceID}
120func UpdateDeviceByID(
121 req *http.Request, userAPI api.ClientUserAPI, device *api.Device,
122 deviceID string,
123) util.JSONResponse {
124
125 defer req.Body.Close() // nolint: errcheck
126
127 payload := deviceUpdateJSON{}
128
129 if resErr := httputil.UnmarshalJSONRequest(req, &payload); resErr != nil {
130 return *resErr
131 }
132
133 var performRes api.PerformDeviceUpdateResponse
134 err := userAPI.PerformDeviceUpdate(req.Context(), &api.PerformDeviceUpdateRequest{
135 RequestingUserID: device.UserID,
136 DeviceID: deviceID,
137 DisplayName: payload.DisplayName,
138 }, &performRes)
139 if err != nil {
140 util.GetLogger(req.Context()).WithError(err).Error("PerformDeviceUpdate failed")
141 return jsonerror.InternalServerError()
142 }
143 if !performRes.DeviceExists {
144 return util.JSONResponse{
145 Code: http.StatusNotFound,
146 JSON: jsonerror.Forbidden("device does not exist"),
147 }
148 }
149 if performRes.Forbidden {
150 return util.JSONResponse{
151 Code: http.StatusForbidden,
152 JSON: jsonerror.Forbidden("device not owned by current user"),
153 }
154 }
155
156 return util.JSONResponse{
157 Code: http.StatusOK,
158 JSON: struct{}{},
159 }
160}
161
162// DeleteDeviceById handles DELETE requests to /devices/{deviceId}
163func DeleteDeviceById(

Callers 1

SetupFunction · 0.85

Calls 4

ContextMethod · 0.80
CloseMethod · 0.65
PerformDeviceUpdateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected