diff --git a/action_create.go b/action_create.go index d99bac7..c98bf45 100644 --- a/action_create.go +++ b/action_create.go @@ -47,7 +47,7 @@ func (s Service) Create(payload CreateOptions) error { // Create device _, err = col.InsertOne(ctx, deviceData) if err != nil { - logger.Error("devicemngt - Create ", logger.LogData{ + logger.Error("devicemngmt - Create ", logger.LogData{ "doc": deviceData, "err": err.Error(), }) diff --git a/action_delete.go b/action_delete.go index 74c1253..f62e139 100644 --- a/action_delete.go +++ b/action_delete.go @@ -20,7 +20,7 @@ func (s Service) DeleteByDeviceID(deviceID string) error { // Delete if _, err := col.DeleteOne(ctx, cond); err != nil { - logger.Error("devicemngt - deleteByDeviceID", logger.LogData{ + logger.Error("devicemngmt - deleteByDeviceID", logger.LogData{ "deviceId": deviceID, "err": err.Error(), }) diff --git a/action_get_all.go b/action_get_all.go index c7889bc..38a3819 100644 --- a/action_get_all.go +++ b/action_get_all.go @@ -21,7 +21,7 @@ func (s Service) FindAllDevicesByUserID(userID string) []Device { // Find cursor, err := col.Find(ctx, cond) if err != nil { - logger.Error("devicemngt - findAllDevicesByUserID ", logger.LogData{ + logger.Error("devicemngmt - findAllDevicesByUserID ", logger.LogData{ "err": err.Error(), }) return result diff --git a/action_get_user_id.go b/action_get_user_id.go index 9c4d47f..aa0f829 100644 --- a/action_get_user_id.go +++ b/action_get_user_id.go @@ -20,7 +20,7 @@ func (s Service) GetUserIDByAuthToken(authToken string) (userID string) { // Find if err := col.FindOne(ctx, cond).Decode(&device); err != nil { - logger.Error("devicemngt - getUserIDByAuthToken", logger.LogData{ + logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{ "authToken": authToken, "err": err.Error(), }) diff --git a/action_update.go b/action_update.go index 9313b88..f092c65 100644 --- a/action_update.go +++ b/action_update.go @@ -59,7 +59,7 @@ func (s Service) UpdateByDeviceID(deviceID string, payload UpdateOptions) error // Update _, err = col.UpdateOne(ctx, cond, updateData) if err != nil { - logger.Error("devicemngt - updateByDeviceID", logger.LogData{ + logger.Error("devicemngmt - updateByDeviceID", logger.LogData{ "deviceId": deviceID, "err": err.Error(), }) diff --git a/constant.go b/constant.go index ca4c13f..4c427d1 100644 --- a/constant.go +++ b/constant.go @@ -3,6 +3,7 @@ package devicemngmt // Constant ... const ( tableDevice = "devices" + tablePrefixDefault = "devicemngmt" timezoneHCM = "Asia/Ho_Chi_Minh" diff --git a/db.go b/db.go index 222c272..5aae623 100644 --- a/db.go +++ b/db.go @@ -24,7 +24,7 @@ func (s Service) isDeviceIDExisted(ctx context.Context, deviceID string) bool { ) if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil { - logger.Error("devicemngt - findByDeviceID", logger.LogData{ + logger.Error("devicemngmt - findByDeviceID", logger.LogData{ "deviceId": deviceID, "err": err.Error(), }) diff --git a/devicemngt.go b/devicemngt.go index cdcfab8..bf5de05 100644 --- a/devicemngt.go +++ b/devicemngt.go @@ -35,6 +35,11 @@ func Init(config Config) (*Service, error) { return nil, errors.New("please provide all necessary information for init device") } + // If prefixTable is empty then it is devicemngmt + if config.TablePrefix == "" { + config.TablePrefix = tablePrefixDefault + } + // Connect MongoDB db, err := mongodb.Connect( config.MongoDB.Host, diff --git a/go.mod b/go.mod index 42f5b90..0047395 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/selly-Modules/devicemngmt +module github.com/Selly-Modules/devicemngmt go 1.17 diff --git a/validate.go b/validate.go index 7dbb1c2..aef6e2b 100644 --- a/validate.go +++ b/validate.go @@ -9,7 +9,7 @@ import ( func (co CreateOptions) validate() error { // DeviceID if co.DeviceID == "" { - logger.Error("devicemngt - Create: no deviceID data", logger.LogData{ + logger.Error("devicemngmt - Create: no deviceID data", logger.LogData{ "payload": co, }) return errors.New("no deviceID data") @@ -17,7 +17,7 @@ func (co CreateOptions) validate() error { // UserAgent if co.UserAgent == "" { - logger.Error("devicemngt - Create: no userAgent data", logger.LogData{ + logger.Error("devicemngmt - Create: no userAgent data", logger.LogData{ "payload": co, }) return errors.New("no userAgent data") @@ -25,7 +25,7 @@ func (co CreateOptions) validate() error { // IP if co.IP == "" { - logger.Error("devicemngt - Create: no ip data", logger.LogData{ + logger.Error("devicemngmt - Create: no ip data", logger.LogData{ "payload": co, }) return errors.New("no ip data") @@ -33,7 +33,7 @@ func (co CreateOptions) validate() error { // UserID if co.UserID == "" { - logger.Error("devicemngt - Create: no userID data", logger.LogData{ + logger.Error("devicemngmt - Create: no userID data", logger.LogData{ "payload": co, }) return errors.New("no userID data") @@ -41,7 +41,7 @@ func (co CreateOptions) validate() error { // AuthToken if co.AuthToken == "" { - logger.Error("devicemngt - Create: no authToken data", logger.LogData{ + logger.Error("devicemngmt - Create: no authToken data", logger.LogData{ "payload": co, }) return errors.New("no authToken data") @@ -53,7 +53,7 @@ func (co CreateOptions) validate() error { func (uo UpdateOptions) validate() error { // UserAgent if uo.UserAgent == "" { - logger.Error("devicemngt - Update: no userAgent data", logger.LogData{ + logger.Error("devicemngmt - Update: no userAgent data", logger.LogData{ "payload": uo, }) return errors.New("no userAgent data") @@ -61,7 +61,7 @@ func (uo UpdateOptions) validate() error { // IP if uo.IP == "" { - logger.Error("devicemngt - Update: no ip data", logger.LogData{ + logger.Error("devicemngmt - Update: no ip data", logger.LogData{ "payload": uo, }) return errors.New("no ip data") @@ -69,7 +69,7 @@ func (uo UpdateOptions) validate() error { // AuthToken if uo.AuthToken == "" { - logger.Error("devicemngt - Update: no authToken data", logger.LogData{ + logger.Error("devicemngmt - Update: no authToken data", logger.LogData{ "payload": uo, }) return errors.New("no authToken data")