GetExtends
This commit is contained in:
@@ -196,23 +196,43 @@ type Claims struct {
|
|||||||
Session SessionClaims `json:"session"`
|
Session SessionClaims `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetExtend(obj utils.DBObject, extends map[string][]tools.DataType) map[string]interface{} {
|
func GetExtends(objs []utils.ShallowDBObject, extends map[string][]tools.DataType) []map[string]interface{} {
|
||||||
|
cache := map[tools.DataType]map[string]interface{}{}
|
||||||
|
m := []map[string]interface{}{}
|
||||||
|
for _, obj := range objs {
|
||||||
|
m = append(m, GetExtend(obj, extends, cache))
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetExtend(obj utils.DBObject, extends map[string][]tools.DataType, cache map[tools.DataType]map[string]interface{}) map[string]interface{} {
|
||||||
base := obj.Serialize(obj)
|
base := obj.Serialize(obj)
|
||||||
for k, v := range extends {
|
for k, v := range extends {
|
||||||
if base[k+"_id"] == nil || base[k+"_id"] == "" {
|
if base[k+"_id"] == nil || base[k+"_id"] == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, vv := range v {
|
for _, vv := range v {
|
||||||
|
if cache[vv] != nil && cache[vv][k] != nil {
|
||||||
|
base[k] = cache[vv][k]
|
||||||
|
continue
|
||||||
|
}
|
||||||
if d, _, err := models.Model(vv.EnumIndex()).GetAccessor(&tools.APIRequest{
|
if d, _, err := models.Model(vv.EnumIndex()).GetAccessor(&tools.APIRequest{
|
||||||
Admin: true,
|
Admin: true,
|
||||||
}).LoadOne(fmt.Sprintf("%v", base[k+"_id"])); d != nil && err == nil {
|
}).LoadOne(fmt.Sprintf("%v", base[k+"_id"])); d != nil && err == nil {
|
||||||
base[k] = d.Serialize(d)
|
base[k] = d.Serialize(d)
|
||||||
|
if cache[vv] == nil {
|
||||||
|
cache[vv] = map[string]interface{}{}
|
||||||
|
}
|
||||||
|
if cache[vv][k] == nil {
|
||||||
|
cache[vv][k] = base[k]
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractTokenInfo(request http.Request) (string, string, []string) {
|
func ExtractTokenInfo(request http.Request) (string, string, []string) {
|
||||||
reqToken := request.Header.Get("Authorization")
|
reqToken := request.Header.Get("Authorization")
|
||||||
splitToken := strings.Split(reqToken, "Bearer ")
|
splitToken := strings.Split(reqToken, "Bearer ")
|
||||||
|
|||||||
Reference in New Issue
Block a user