fix comment
This commit is contained in:
parent
8fcb6cdb08
commit
7a3fa56b3c
|
@ -75,6 +75,7 @@ func (payload CreateOptions) newDevice() (result Device, err error) {
|
|||
FCMToken: payload.FCMToken,
|
||||
Model: payload.Model,
|
||||
Manufacturer: payload.Manufacturer,
|
||||
UserID: payload.UserID,
|
||||
}
|
||||
|
||||
// App version
|
||||
|
|
|
@ -3,50 +3,31 @@ package devicemngmt
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Selly-Modules/mongodb"
|
||||
"github.com/Selly-Modules/logger"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// FindAllDevicesByUserID ...
|
||||
func (s Service) FindAllDevicesByUserID(userID string) []ResponseDevice {
|
||||
func (s Service) FindAllDevicesByUserID(userID string) []Device {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
col = s.getDeviceCollection()
|
||||
docs = make([]Device, 0)
|
||||
result = make([]ResponseDevice, 0)
|
||||
result = make([]Device, 0)
|
||||
cond = bson.M{
|
||||
"userID": mongodb.NewIDFromString(userID),
|
||||
"userID": userID,
|
||||
}
|
||||
)
|
||||
|
||||
// Find
|
||||
cursor, err := col.Find(ctx, cond)
|
||||
if err != nil {
|
||||
logger.Error("devicemngt - findAllDevicesByUserID ", logger.LogData{
|
||||
"err": err.Error(),
|
||||
})
|
||||
return result
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
cursor.All(ctx, &docs)
|
||||
|
||||
// Get response data
|
||||
for _, doc := range docs {
|
||||
result = append(result, ResponseDevice{
|
||||
ID: doc.ID,
|
||||
DeviceID: doc.DeviceID,
|
||||
IP: doc.IP,
|
||||
OS: ResponseOS{
|
||||
Name: doc.OSName,
|
||||
Version: doc.OSVersion,
|
||||
},
|
||||
AppVersion: doc.AppVersion,
|
||||
Language: doc.Language,
|
||||
IsMobile: doc.IsMobile,
|
||||
FCMToken: doc.FCMToken,
|
||||
Model: doc.Model,
|
||||
Manufacturer: doc.Manufacturer,
|
||||
LastActivatedAt: doc.LastActivatedAt,
|
||||
CreatedAt: doc.CreatedAt,
|
||||
})
|
||||
}
|
||||
cursor.All(ctx, &result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
28
model.go
28
model.go
|
@ -17,32 +17,10 @@ type Device struct {
|
|||
Language string `bson:"language" json:"language"` // vi, en
|
||||
IsMobile bool `bson:"isMobile" json:"isMobile"`
|
||||
LastActivatedAt time.Time `bson:"lastActivatedAt" json:"lastActivatedAt"`
|
||||
UserID primitive.ObjectID `bson:"userID" json:"userId"`
|
||||
UserID string `bson:"userID" json:"userId"`
|
||||
AuthToken string `bson:"authToken" json:"authToken"`
|
||||
FCMToken string `bson:"fcmToken" json:"fcmToken"`
|
||||
Model string `bson:"model,omitempty" json:"model,omitempty"`
|
||||
Manufacturer string `bson:"manufacturer,omitempty" json:"manufacturer,omitempty"`
|
||||
Model string `bson:"model" json:"model"`
|
||||
Manufacturer string `bson:"manufacturer" json:"manufacturer"`
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
|
||||
}
|
||||
|
||||
// ResponseOS ...
|
||||
type ResponseOS struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// ResponseDevice ...
|
||||
type ResponseDevice struct {
|
||||
ID primitive.ObjectID `json:"_id"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
IP string `json:"ip"`
|
||||
OS ResponseOS `json:"os"`
|
||||
AppVersion string `json:"appVersion"`
|
||||
Language string `json:"language"`
|
||||
IsMobile bool `json:"isMobile"`
|
||||
FCMToken string `json:"fcmToken"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Manufacturer string `json:"manufacturer,omitempty"`
|
||||
LastActivatedAt time.Time `json:"lastActivatedAt"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue