diff --git a/model/db.go b/model/db.go index b4a5132..b4b0795 100644 --- a/model/db.go +++ b/model/db.go @@ -12,6 +12,7 @@ type DBRole struct { Name string `bson:"name"` Code string `bson:"code"` IsAdmin bool `bson:"isAdmin"` + Level int `bson:"level"` CreatedAt time.Time `bson:"createdAt"` UpdatedAt time.Time `bson:"updatedAt"` } @@ -26,7 +27,7 @@ type DBUser struct { HashedPassword string `bson:"hashedPassword"` Status string `bson:"status"` RoleID primitive.ObjectID `bson:"roleId"` - Other string `bson:"other"` + Other interface{} `bson:"other"` CreatedAt time.Time `bson:"createdAt"` UpdatedAt time.Time `bson:"updatedAt"` } diff --git a/model/permission_request.go b/model/permission_request.go index b7ecc3f..6d0eb34 100644 --- a/model/permission_request.go +++ b/model/permission_request.go @@ -10,6 +10,7 @@ import ( // PermissionCreateOptions ... type PermissionCreateOptions struct { Name string + Code string RoleID string Desc string } @@ -17,6 +18,7 @@ type PermissionCreateOptions struct { // PermissionUpdateOptions ... type PermissionUpdateOptions struct { Name string + Code string RoleID string Desc string } @@ -37,6 +39,14 @@ func (co PermissionCreateOptions) Validate() error { return errors.New("no name data") } + // Code + if co.Code == "" { + logger.Error("usermngmt - Permission - Create: no code data", logger.LogData{ + "payload": co, + }) + return errors.New("no code data") + } + // RoleID if co.RoleID == "" { logger.Error("usermngmt - Permission - Create: no roleID data", logger.LogData{ @@ -68,6 +78,14 @@ func (co PermissionUpdateOptions) Validate() error { return errors.New("no name data") } + // Code + if co.Code == "" { + logger.Error("usermngmt - Permission - Update: no code data", logger.LogData{ + "payload": co, + }) + return errors.New("no code data") + } + // RoleID if co.RoleID == "" { logger.Error("usermngmt - Permission - Update: no roleID data", logger.LogData{ diff --git a/model/role_request.go b/model/role_request.go index 8fb5f24..e976e12 100644 --- a/model/role_request.go +++ b/model/role_request.go @@ -8,12 +8,14 @@ import ( // RoleCreateOptions ... type RoleCreateOptions struct { - Name string + Name string + Level int } // RoleUpdateOptions ... type RoleUpdateOptions struct { - Name string + Name string + Level int } // RoleAllQuery ... diff --git a/model/role_response.go b/model/role_response.go index 459963a..1c47dd1 100644 --- a/model/role_response.go +++ b/model/role_response.go @@ -16,6 +16,7 @@ type Role struct { ID string `json:"_id"` Name string `json:"name"` Code string `json:"code"` + Level int `json:"level"` IsAdmin bool `json:"isAdmin"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` diff --git a/model/user_request.go b/model/user_request.go index a0b2a88..7a2cb40 100644 --- a/model/user_request.go +++ b/model/user_request.go @@ -14,7 +14,7 @@ type UserCreateOptions struct { Password string Status string RoleID string - Other string + Other interface{} } // UserUpdateOptions ... @@ -23,7 +23,7 @@ type UserUpdateOptions struct { Phone string Email string RoleID string - Other string + Other interface{} } // ChangePasswordOptions ... diff --git a/model/user_response.go b/model/user_response.go index 5344b7b..9bd6344 100644 --- a/model/user_response.go +++ b/model/user_response.go @@ -6,15 +6,15 @@ import ( // User ... type User struct { - ID string `json:"_id"` - Name string `json:"name"` - Phone string `json:"phone"` - Email string `json:"email"` - Status string `json:"status"` - Role RoleShort `json:"role"` - Other string `json:"other"` - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` + ID string `json:"_id"` + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + Status string `json:"status"` + Role RoleShort `json:"role"` + Other interface{} `json:"other"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` } type ( diff --git a/permission/handle.go b/permission/handle.go index 1a67eb2..db6477b 100644 --- a/permission/handle.go +++ b/permission/handle.go @@ -40,7 +40,7 @@ func newPermission(payload model.PermissionCreateOptions) model.DBPermission { return model.DBPermission{ ID: mongodb.NewObjectID(), Name: payload.Name, - Code: internal.GenerateCode(payload.Name), + Code: payload.Code, RoleID: roleID, Desc: payload.Desc, CreatedAt: timeNow, @@ -75,7 +75,7 @@ func Update(permissionID string, payload model.PermissionUpdateOptions) error { updateData := bson.M{ "$set": bson.M{ "name": payload.Name, - "code": internal.GenerateCode(payload.Name), + "code": payload.Code, "roleId": roleID, "desc": payload.Desc, "updatedAt": internal.Now(), diff --git a/role/handle.go b/role/handle.go index e4145a6..9c63284 100644 --- a/role/handle.go +++ b/role/handle.go @@ -40,6 +40,7 @@ func newRole(payload model.RoleCreateOptions) model.DBRole { ID: mongodb.NewObjectID(), Name: payload.Name, Code: internal.GenerateCode(payload.Name), + Level: payload.Level, CreatedAt: timeNow, UpdatedAt: timeNow, } @@ -72,6 +73,7 @@ func Update(roleID string, payload model.RoleUpdateOptions) error { "$set": bson.M{ "name": payload.Name, "code": internal.GenerateCode(payload.Name), + "level": payload.Level, "updatedAt": internal.Now(), }, } @@ -125,6 +127,7 @@ func getResponseList(roles []model.DBRole) []model.Role { ID: role.ID.Hex(), Name: role.Name, Code: role.Code, + Level: role.Level, CreatedAt: role.CreatedAt, UpdatedAt: role.UpdatedAt, })