@@ -12,6 +12,8 @@ import (
12
12
"fmt"
13
13
"net/http"
14
14
"net/url"
15
+
16
+ "github.com/durudex/go-polybase/input"
15
17
)
16
18
17
19
type Collection [T any ] interface {
@@ -38,62 +40,61 @@ func (c *collection[T]) Get(ctx context.Context) *Response[T] {
38
40
defer recoverFunc (ctx , c .client .Config ().RecoverHandler )
39
41
40
42
req := & Request {
41
- Endpoint : fmt .Sprintf ("/collections/%s/records" , c .name ),
43
+ Endpoint : fmt .Sprintf (recordsEndpointFormat , c .name ),
42
44
Method : http .MethodGet ,
43
45
}
44
46
45
47
var resp Response [T ]
46
48
47
49
if err := c .client .MakeRequest (ctx , req , & resp ); err != nil {
48
- panic ("error getting collection records: " + err .Error ())
50
+ panic ("error: getting collection records: " + err .Error ())
49
51
}
50
52
51
53
return & resp
52
54
}
53
55
54
56
func (c * collection [T ]) Before (cursor string ) Query [T ] {
55
57
return newQuery [T ](c .client ,
56
- fmt .Sprintf ("/collections/%s/records" , c .name )).Before (cursor )
58
+ fmt .Sprintf (recordsEndpointFormat , c .name )).Before (cursor )
57
59
}
58
60
59
61
func (c * collection [T ]) After (cursor string ) Query [T ] {
60
62
return newQuery [T ](c .client ,
61
- fmt .Sprintf ("/collections/%s/records" , c .name )).After (cursor )
63
+ fmt .Sprintf (recordsEndpointFormat , c .name )).After (cursor )
62
64
}
63
65
64
66
func (c * collection [T ]) Limit (num int ) Query [T ] {
65
67
return newQuery [T ](c .client ,
66
- fmt .Sprintf ("/collections/%s/records" , c .name )).Limit (num )
68
+ fmt .Sprintf (recordsEndpointFormat , c .name )).Limit (num )
67
69
}
68
70
69
71
func (c * collection [T ]) Sort (field string , direction ... string ) Query [T ] {
70
72
return newQuery [T ](c .client ,
71
- fmt .Sprintf ("/collections/%s/records" , c .name )).Sort (field , direction ... )
73
+ fmt .Sprintf (recordsEndpointFormat , c .name )).Sort (field , direction ... )
72
74
}
73
75
74
76
func (c * collection [T ]) Where (field string , op WhereOperator , value any ) Query [T ] {
75
77
return newQuery [T ](c .client ,
76
- fmt .Sprintf ("/collections/%s/records" , c .name )).Where (field , op , value )
78
+ fmt .Sprintf (recordsEndpointFormat , c .name )).Where (field , op , value )
77
79
}
78
80
79
81
func (c * collection [T ]) Record (id string ) RecordDoer [T ] {
80
- return newRecordDoer [T ](c .client ,
81
- fmt .Sprintf ("/collections/%s/records/%s" , c .name , url .QueryEscape (id )))
82
+ return newRecordDoer [T ](c .client , c .name , id )
82
83
}
83
84
84
85
func (c * collection [T ]) Create (ctx context.Context , args ... any ) * SingleResponse [T ] {
85
86
defer recoverFunc (ctx , c .client .Config ().RecoverHandler )
86
87
87
88
req := & Request {
88
- Endpoint : fmt .Sprintf ("/collections/%s/records" , c .name ),
89
+ Endpoint : fmt .Sprintf (recordsEndpointFormat , c .name ),
89
90
Method : http .MethodPost ,
90
- Body : Body {Args : ParseInput (args )},
91
+ Body : Body {Args : input . Parse (args )},
91
92
}
92
93
93
94
var resp SingleResponse [T ]
94
95
95
96
if err := c .client .MakeRequest (ctx , req , & resp ); err != nil {
96
- panic ("error creating a new record: " + err .Error ())
97
+ panic ("error: creating a new record instance : " + err .Error ())
97
98
}
98
99
99
100
return & resp
0 commit comments