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

Function GetDevicesByLocalpart

clientapi/routing/device.go:90–117  ·  view source on GitHub ↗

GetDevicesByLocalpart handles /devices

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

Source from the content-addressed store, hash-verified

88
89// GetDevicesByLocalpart handles /devices
90func GetDevicesByLocalpart(
91 req *http.Request, userAPI api.ClientUserAPI, device *api.Device,
92) util.JSONResponse {
93 var queryRes api.QueryDevicesResponse
94 err := userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{
95 UserID: device.UserID,
96 }, &queryRes)
97 if err != nil {
98 util.GetLogger(req.Context()).WithError(err).Error("QueryDevices failed")
99 return jsonerror.InternalServerError()
100 }
101
102 res := devicesJSON{}
103
104 for _, dev := range queryRes.Devices {
105 res.Devices = append(res.Devices, deviceJSON{
106 DeviceID: dev.ID,
107 DisplayName: dev.DisplayName,
108 LastSeenIP: stripIPPort(dev.LastSeenIP),
109 LastSeenTS: dev.LastSeenTS,
110 })
111 }
112
113 return util.JSONResponse{
114 Code: http.StatusOK,
115 JSON: res,
116 }
117}
118
119// UpdateDeviceByID handles PUT on /devices/{deviceID}
120func UpdateDeviceByID(

Callers 1

SetupFunction · 0.85

Calls 4

stripIPPortFunction · 0.85
ContextMethod · 0.80
QueryDevicesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected