fix(controller): list device by id
This commit is contained in:
parent
e207bd0f0a
commit
3fa8315d62
|
|
@ -2,11 +2,12 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/leandrofars/oktopus/internal/db"
|
"github.com/leandrofars/oktopus/internal/db"
|
||||||
usp_msg "github.com/leandrofars/oktopus/internal/usp_message"
|
usp_msg "github.com/leandrofars/oktopus/internal/usp_message"
|
||||||
|
|
@ -37,11 +38,15 @@ func (a *Api) retrieveDevices(w http.ResponseWriter, r *http.Request) {
|
||||||
const PAGE_SIZE_DEFAULT = 20
|
const PAGE_SIZE_DEFAULT = 20
|
||||||
|
|
||||||
// Get specific device
|
// Get specific device
|
||||||
id := mux.Vars(r)["id"]
|
id := r.URL.Query().Get("id")
|
||||||
if id != "" {
|
if id != "" {
|
||||||
device, err := a.Db.RetrieveDevice(id)
|
device, err := a.Db.RetrieveDevice(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
if err == mongo.ErrNoDocuments {
|
||||||
|
json.NewEncoder(w).Encode("Device id: " + id + " not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user