|
@@ -2,7 +2,6 @@ package rest_gorm
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "log"
|
|
|
"reflect"
|
|
|
|
|
|
"git.ali33.ru/fcg-xvii/go-tools/json"
|
|
@@ -84,23 +83,18 @@ func (s *List) Result(pg *gorm.DB, fields rest.FieldNamesList, res any) (count i
|
|
|
err = rest.ErrorFiled("ErrDB", pg.Error.Error())
|
|
|
return
|
|
|
}
|
|
|
- log.Println(res)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func toAnySlice(slice any) []any {
|
|
|
v := reflect.ValueOf(slice)
|
|
|
- log.Println("kk", v.Kind())
|
|
|
-
|
|
|
if v.Kind() == reflect.Ptr {
|
|
|
v = v.Elem()
|
|
|
}
|
|
|
-
|
|
|
// Check if the input is a slice
|
|
|
if v.Kind() != reflect.Slice {
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
result := make([]any, v.Len())
|
|
|
for i := 0; i < v.Len(); i++ {
|
|
|
result[i] = v.Index(i).Interface()
|
|
@@ -113,7 +107,6 @@ func (s *List) ResultAnswer(pg *gorm.DB, fields rest.FieldNamesList, res any, of
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- log.Println("---", res)
|
|
|
rList := &ResultList{
|
|
|
Items: toAnySlice(res),
|
|
|
Offset: offset,
|
|
@@ -129,14 +122,12 @@ func (s *List) ResultOut(pg *gorm.DB, model any, req rest.IRequestIn) rest.IRequ
|
|
|
return req.OutError(rest.ErrorMessage("ErrFileds", err.Error()))
|
|
|
}
|
|
|
// preload
|
|
|
- log.Println("list preload...")
|
|
|
if pg, err = Preload(model, req.Fields(), pg); err != nil {
|
|
|
return req.OutError(rest.ErrorMessage("ErrPreload", err.Error()))
|
|
|
}
|
|
|
|
|
|
// Определяем тип элемента напрямую без использования reflect.ValueOf
|
|
|
elemType := reflect.TypeOf(model)
|
|
|
- log.Println(elemType)
|
|
|
// Создаем срез нужного типа
|
|
|
sl := reflect.MakeSlice(reflect.SliceOf(elemType), 0, 0)
|
|
|
// Создаем указатель на этот срез
|