add RoleMethods #6

Merged
lqhoang99 merged 2 commits from feature/Role into master 2021-11-10 08:05:20 +00:00
3 changed files with 8 additions and 7 deletions
Showing only changes of commit 02653fd7aa - Show all commits

View File

@ -58,7 +58,7 @@ func (s Service) UpdateRole(roleID string, payload model.RoleUpdateOptions) erro
return role.Update(roleID, payload)
}
// GetAllRole ...
func (s Service) GetAllRole(query model.RoleAllQuery) model.RoleAll {
// GetAllRoles ...
func (s Service) GetAllRoles(query model.RoleAllQuery) model.RoleAll {
return role.All(query)
}

View File

@ -38,10 +38,11 @@ func GetSearchString(fieldList ...string) string {
return fmt.Sprintf(format, searchList...)
}
// GetCode ...
func GetCode(s string) string {
// GenerateCode ...
func GenerateCode(s string) string {
var (
underscore = "_"
emptySpace = " "
)
return strings.ReplaceAll(mongodb.NonAccentVietnamese(s), " ", underscore)
return strings.ReplaceAll(mongodb.NonAccentVietnamese(s), emptySpace, underscore)
}

View File

@ -39,7 +39,7 @@ func newRole(payload model.RoleCreateOptions) model.DBRole {
return model.DBRole{
ID: mongodb.NewObjectID(),
Name: payload.Name,
Code: internal.GetCode(payload.Name),
Code: internal.GenerateCode(payload.Name),
CreatedAt: timeNow,
UpdatedAt: timeNow,
}
@ -71,7 +71,7 @@ func Update(roleID string, payload model.RoleUpdateOptions) error {
updateData := bson.M{
"$set": bson.M{
"name": payload.Name,
"code": internal.GetCode(payload.Name),
"code": internal.GenerateCode(payload.Name),
"updatedAt": internal.Now(),
},
}