fix modulePath

This commit is contained in:
Hoang 2021-11-10 17:08:39 +07:00
parent 7bea76065a
commit 09cc989cc8
10 changed files with 21 additions and 15 deletions

View File

@ -47,7 +47,7 @@ func (s Service) Create(payload CreateOptions) error {
// Create device // Create device
_, err = col.InsertOne(ctx, deviceData) _, err = col.InsertOne(ctx, deviceData)
if err != nil { if err != nil {
logger.Error("devicemngt - Create ", logger.LogData{ logger.Error("devicemngmt - Create ", logger.LogData{
"doc": deviceData, "doc": deviceData,
"err": err.Error(), "err": err.Error(),
}) })

View File

@ -20,7 +20,7 @@ func (s Service) DeleteByDeviceID(deviceID string) error {
// Delete // Delete
if _, err := col.DeleteOne(ctx, cond); err != nil { if _, err := col.DeleteOne(ctx, cond); err != nil {
logger.Error("devicemngt - deleteByDeviceID", logger.LogData{ logger.Error("devicemngmt - deleteByDeviceID", logger.LogData{
"deviceId": deviceID, "deviceId": deviceID,
"err": err.Error(), "err": err.Error(),
}) })

View File

@ -21,7 +21,7 @@ func (s Service) FindAllDevicesByUserID(userID string) []Device {
// 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{ logger.Error("devicemngmt - findAllDevicesByUserID ", logger.LogData{
"err": err.Error(), "err": err.Error(),
}) })
return result return result

View File

@ -20,7 +20,7 @@ func (s Service) GetUserIDByAuthToken(authToken string) (userID string) {
// Find // Find
if err := col.FindOne(ctx, cond).Decode(&device); err != nil { if err := col.FindOne(ctx, cond).Decode(&device); err != nil {
logger.Error("devicemngt - getUserIDByAuthToken", logger.LogData{ logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{
"authToken": authToken, "authToken": authToken,
"err": err.Error(), "err": err.Error(),
}) })

View File

@ -59,7 +59,7 @@ func (s Service) UpdateByDeviceID(deviceID string, payload UpdateOptions) error
// Update // Update
_, err = col.UpdateOne(ctx, cond, updateData) _, err = col.UpdateOne(ctx, cond, updateData)
if err != nil { if err != nil {
logger.Error("devicemngt - updateByDeviceID", logger.LogData{ logger.Error("devicemngmt - updateByDeviceID", logger.LogData{
"deviceId": deviceID, "deviceId": deviceID,
"err": err.Error(), "err": err.Error(),
}) })

View File

@ -3,6 +3,7 @@ package devicemngmt
// Constant ... // Constant ...
const ( const (
tableDevice = "devices" tableDevice = "devices"
tablePrefixDefault = "devicemngmt"
timezoneHCM = "Asia/Ho_Chi_Minh" timezoneHCM = "Asia/Ho_Chi_Minh"

2
db.go
View File

@ -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 { 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, "deviceId": deviceID,
"err": err.Error(), "err": err.Error(),
}) })

View File

@ -35,6 +35,11 @@ func Init(config Config) (*Service, error) {
return nil, errors.New("please provide all necessary information for init device") 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 // Connect MongoDB
db, err := mongodb.Connect( db, err := mongodb.Connect(
config.MongoDB.Host, config.MongoDB.Host,

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/selly-Modules/devicemngmt module github.com/Selly-Modules/devicemngmt
go 1.17 go 1.17

View File

@ -9,7 +9,7 @@ import (
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("devicemngmt - Create: no deviceID data", logger.LogData{
"payload": co, "payload": co,
}) })
return errors.New("no deviceID data") return errors.New("no deviceID data")
@ -17,7 +17,7 @@ func (co CreateOptions) validate() error {
// UserAgent // UserAgent
if co.UserAgent == "" { if co.UserAgent == "" {
logger.Error("devicemngt - Create: no userAgent data", logger.LogData{ logger.Error("devicemngmt - Create: no userAgent data", logger.LogData{
"payload": co, "payload": co,
}) })
return errors.New("no userAgent data") return errors.New("no userAgent data")
@ -25,7 +25,7 @@ func (co CreateOptions) validate() error {
// IP // IP
if co.IP == "" { if co.IP == "" {
logger.Error("devicemngt - Create: no ip data", logger.LogData{ logger.Error("devicemngmt - Create: no ip data", logger.LogData{
"payload": co, "payload": co,
}) })
return errors.New("no ip data") return errors.New("no ip data")
@ -33,7 +33,7 @@ func (co CreateOptions) validate() error {
// UserID // UserID
if co.UserID == "" { if co.UserID == "" {
logger.Error("devicemngt - Create: no userID data", logger.LogData{ logger.Error("devicemngmt - Create: no userID data", logger.LogData{
"payload": co, "payload": co,
}) })
return errors.New("no userID data") return errors.New("no userID data")
@ -41,7 +41,7 @@ func (co CreateOptions) validate() error {
// AuthToken // AuthToken
if co.AuthToken == "" { if co.AuthToken == "" {
logger.Error("devicemngt - Create: no authToken data", logger.LogData{ logger.Error("devicemngmt - Create: no authToken data", logger.LogData{
"payload": co, "payload": co,
}) })
return errors.New("no authToken data") return errors.New("no authToken data")
@ -53,7 +53,7 @@ func (co CreateOptions) validate() error {
func (uo UpdateOptions) validate() error { func (uo UpdateOptions) validate() error {
// UserAgent // UserAgent
if uo.UserAgent == "" { if uo.UserAgent == "" {
logger.Error("devicemngt - Update: no userAgent data", logger.LogData{ logger.Error("devicemngmt - Update: no userAgent data", logger.LogData{
"payload": uo, "payload": uo,
}) })
return errors.New("no userAgent data") return errors.New("no userAgent data")
@ -61,7 +61,7 @@ func (uo UpdateOptions) validate() error {
// IP // IP
if uo.IP == "" { if uo.IP == "" {
logger.Error("devicemngt - Update: no ip data", logger.LogData{ logger.Error("devicemngmt - Update: no ip data", logger.LogData{
"payload": uo, "payload": uo,
}) })
return errors.New("no ip data") return errors.New("no ip data")
@ -69,7 +69,7 @@ func (uo UpdateOptions) validate() error {
// AuthToken // AuthToken
if uo.AuthToken == "" { if uo.AuthToken == "" {
logger.Error("devicemngt - Update: no authToken data", logger.LogData{ logger.Error("devicemngmt - Update: no authToken data", logger.LogData{
"payload": uo, "payload": uo,
}) })
return errors.New("no authToken data") return errors.New("no authToken data")