Merge pull request #3 from Selly-Modules/feature/AllMethod

add allMethod
This commit is contained in:
Nam Huynh 2021-11-05 17:28:54 +07:00 committed by GitHub
commit 385e1f861f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 11 deletions

View File

@ -19,6 +19,8 @@ type CreateOptions struct {
FCMToken string FCMToken string
AuthToken string AuthToken string
Language string Language string
Model string
Manufacturer string
} }
// Create ... // Create ...
@ -71,6 +73,9 @@ func (payload CreateOptions) newDevice() (result Device, err error) {
LastActivatedAt: timeNow, LastActivatedAt: timeNow,
CreatedAt: timeNow, CreatedAt: timeNow,
FCMToken: payload.FCMToken, FCMToken: payload.FCMToken,
Model: payload.Model,
Manufacturer: payload.Manufacturer,
UserID: payload.UserID,
} }
// App version // App version

33
action_get_all.go Normal file
View File

@ -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
}

View File

@ -17,8 +17,10 @@ type Device struct {
Language string `bson:"language" json:"language"` // vi, en Language string `bson:"language" json:"language"` // vi, en
IsMobile bool `bson:"isMobile" json:"isMobile"` IsMobile bool `bson:"isMobile" json:"isMobile"`
LastActivatedAt time.Time `bson:"lastActivatedAt" json:"lastActivatedAt"` 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"` AuthToken string `bson:"authToken" json:"authToken"`
FCMToken string `bson:"fcmToken" json:"fcmToken"` 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"` CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/Selly-Modules/logger" "github.com/Selly-Modules/logger"
) )
func (co CreateOptions) validate() error{ func (co CreateOptions) validate() error {
// DeviceID // DeviceID
if co.DeviceID == "" { if co.DeviceID == "" {
logger.Error("devicemngt - Create: no deviceID data", logger.LogData{ logger.Error("devicemngt - Create: no deviceID data", logger.LogData{