2021-11-05 09:57:33 +00:00
|
|
|
package devicemngmt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-11-05 10:24:08 +00:00
|
|
|
"github.com/Selly-Modules/logger"
|
2021-11-05 09:57:33 +00:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FindAllDevicesByUserID ...
|
2021-11-05 10:24:08 +00:00
|
|
|
func (s Service) FindAllDevicesByUserID(userID string) []Device {
|
2021-11-05 09:57:33 +00:00
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
col = s.getDeviceCollection()
|
2021-11-05 10:24:08 +00:00
|
|
|
result = make([]Device, 0)
|
2021-11-05 09:57:33 +00:00
|
|
|
cond = bson.M{
|
2021-11-05 10:24:08 +00:00
|
|
|
"userID": userID,
|
2021-11-05 09:57:33 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Find
|
|
|
|
cursor, err := col.Find(ctx, cond)
|
|
|
|
if err != nil {
|
2021-11-05 10:24:08 +00:00
|
|
|
logger.Error("devicemngt - findAllDevicesByUserID ", logger.LogData{
|
|
|
|
"err": err.Error(),
|
|
|
|
})
|
2021-11-05 09:57:33 +00:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
defer cursor.Close(ctx)
|
2021-11-05 10:24:08 +00:00
|
|
|
cursor.All(ctx, &result)
|
2021-11-05 09:57:33 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|