-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvote.go
More file actions
173 lines (152 loc) · 5.31 KB
/
vote.go
File metadata and controls
173 lines (152 loc) · 5.31 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
// 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"
)
// VoteService 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 [NewVoteService] method instead.
type VoteService struct {
Options []option.RequestOption
}
// NewVoteService 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 NewVoteService(opts ...option.RequestOption) (r VoteService) {
r = VoteService{}
r.Options = opts
return
}
// Vote on a post
func (r *VoteService) Add(ctx context.Context, body VoteAddParams, opts ...option.RequestOption) (res *VoteAddResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "votes"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Remove vote from a post
func (r *VoteService) Remove(ctx context.Context, body VoteRemoveParams, opts ...option.RequestOption) (res *VoteRemoveResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "votes"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...)
return
}
type CurrentUserVote struct {
CreatedAt string `json:"createdAt,required"`
PostID string `json:"postId,required"`
UserID string `json:"userId,required"`
VoteID string `json:"voteId,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
PostID respjson.Field
UserID respjson.Field
VoteID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r CurrentUserVote) RawJSON() string { return r.JSON.raw }
func (r *CurrentUserVote) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostVote struct {
Votes []PostVoteVote `json:"votes,required"`
VotesCount float64 `json:"votesCount,required"`
ViewerVote CurrentUserVote `json:"viewerVote"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Votes respjson.Field
VotesCount respjson.Field
ViewerVote respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r PostVote) RawJSON() string { return r.JSON.raw }
func (r *PostVote) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type PostVoteVote struct {
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 {
Username respjson.Field
Avatar respjson.Field
Name respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
CurrentUserVote
}
// Returns the unmodified JSON received from the API
func (r PostVoteVote) RawJSON() string { return r.JSON.raw }
func (r *PostVoteVote) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VoteAddResponse struct {
Voters PostVote `json:"voters"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Voters respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VoteAddResponse) RawJSON() string { return r.JSON.raw }
func (r *VoteAddResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VoteRemoveResponse struct {
Voters PostVote `json:"voters"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Voters respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VoteRemoveResponse) RawJSON() string { return r.JSON.raw }
func (r *VoteRemoveResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VoteAddParams struct {
// ID of the post to vote on.
PostID string `json:"postId,required"`
paramObj
}
func (r VoteAddParams) MarshalJSON() (data []byte, err error) {
type shadow VoteAddParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *VoteAddParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VoteRemoveParams struct {
// ID of the post to vote on.
PostID string `json:"postId,required"`
paramObj
}
func (r VoteRemoveParams) MarshalJSON() (data []byte, err error) {
type shadow VoteRemoveParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *VoteRemoveParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}