Merge pull request #3 from Selly-Modules/feature/AllMethod
add allMethod
This commit is contained in:
commit
385e1f861f
|
@ -11,14 +11,16 @@ import (
|
|||
|
||||
// CreateOptions ...
|
||||
type CreateOptions struct {
|
||||
DeviceID string
|
||||
UserID string
|
||||
UserAgent string
|
||||
AppVersion string
|
||||
IP string
|
||||
FCMToken string
|
||||
AuthToken string
|
||||
Language string
|
||||
DeviceID string
|
||||
UserID string
|
||||
UserAgent string
|
||||
AppVersion string
|
||||
IP string
|
||||
FCMToken string
|
||||
AuthToken string
|
||||
Language string
|
||||
Model string
|
||||
Manufacturer string
|
||||
}
|
||||
|
||||
// Create ...
|
||||
|
@ -71,6 +73,9 @@ func (payload CreateOptions) newDevice() (result Device, err error) {
|
|||
LastActivatedAt: timeNow,
|
||||
CreatedAt: timeNow,
|
||||
FCMToken: payload.FCMToken,
|
||||
Model: payload.Model,
|
||||
Manufacturer: payload.Manufacturer,
|
||||
UserID: payload.UserID,
|
||||
}
|
||||
|
||||
// App version
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package devicemngmt
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Selly-Modules/logger"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// FindAllDevicesByUserID ...
|
||||
func (s Service) FindAllDevicesByUserID(userID string) []Device {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
col = s.getDeviceCollection()
|
||||
result = make([]Device, 0)
|
||||
cond = bson.M{
|
||||
"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, &result)
|
||||
|
||||
return result
|
||||
}
|
4
model.go
4
model.go
|
@ -17,8 +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" json:"model"`
|
||||
Manufacturer string `bson:"manufacturer" json:"manufacturer"`
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/Selly-Modules/logger"
|
||||
)
|
||||
|
||||
func (co CreateOptions) validate() error{
|
||||
func (co CreateOptions) validate() error {
|
||||
// DeviceID
|
||||
if co.DeviceID == "" {
|
||||
logger.Error("devicemngt - Create: no deviceID data", logger.LogData{
|
||||
|
@ -20,7 +20,7 @@ func (co CreateOptions) validate() error{
|
|||
logger.Error("devicemngt - Create: no userAgent data", logger.LogData{
|
||||
"payload": co,
|
||||
})
|
||||
return errors.New("no userAgent data")
|
||||
return errors.New("no userAgent data")
|
||||
}
|
||||
|
||||
// IP
|
||||
|
|
Loading…
Reference in New Issue