2021-11-11 08:16:17 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/Selly-Modules/logger"
|
|
|
|
"github.com/Selly-Modules/usermngmt/database"
|
|
|
|
"github.com/Selly-Modules/usermngmt/model"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
)
|
|
|
|
|
|
|
|
func roleFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBRole) {
|
|
|
|
var (
|
|
|
|
col = database.GetRoleCol()
|
|
|
|
)
|
|
|
|
docs = make([]model.DBRole, 0)
|
|
|
|
|
|
|
|
cursor, err := col.Find(ctx, cond, opts...)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("usermngmt - Role - Find", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.roleFindByCondition",
|
|
|
|
Message: err.Error(),
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
},
|
2021-11-11 08:16:17 +00:00
|
|
|
})
|
2022-10-05 10:59:08 +00:00
|
|
|
|
2021-11-11 08:16:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer cursor.Close(ctx)
|
|
|
|
if err = cursor.All(ctx, &docs); err != nil {
|
|
|
|
logger.Error("usermngmt - Role - Decode", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.roleFindByCondition",
|
|
|
|
Message: err.Error(),
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
},
|
2021-11-11 08:16:17 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func permissionFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBPermission) {
|
|
|
|
var (
|
|
|
|
col = database.GetPermissionCol()
|
|
|
|
)
|
|
|
|
docs = make([]model.DBPermission, 0)
|
|
|
|
|
|
|
|
cursor, err := col.Find(ctx, cond, opts...)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("usermngmt - Permission - Find", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.permissionFindByCondition",
|
|
|
|
Message: err.Error(),
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
},
|
2021-11-11 08:16:17 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer cursor.Close(ctx)
|
|
|
|
if err = cursor.All(ctx, &docs); err != nil {
|
|
|
|
logger.Error("usermngmt - Permission - Decode", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.permissionFindByCondition",
|
|
|
|
Message: err.Error(),
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
},
|
2021-11-11 08:16:17 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|