devicemngmt/action_get_all.go

34 lines
613 B
Go
Raw Normal View History

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-08 10:23:03 +00:00
"userId": userID,
2021-11-05 09:57:33 +00:00
}
)
// Find
cursor, err := col.Find(ctx, cond)
if err != nil {
2021-11-10 10:08:39 +00:00
logger.Error("devicemngmt - findAllDevicesByUserID ", logger.LogData{
2021-11-05 10:24:08 +00:00
"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
}