-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpost.go
More file actions
303 lines (271 loc) · 9.97 KB
/
post.go
File metadata and controls
303 lines (271 loc) · 9.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package logchimp
import (
"context"
"net/http"
"slices"
"github.com/logchimp/logchimp-go/internal/apijson"
"github.com/logchimp/logchimp-go/internal/requestconfig"
"github.com/logchimp/logchimp-go/option"
"github.com/logchimp/logchimp-go/packages/param"
"github.com/logchimp/logchimp-go/packages/respjson"
)
// PostService contains methods and other services that help with interacting with
// the logchimp API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewPostService] method instead.
type PostService struct {
Options []option.RequestOption
}
// NewPostService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewPostService(opts ...option.RequestOption) (r PostService) {
r = PostService{}
r.Options = opts
return
}
// Create a new post
func (r *PostService) New(ctx context.Context, body PostNewParams, opts ...option.RequestOption) (res *PostNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "posts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Update a post
func (r *PostService) Update(ctx context.Context, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
path := "posts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, nil, nil, opts...)
return
}
// Get all the posts
func (r *PostService) List(ctx context.Context, body PostListParams, opts ...option.RequestOption) (res *PostListResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "posts/get"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Delete a posts
func (r *PostService) Delete(ctx context.Context, body PostDeleteParams, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
path := "posts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, nil, opts...)
return
}
// Get post by Slug
func (r *PostService) GetBySlug(ctx context.Context, body PostGetBySlugParams, opts ...option.RequestOption) (res *PostGetBySlugResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "posts/slug"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
type Post struct {
Author PostAuthor `json:"author,required"`
Board Board `json:"board,required"`
CreatedAt string `json:"createdAt,required"`
PostID string `json:"postId,required"`
Slug string `json:"slug,required"`
// Title of the post.
Title string `json:"title,required"`
UpdatedAt string `json:"updatedAt,required"`
Voters PostVote `json:"voters,required"`
// Post description.
ContentMarkdown string `json:"contentMarkdown"`
Roadmap Roadmap `json:"roadmap"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Author respjson.Field
Board respjson.Field
CreatedAt respjson.Field
PostID respjson.Field
Slug respjson.Field
Title respjson.Field
UpdatedAt respjson.Field
Voters respjson.Field
ContentMarkdown respjson.Field
Roadmap respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r Post) RawJSON() string { return r.JSON.raw }
func (r *Post) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostAuthor struct {
UserID string `json:"userId,required"`
Username string `json:"username,required"`
Avatar string `json:"avatar"`
Name string `json:"name"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
UserID respjson.Field
Username respjson.Field
Avatar respjson.Field
Name respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r PostAuthor) RawJSON() string { return r.JSON.raw }
func (r *PostAuthor) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostNewResponse struct {
Post PostNewResponsePost `json:"post"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Post respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r PostNewResponse) RawJSON() string { return r.JSON.raw }
func (r *PostNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostNewResponsePost struct {
PostID string `json:"postId,required"`
BoardID string `json:"boardId"`
// Post description.
ContentMarkdown string `json:"contentMarkdown"`
CreatedAt string `json:"createdAt"`
RoadmapID string `json:"roadmap_id"`
Slug string `json:"slug"`
SlugID string `json:"slugId"`
// Title of the post.
Title string `json:"title"`
UpdatedAt string `json:"updatedAt"`
UserID string `json:"userId"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
PostID respjson.Field
BoardID respjson.Field
ContentMarkdown respjson.Field
CreatedAt respjson.Field
RoadmapID respjson.Field
Slug respjson.Field
SlugID respjson.Field
Title respjson.Field
UpdatedAt respjson.Field
UserID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r PostNewResponsePost) RawJSON() string { return r.JSON.raw }
func (r *PostNewResponsePost) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostListResponse struct {
Posts []Post `json:"posts"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Posts respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r PostListResponse) RawJSON() string { return r.JSON.raw }
func (r *PostListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostGetBySlugResponse struct {
Post PostGetBySlugResponsePost `json:"post"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Post respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r PostGetBySlugResponse) RawJSON() string { return r.JSON.raw }
func (r *PostGetBySlugResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostGetBySlugResponsePost struct {
SlugID string `json:"slugId,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SlugID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
Post
}
// Returns the unmodified JSON received from the API
func (r PostGetBySlugResponsePost) RawJSON() string { return r.JSON.raw }
func (r *PostGetBySlugResponsePost) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostNewParams struct {
// Title of the post.
Title string `json:"title,required"`
BoardID param.Opt[string] `json:"boardId,omitzero"`
// Post description.
ContentMarkdown param.Opt[string] `json:"contentMarkdown,omitzero"`
RoadmapID param.Opt[string] `json:"roadmapId,omitzero"`
paramObj
}
func (r PostNewParams) MarshalJSON() (data []byte, err error) {
type shadow PostNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *PostNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostListParams struct {
// Sort posts by creation date in 'asc' or 'desc' order.
Created string `json:"created,required"`
// Page number of the results to fetch.
Page float64 `json:"page,required"`
// "Number of posts to return in a single request. Default is 10."
Limit param.Opt[float64] `json:"limit,omitzero"`
RoadmapID param.Opt[string] `json:"roadmapId,omitzero" format:"uuid"`
UserID param.Opt[string] `json:"userId,omitzero" format:"uuid"`
// Posts will be searched from the list of provided board IDs. If a value is not
// provided, it defaults to empty array and posts are searched from all the boards.
BoardID []string `json:"boardId,omitzero" format:"uuid"`
paramObj
}
func (r PostListParams) MarshalJSON() (data []byte, err error) {
type shadow PostListParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *PostListParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostDeleteParams struct {
ID string `json:"id,required"`
paramObj
}
func (r PostDeleteParams) MarshalJSON() (data []byte, err error) {
type shadow PostDeleteParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *PostDeleteParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostGetBySlugParams struct {
Slug string `json:"slug,required"`
UserID param.Opt[string] `json:"userId,omitzero" format:"uuid"`
paramObj
}
func (r PostGetBySlugParams) MarshalJSON() (data []byte, err error) {
type shadow PostGetBySlugParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *PostGetBySlugParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}