From 85c9692da0b142a2a8b32b6847ece80f85ed1da8 Mon Sep 17 00:00:00 2001 From: Hoang Date: Fri, 5 Nov 2021 16:24:53 +0700 Subject: [PATCH] fix comment again --- action_create.go | 20 ++++++++++---------- helper.go | 5 +---- model.go | 26 +++++++++++++------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/action_create.go b/action_create.go index 36413d8..eebbd0e 100644 --- a/action_create.go +++ b/action_create.go @@ -61,16 +61,16 @@ func (s Service) Create(payload CreateOptions) error { func (payload CreateOptions) newDevice() (result Device, err error) { timeNow := now() device := Device{ - ID: mongodb.NewObjectID(), - DeviceID: payload.DeviceID, - OSName: getOSName(payload.UserAgent), - OSVersion: getOSVersion(payload.UserAgent), - IP: payload.IP, - Language: getLanguage(payload.Language), - AuthToken: payload.AuthToken, - LastActivityAt: timeNow, - CreatedAt: timeNow, - FCMToken: payload.FCMToken, + ID: mongodb.NewObjectID(), + DeviceID: payload.DeviceID, + OSName: getOSName(payload.UserAgent), + OSVersion: getOSVersion(payload.UserAgent), + IP: payload.IP, + Language: getLanguage(payload.Language), + AuthToken: payload.AuthToken, + LastActivatedAt: timeNow, + CreatedAt: timeNow, + FCMToken: payload.FCMToken, } // App version diff --git a/helper.go b/helper.go index 3441415..120e9d5 100644 --- a/helper.go +++ b/helper.go @@ -26,12 +26,9 @@ func (s Service) isDeviceIDExisted(ctx context.Context, deviceID string) bool { "deviceID": deviceID, "err": err.Error(), }) - } - if !device.ID.IsZero() { return true } - - return false + return !device.ID.IsZero() } func getOSName(userAgent string) string { diff --git a/model.go b/model.go index 33dce53..7c00d78 100644 --- a/model.go +++ b/model.go @@ -8,17 +8,17 @@ import ( // Device ... type Device struct { - ID primitive.ObjectID `bson:"_id" json:"_id"` - DeviceID string `bson:"deviceID" json:"deviceId"` // unique - IP string `bson:"ip" json:"ip"` - OSName string `bson:"osName" json:"osName"` - OSVersion string `bson:"osVersion" json:"osVersion"` - AppVersion string `bson:"appVersion" json:"appVersion"` - Language string `bson:"language" json:"language"` // vi, en - IsMobile bool `bson:"isMobile" json:"isMobile"` - LastActivityAt time.Time `bson:"lastActivityAt" json:"lastActivityAt"` - UserID primitive.ObjectID `bson:"userID" json:"userId"` - AuthToken string `bson:"authToken" json:"authToken"` - FCMToken string `bson:"fcmToken" json:"fcmToken"` - CreatedAt time.Time `bson:"createdAt" json:"createdAt"` + ID primitive.ObjectID `bson:"_id" json:"_id"` + DeviceID string `bson:"deviceID" json:"deviceId"` // unique + IP string `bson:"ip" json:"ip"` + OSName string `bson:"osName" json:"osName"` + OSVersion string `bson:"osVersion" json:"osVersion"` + AppVersion string `bson:"appVersion" json:"appVersion"` + 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"` + AuthToken string `bson:"authToken" json:"authToken"` + FCMToken string `bson:"fcmToken" json:"fcmToken"` + CreatedAt time.Time `bson:"createdAt" json:"createdAt"` }