2021-11-11 08:16:17 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-10 08:55:47 +00:00
|
|
|
"git.selly.red/Selly-Modules/logger"
|
|
|
|
"git.selly.red/Selly-Modules/usermngmt/database"
|
|
|
|
"git.selly.red/Selly-Modules/usermngmt/model"
|
2021-11-11 08:16:17 +00:00
|
|
|
"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{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
"err": err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer cursor.Close(ctx)
|
|
|
|
if err = cursor.All(ctx, &docs); err != nil {
|
|
|
|
logger.Error("usermngmt - Role - Decode", logger.LogData{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
"err": err.Error(),
|
|
|
|
})
|
|
|
|
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{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
"err": err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer cursor.Close(ctx)
|
|
|
|
if err = cursor.All(ctx, &docs); err != nil {
|
|
|
|
logger.Error("usermngmt - Permission - Decode", logger.LogData{
|
|
|
|
"cond": cond,
|
|
|
|
"opts": opts,
|
|
|
|
"err": err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|