Browse Source

model

- remove generic for PageInfo
Alexey Kim 1 năm trước cách đây
mục cha
commit
bc5e6fc29a
2 tập tin đã thay đổi với 133 bổ sung4 xóa
  1. 4 4
      model/page_info.go
  2. 129 0
      model/page_info_easyjson.go

+ 4 - 4
model/page_info.go

@@ -6,7 +6,7 @@ import (
 )
 
 //easyjson:json
-type PageInfo[T connection.Cursor] struct {
+type PageInfo struct {
 	Total           int     `json:"total"`
 	StartCursor     *string `json:"start_cursor,omitempty"`
 	EndCursor       *string `json:"end_cursor,omitempty"`
@@ -14,12 +14,12 @@ type PageInfo[T connection.Cursor] struct {
 	HasPreviousPage bool    `json:"has_previous_page"`
 }
 
-func (pi *PageInfo[T]) SetTotal(nodes []T) {
+func (pi *PageInfo) SetTotal(nodes ...connection.Cursor) {
 	pi.Total = len(nodes)
-	pi.Invalidate(nodes)
+	pi.Invalidate(nodes...)
 }
 
-func (pi *PageInfo[T]) Invalidate(nodes []T) {
+func (pi *PageInfo) Invalidate(nodes ...connection.Cursor) {
 	l := len(nodes)
 	if l < 1 {
 		pi.HasPreviousPage = pi.StartCursor != nil

+ 129 - 0
model/page_info_easyjson.go

@@ -0,0 +1,129 @@
+// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.
+
+package model
+
+import (
+	json "encoding/json"
+	easyjson "github.com/mailru/easyjson"
+	jlexer "github.com/mailru/easyjson/jlexer"
+	jwriter "github.com/mailru/easyjson/jwriter"
+)
+
+// suppress unused package warning
+var (
+	_ *json.RawMessage
+	_ *jlexer.Lexer
+	_ *jwriter.Writer
+	_ easyjson.Marshaler
+)
+
+func easyjson142f204aDecodeGitBeejayKimCraftApiModel(in *jlexer.Lexer, out *PageInfo) {
+	isTopLevel := in.IsStart()
+	if in.IsNull() {
+		if isTopLevel {
+			in.Consumed()
+		}
+		in.Skip()
+		return
+	}
+	in.Delim('{')
+	for !in.IsDelim('}') {
+		key := in.UnsafeFieldName(false)
+		in.WantColon()
+		if in.IsNull() {
+			in.Skip()
+			in.WantComma()
+			continue
+		}
+		switch key {
+		case "total":
+			out.Total = int(in.Int())
+		case "start_cursor":
+			if in.IsNull() {
+				in.Skip()
+				out.StartCursor = nil
+			} else {
+				if out.StartCursor == nil {
+					out.StartCursor = new(string)
+				}
+				*out.StartCursor = string(in.String())
+			}
+		case "end_cursor":
+			if in.IsNull() {
+				in.Skip()
+				out.EndCursor = nil
+			} else {
+				if out.EndCursor == nil {
+					out.EndCursor = new(string)
+				}
+				*out.EndCursor = string(in.String())
+			}
+		case "has_next_page":
+			out.HasNextPage = bool(in.Bool())
+		case "has_previous_page":
+			out.HasPreviousPage = bool(in.Bool())
+		default:
+			in.SkipRecursive()
+		}
+		in.WantComma()
+	}
+	in.Delim('}')
+	if isTopLevel {
+		in.Consumed()
+	}
+}
+func easyjson142f204aEncodeGitBeejayKimCraftApiModel(out *jwriter.Writer, in PageInfo) {
+	out.RawByte('{')
+	first := true
+	_ = first
+	{
+		const prefix string = ",\"total\":"
+		out.RawString(prefix[1:])
+		out.Int(int(in.Total))
+	}
+	if in.StartCursor != nil {
+		const prefix string = ",\"start_cursor\":"
+		out.RawString(prefix)
+		out.String(string(*in.StartCursor))
+	}
+	if in.EndCursor != nil {
+		const prefix string = ",\"end_cursor\":"
+		out.RawString(prefix)
+		out.String(string(*in.EndCursor))
+	}
+	{
+		const prefix string = ",\"has_next_page\":"
+		out.RawString(prefix)
+		out.Bool(bool(in.HasNextPage))
+	}
+	{
+		const prefix string = ",\"has_previous_page\":"
+		out.RawString(prefix)
+		out.Bool(bool(in.HasPreviousPage))
+	}
+	out.RawByte('}')
+}
+
+// MarshalJSON supports json.Marshaler interface
+func (v PageInfo) MarshalJSON() ([]byte, error) {
+	w := jwriter.Writer{}
+	easyjson142f204aEncodeGitBeejayKimCraftApiModel(&w, v)
+	return w.Buffer.BuildBytes(), w.Error
+}
+
+// MarshalEasyJSON supports easyjson.Marshaler interface
+func (v PageInfo) MarshalEasyJSON(w *jwriter.Writer) {
+	easyjson142f204aEncodeGitBeejayKimCraftApiModel(w, v)
+}
+
+// UnmarshalJSON supports json.Unmarshaler interface
+func (v *PageInfo) UnmarshalJSON(data []byte) error {
+	r := jlexer.Lexer{Data: data}
+	easyjson142f204aDecodeGitBeejayKimCraftApiModel(&r, v)
+	return r.Error()
+}
+
+// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
+func (v *PageInfo) UnmarshalEasyJSON(l *jlexer.Lexer) {
+	easyjson142f204aDecodeGitBeejayKimCraftApiModel(l, v)
+}