|
@@ -4,6 +4,7 @@ import (
|
|
|
"fmt"
|
|
|
"reflect"
|
|
|
|
|
|
+ "git.ali33.ru/fcg-xvii/go-tools/json"
|
|
|
"git.ali33.ru/fcg-xvii/rest"
|
|
|
"gorm.io/gorm"
|
|
|
"gorm.io/gorm/clause"
|
|
@@ -100,13 +101,6 @@ func toAnySlice(slice any) []any {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
-type ResultList struct {
|
|
|
- Items []any `json:"Items" rest:"fixed"`
|
|
|
- Offset int `json:"Offset" rest:"fixed"`
|
|
|
- Limit int `json:"Limit" rest:"fixed"`
|
|
|
- Count int64 `json:"Count" rest:"fixed"`
|
|
|
-}
|
|
|
-
|
|
|
func (s *List) ResultAnswer(pg *gorm.DB, fields rest.FieldNamesList, res any, offset, limit int) (*ResultList, rest.IErrorArgs) {
|
|
|
count, err := s.Result(pg, fields, res)
|
|
|
if err != nil {
|
|
@@ -120,3 +114,29 @@ func (s *List) ResultAnswer(pg *gorm.DB, fields rest.FieldNamesList, res any, of
|
|
|
}
|
|
|
return rList, nil
|
|
|
}
|
|
|
+
|
|
|
+type ResultList struct {
|
|
|
+ Items []any `json:"Items" rest:"fixed"`
|
|
|
+ Offset int `json:"Offset" rest:"fixed"`
|
|
|
+ Limit int `json:"Limit" rest:"fixed"`
|
|
|
+ Count int64 `json:"Count" rest:"fixed"`
|
|
|
+}
|
|
|
+
|
|
|
+func (s *ResultList) Map(req rest.IRequestIn) (json.Map, rest.IErrorArgs) {
|
|
|
+ fields := req.Fields()
|
|
|
+ ml := make([]json.Map, 0, len(s.Items))
|
|
|
+ for _, item := range s.Items {
|
|
|
+ it, ierr := rest.Fields(item, nil, fields)
|
|
|
+ if ierr != nil {
|
|
|
+ return nil, ierr
|
|
|
+ }
|
|
|
+ ml = append(ml, it)
|
|
|
+ }
|
|
|
+ res := json.Map{
|
|
|
+ "Items": ml,
|
|
|
+ "Offset": s.Offset,
|
|
|
+ "Limit": s.Limit,
|
|
|
+ "Count": s.Count,
|
|
|
+ }
|
|
|
+ return res, nil
|
|
|
+}
|