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,
 | 
							FCMToken:        payload.FCMToken,
 | 
				
			||||||
		Model:           payload.Model,
 | 
							Model:           payload.Model,
 | 
				
			||||||
		Manufacturer:    payload.Manufacturer,
 | 
							Manufacturer:    payload.Manufacturer,
 | 
				
			||||||
 | 
							UserID:          payload.UserID,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// App version
 | 
						// App version
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,50 +3,31 @@ package devicemngmt
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/Selly-Modules/mongodb"
 | 
						"github.com/Selly-Modules/logger"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/bson"
 | 
						"go.mongodb.org/mongo-driver/bson"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FindAllDevicesByUserID ...
 | 
					// FindAllDevicesByUserID ...
 | 
				
			||||||
func (s Service) FindAllDevicesByUserID(userID string) []ResponseDevice {
 | 
					func (s Service) FindAllDevicesByUserID(userID string) []Device {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		ctx    = context.Background()
 | 
							ctx    = context.Background()
 | 
				
			||||||
		col    = s.getDeviceCollection()
 | 
							col    = s.getDeviceCollection()
 | 
				
			||||||
		docs   = make([]Device, 0)
 | 
							result = make([]Device, 0)
 | 
				
			||||||
		result = make([]ResponseDevice, 0)
 | 
					 | 
				
			||||||
		cond   = bson.M{
 | 
							cond   = bson.M{
 | 
				
			||||||
			"userID": mongodb.NewIDFromString(userID),
 | 
								"userID": userID,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Find
 | 
						// Find
 | 
				
			||||||
	cursor, err := col.Find(ctx, cond)
 | 
						cursor, err := col.Find(ctx, cond)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							logger.Error("devicemngt - findAllDevicesByUserID ", logger.LogData{
 | 
				
			||||||
 | 
								"err": err.Error(),
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
		return result
 | 
							return result
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer cursor.Close(ctx)
 | 
						defer cursor.Close(ctx)
 | 
				
			||||||
	cursor.All(ctx, &docs)
 | 
						cursor.All(ctx, &result)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 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,
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result
 | 
						return result
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										28
									
								
								model.go
								
								
								
								
							
							
						
						
									
										28
									
								
								model.go
								
								
								
								
							| 
						 | 
					@ -17,32 +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,omitempty" json:"model,omitempty"`
 | 
						Model           string             `bson:"model" json:"model"`
 | 
				
			||||||
	Manufacturer    string             `bson:"manufacturer,omitempty" json:"manufacturer,omitempty"`
 | 
						Manufacturer    string             `bson:"manufacturer" json:"manufacturer"`
 | 
				
			||||||
	CreatedAt       time.Time          `bson:"createdAt" json:"createdAt"`
 | 
						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